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:00

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?


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

Shawn M wrote
Setting up a dual boot for Windows 10 and Debian Stretch per you directions above. All seems well, but when I select the new Windows 10 entry in the Grub2 menu I get a 'Invalid Signature' message and then Grub returns to the main menu. ...any suggestions?? I have tried --force with the chainload command and check that fs_uuid with grub_probe and verified that the windows boot program is in the correct location in the EFI partition. I have run out of things to try...


2018-07-22 21:54:21

Sam Mangum wrote
Just wanted to note I had to use grub2-mkconfig on Fedora 28. Thanks for the help.

2018-09-16 04:49:51

Phil wrote
Thanks so much for this post. On first attempt I got the error "cannot find /EFI/Microsoft/Boot/bootmgfw.efi". I found a bootmgfw.efi at the location "/Windows/Boot/EFI/bootmgfw.efi" so I went with that instead but now get the error "error: symlink type invalid"

Windows is on /dev/sda2. My main linux root partition is on /dev/sdb2, and it seems that /dev/sdb1 is what's getting booted. Is it a problem that it's on a different device?

root@phil-box:/mnt/windows-mount/EFI/ubuntu# fdisk -l
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x00003a01

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 718847 716800 350M 7 HPFS/NTFS/exFAT
/dev/sda2 718848 408677438 407958591 194.5G 7 HPFS/NTFS/exFAT
/dev/sda3 408678400 409602047 923648 451M 27 Hidden NTFS WinRE
/dev/sda4 409604094 1811353599 1401749506 668.4G 5 Extended
/dev/sda5 807700480 1811353599 1003653120 478.6G 83 Linux

Partition 4 does not start on physical sector boundary.

root@phil-box:/mnt/windows-mount/EFI/ubuntu# fdisk -l
Disk /dev/sdb: 223.6 GiB, 240057409536 bytes, 468862128 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 94534EDF-AE9A-4A28-AA54-11FEA8E35D35

Device Start End Sectors Size Type
/dev/sdb1 2048 1050623 1048576 512M EFI System
/dev/sdb2 1050624 468860927 467810304 223.1G Linux filesystem

root@phil-box:/mnt/windows-mount/EFI/ubuntu# blkid /dev/sda2
/dev/sda2: UUID="E4D83DADD83D7EBC" TYPE="ntfs" PARTUUID="00003a01-02"

root@phil-box:/mnt/windows-mount/EFI/ubuntu# cat /etc/grub.d/40_custom
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Windows 10" --class windows --class os {
search --no-floppy --set=root --fs-uuid E4D83DADD83D7EBC
chainloader (${root})/Windows/Boot/EFI/bootmgfw.efi

2018-12-10 02:03:00

Norbert Kéri wrote
@Phil sorry but I have no idea, never seen that error. Being on a different device should not be a problem in itself.

2018-12-15 16:07:25

pjaromin wrote
Thanks! I have tested plenty of configurations, but only yours did work.

2018-12-27 18:38:15

neo wrote
Also having the "invalid signature" problem. Of note, it did seem to get further when I used the correct UUID (i.e the one of type XXXX-XXXX vs the 16 digit one), but still an "invalid signature". Can force the boot through BIOS to windows, but seems dumb.

2019-01-22 04:39:11

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