1

I have an HP PC that sets Windows as the first boot partition/device every time you boot Windows. To resolve, I previously have replaced Microsoft's bootmgfw.efi with grubx64.efi in the EFI partition to trick it into thinking that it's booting Windows while in fact it was booting GRUB. The Windows Fall upgrade reset the Windows EFI folder again but now when I replace the bootmgfw.efi file with grubx64.efi, GRUB boots into GRUB when you select Windows (never-ending loop). Linux still boots OK.

Anybody knows how this could be resolved?

Thanks,

blitz
  • 113
  • 2
    you should have replaced /efi/boot/bootx64.efi not efi/windows/bootmgfw.efi – ravery Oct 24 '17 at 10:10
  • Try running Ubuntu boot repair? – Alan Jameson Oct 24 '17 at 10:18
  • ravery: I tried that and it worked once (loaded GRUB OK) but only until I booted Windows from GRUB. Once Windows was booted, I restarted the PC and it booted straight into Windows again without loading GRUB. – blitz Oct 24 '17 at 10:28
  • Alan Jameson: If I go into BIOS and select ubuntu as the first OS, Grub loads and works fine for both Windows and Ubuntu so I don't think that it's a problem with GRUB (unless I'm mistaken?). Of course if I select Windows then Grub stops loading and PC boots straight into Windows. Last time I followed Envy's post in this thread but that doesn't work any longer: https://askubuntu.com/questions/666631/how-can-i-dual-boot-windows-10-and-ubuntu-on-a-uefi-hp-notebook – blitz Oct 24 '17 at 10:31

1 Answers1

1

The Windows boot loader file, which is normally EFI/Windows/Boot/bootmgfw.efi, must exist on the ESP for Windows to boot. You say you replaced this file with a copy of grubx64.efi, but you don't say what you did with the original file. If you overwrote it, then Windows can't boot unless/until you restore the original file. (You can restore the file to another name, as described shortly.) If you've got a backup, you can restore it from that. If not, then I suggest you ask on a Windows forum about restoring the original file. You can then start over, being more careful with that original file.

If you renamed the original file, you should be able to edit GRUB's configuration to launch the file using its new name. The best way to do this, if you stick with GRUB, is to edit /etc/grub.d/40_custom to include something like this:

menuentry "Windows" {
    insmod part_gpt
    insmod chain
    set root='(hd0,gpt1)'
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}

You must change the partition ID [(hd0,gpt1) -- that is, the first partition (gpt1) on the first hard disk (hd0)] in this example to match your ESP. You must also change the boot loader filename, which this example shows as the default filename, which of course you've changed.

After creating or editing /etc/grub/40_custom, you must type sudo update-grub. This transfers these changes, along with other GRUB settings, to /boot/grub/grub.cfg. (You could edit that file directly, but then your edits will be wiped out whenever GRUB updates its configuration, such as after an automatic kernel update.)

Rod Smith
  • 44,284
  • 7
  • 63
  • 105
  • That worked for me thanks very much. P.S. the directory of the 40_custom file is /etc/grub.d/ rather than /etc/grub/ in ubuntu 17.10 – blitz Oct 25 '17 at 21:18
  • Oh, that was a typo on my part; my apologies. I've edited my answer to show the correct path. – Rod Smith Oct 26 '17 at 12:21