Can GRUB2 share the EFI system partition with Windows?

50,354

After a day of research, I can now answer my own Question: yes it is possible, and you can even use that partition as /boot and store your kernels/initramfs/etc. there.

Requirements:

  • Grub >= 2.00 (1.98 and 1.99 do not work)
  • Grub must be installed from a Linux kernel, that has support for EFI variables (CONFIG_EFI_VARS compiled in or as module efivars)
  • For creating the EFI boot entry you will need efibootmgr

Setup:

First mount your EFI partition to /boot

mount /dev/sdX1 /boot

If you look at the mount entry, you will see, that it is simply a FAT(32) partition. Under /boot you should find a directory efi.

As grub will call efibootmgr, you should load evivars, if it is not compiled into the kernel:

modprobe efivars

Now you can install grub:

# Replace x86_64 with i386 for 32 bit installations
grub2-install --target=x86_64-efi

Grub installs its files as usual to /boot/grub2. If everything worked correctly, you should now also have a folder /boot/efi/grub2 or /boot/efi/<name_of_your_distro>. With --bootloader-id=insert_name_here you can also specify the name for the folder yourself.

Grub calls efibootmgr automatically and creates a boot entry with that name in the EFI boot menu (in my case, that means it shows up as a bootable device in the EFI menu, not sure if this is the case on every EFI board)

Further setup does not differ from usual grub2 setup, grub2-mkconfig will add the appropriate modules for EFI to your grub.cfg.

Chainloading Windows:

As I asked for a dual boot with Windows, I will include the grub configuration for chainloading it:

Chainloading a Windows installation on EFI is slightly different from one on a MBR disk. You won't need the ntfs or part_mbr modules, instead fat and part_gpt are needed.

Also, setting root is not required, this information is stored by Windows' own boot manager. Instead specify the search command. The parameters needed for it can be determined by

grub-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi

This will give you the parameters for search specifying the location of the EFI partition, it should look something like:

--hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci0,gpt1 1ce5-7f28

Instead of telling chainloader the number of sectors to read, you will need to set the path to Windows' EFI loader in the EFI partition. This is the same for all Windows EFI installations. The resulting entry should look like this:

menuentry "Microsoft Windows x86_64 UEFI-GPT" {
    insmod part_gpt
    insmod fat
    insmod search_fs_uuid
    insmod chain
    search --fs-uuid --no-floppy --set=root <insert ouput from grub-probe here>
    chainloader /efi/Microsoft/Boot/bootmgfw.efi
}

Sources: These cover some more cases, if you want to boot from EFI, they are worth reading:

Share:
50,354

Related videos on Youtube

crater2150
Author by

crater2150

Updated on September 18, 2022

Comments

  • crater2150
    crater2150 over 1 year

    I have an existing Windows 7 GPT installation, which already has a EFI System partition.

    I am now trying to install a Linux on a separate harddisk, which is also GPT formatted. I did not find any working way to get grub booting without EFI system partition, so my question is:

    Is it possible for grub2 to use the same EFI System partition as windows? How do I tell grub2 to use it?

    To clarify my setup:

    gpt /dev/sda:
        1 EFI System partition created by windows (100MB)
        2 "Microsoft reserved partition" (200MB)
        3 Windows root (rest of disk)
    
    gpt /dev/sdb:
        # After answering my own question: this partition is not needed
        1 boot partition containing grub, kernels etc.(32MB)
        2 crypto LVM partition (rest of disk)
    

    I want grub2 to use the existing /dev/sda1 EFI partition.

    PS: My mainboard is EFI capable.

  • jozxyqk
    jozxyqk over 7 years
    For me (Fedora24) I put the windows 10 efi partition at mount /dev/sdXX /boot/efi, then followed this and ran bcdedit /set {bootmgr} path \EFI\fedora\shim.efi from windows to bootstrap EFI.