Of course I have a backup!

Random blobs of wisdom about software development

Grub2 menuentry for Windows 10 UEFI

Sunday, December 18, 2016

I had some troube setting this up, because most of the google hits that come up are for older windows versions, which are using the old MBR/non-UEFI method, show examples for grub1, outdated, or just plain wrong.

Common, but all wrong solutions you can find while googling

The following things are all wrong:

  • Run the os-probe command (does not exist anymore, part of the config generator now)
  • Mount the windows partition and regenerate the config, so it gets picked up automatically (does not work with UEFI)
  • Add a menuentry with setroot (hd0,msdos1) (does not work with GPT partitioning)
  • Add a menuentry with chainloader +1 (does not work with UEFI)
  • Run bootrec.exe /fixmbr from the windows recovery shell (works, but bombs the grub2 loader)

The solution

Put this in your /etc/grub.d/40_custom file:

menuentry 'Windows 10' {
    search --fs-uuid --no-floppy --set=root D464-A236
    chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
}

Where D464-A236 is the UUID of your windows UEFI partiton. You can find this by doing fdisk -l, and looking for a partition called "EFI System", but also make sure you are looking at the correct drive, you might have 2 or more EFI partitions, if you have multiple OSes. You want the one that is on the same device as the "Windows recovery environment". After you have the device, you can query the UUID with blkid, eg. blkid /dev/sda2.

Leave the chainloader line as it is, grub will evaluate the (${root}) part. If you want to make extra sure, you can mount the aforementioned EFI partition, and verify that the path to bootmgfw.efi is correct. Don't forget to run grub-mkconfig -o /boot/grub.cfg after making the modification.

This was written by Norbert Kéri, posted on Sunday, December 18, 2016, at 01:30

Tagged as:
peterthevicar wrote
Thank you SO much! I've tried ALL those blind alleys but now I have a proper dual-boot without having to go into the BIOS. Thank you for sharing. This is with Ubuntu which requires sudo to run fdisk and blkid but otherwise your instructions worked flawlessly. For Ubuntu you do sudo update-grub after changing the 40_custom file.

2017-11-17 00:35:02

Rod Zirbel wrote
I tried the solution in grub2, linix article. I entered, menuentry 'Win 10' {search --fs-uuid --no-floppy --set=root 01CCA326C8CF1100 chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi}
bash: syntax error near unexpected token `('
and I get that syntax error. What am I doing wrong? How do you save the file when your done? do you have to open a differnt terminal window and save?

Thanks

2017-12-27 20:06:02

Norbert Kéri wrote
@Rod Zirbel
You are supposed to put these entries in a file called /etc/grub.d/40_custom (the article mentions this). You will have to edit the file as root, so try something like "sudo nano /etc/grub.d/40_custom".

2017-12-28 01:37:03

Rod Zirbel wrote
Thanks for your quick answer, sorry but I'm am not more acquainted with Ubuntu. Following your instructions I was able to edit the GRUB. But it came back with the message cannot find /EFI/Microsoft/Boot/bootmgfw.efi When you run Fdisk -l does it show an EFI partition? This is what mine shows:
Disk identifier: 0x6a503528

Device Boot Start End Sectors Size Id Type
/dev/sda2 * 63 3244005512 3244005450 1.5T 7 HPFS/NTFS/exFAT
/dev/sda3 3755627568 3883938114 128310547 61.2G 83 Linux
/dev/sda4 3883938660 3907024064 23085405 11G 82 Linux swap / Solaris

Partition 2 does not start on physical sector boundary.
Partition 4 does not start on physical sector boundary.

I found a file call bootmgr.efi in the windows tree and changed the name to that but got the same message for that file also. I used to have another windows partition but deleted it and made larger using Partition commander software, did that delete the EFI partition or is what you see normal? Maybe I should just do a clean install of Win 10? Any thoughts would be appreciated. Thanks Rod Zirbel

2017-12-28 18:30:22

François Jaouen wrote
Thank you so much Norbert !

Maybe a slight simplification : the (${root}) can be ommitted in the chainloader line it's implicit. The chainloader line then becomes : chainloader /EFI/Microsoft/Boot/bootmgfw.efi (notice the / before EFI)

@Rod Zirbel
It seems to me that you are not booting in EFI but in BIOS mode. Using Ubuntu, os-prober package should be installed and running the following command as root should find your windows 10 entry :
# grub-mkconfig -o /boot/grub/grub.cfg
More information : https://help.ubuntu.com/community/Grub2/Setup

2018-01-06 13:52:57

Post a comment

Providing your email is optional, it is never published or shared, it is only used for auto approval purposes. If you already have at least 1 approved comment(s) tied to your email, you don't have to wait for moderation, otherwise the author must approve your comment.

Please solve this totally random captcha