The TL;DR, added in the edit:
The question is:
How can I make the BIOS prefer GRUB over Windows Boot Manager on the same UEFI boot partition?
The problem is not with Grub; Grub does the right thing when the BIOS starts it. The problem is not with "the disk isn’t bootable," because both the Windows UEFI bootstrap and the Grub UEFI bootstrap are bootable. The problem is which UEFI bootstrap the BIOS chooses to boot from.
I’m setting up a new computer, and want it to by default boot into Ubuntu, but have the option to select Windows on boot. This is especially important if power goes out and comes back; I won’t even be in the house.
I started out by installing Ubuntu 17.04 on my internal NVMe disk, partitioned with GPT to use half the disk, and a separate UEFI boot partition. GRUB boots that just fine, and I see the GRUB boot menu on start-up where I can select whatever items GRUB knows about.
Then I installed Windows 10 Pro from a recently downloaded ISO.It installed Windows Boot Manager onto the same UEFI partition, and left the Ubuntu intact (great!) and that boots fine into Windows 10.
However, it did "something" that makes the UEFI firmware immediately select the Windows Boot Manager rather than GRUB on power-up. The only way to boot Linux now is to use the BIOS boot manager (F11 on my BIOS) and select the GRUB boot loader manually.The UEFI BIOS knows that there are multiple bootable installs on the UEFI partition, because I can choose between them in the boot manager.However, when I’m in the setup menu in the UEFI BIOS, it just lets me choose "UEFI boot my internal drive" in the boot priority selection — it doesn’t let me choose which particular boot loader on that partition to use. And, by default, it chooses Windows, not GRUB.
The internets (and this site) suggests that the old way to fix this is to run
update-grub
(so GRUB recognizes Windows) and thengrub-install
(to put GRUB back on the device.) I have done this, but unfortunately, it still has the behavior as described above, where the BIOS by default chooses Windows Boot Manager. (update-grub
does find the Windows Boot Manager install, and adds that to the menu, and that menu item works when I manually choose the GRUB partition in the UEFI boot manager.)What can I do to make GRUB the "default" boot on my UEFI boot partition?
Using a MSI X399 Carbon motherboard.
Second edit: Because the correct answer ends up being mentioned in a comment to a response, I’ll repeat it here:
"BCDEDIT" in an admin shell on Windows is the working solution. The others don't work.
Solution:
There are quite a few different ways to do this, including:
- The EFI setup utility — Most EFIs provide setup utilities that you can access by hitting a special key at boot time (Esc, Del, or a function key, typically; but what key it is varies from one system to another). These often, but not always, provide a way to adjust the boot order. If your firmware provides such an option, you should be able to use it to move GRUB to the top position. (GRUB is likely to be called
ubuntu
, given that you installed it from that distribution.) - An EFI shell — You can use the
bcfg
command in an EFI version 2 shell, as described on the Arch Linux wiki. If your system isn’t already set up with an easy-to-access shell, this approach is likely to be harder to use than the others, but it is OS-agnostic. - EasyUEFI — The third-party Windows EasyUEFI program is likely to be the easiest way to do what you want. You can click the
ubuntu
entry in EasyUEFI’s list and move it to the top. bcdedit
— The Windowsbcdedit
command can alter the NVRAM-based boot order. Specifically, opening an Administrator Command Prompt window and typingbcdedit /set "{bootmgr}" path EFIubuntushimx64.efi
(optionally followed bybcdedit /set "{bootmgr}" description "ubuntu"
to keep the description sensible) should do the trick.efibootmgr
— This Linux tool can adjust the boot order. Begin by typingsudo efibootmgr
alone to see the options. Note the number (Boot####
) associated with theubuntu
entry, and the current boot order (on theBootOrder
line). You can then enter a new boot order with theubuntu
entry at the top by using the-o
option. For instance, if the current boot order is 0000,0003,0007,0004 andubuntu
is 0007, you’d typesudo efibootmgr -o 0007,0000,0003,0004
to adjust the boot order.refind-mkdefault
— This script comes with rEFInd, and it’s a way to automate the preceding procedure. If you’re not using rEFInd, you’d need to download the script here and make it executable (chmod a+x refind-mkdefault
). You’d then run it assudo ./refind-mkdefault -L ubuntu
orsudo ./refind-mkdefault -L shimx64
to make GRUB the default boot entry.
There are potential problems and complications with any of these options. The most likely complicating factor is if there are old or alternative ubuntu
boot entries. It’s important that you move the correct one to the top position in the boot order; if you move the wrong one, you’ll end up with either no change in behavior or something non-functional booting, which would make it harder to boot. If you use efibootmgr
, the BootCurrent
line may help you to tell which option you should set as the default.
There are other ways to do it that are overkill. Re-installing GRUB (via Boot Repair or grub-install
) should do the trick, for instance. These approaches run the risk of damaging a known-working GRUB configuration, though.
Note also that some EFIs are buggy and there are other issues that can make it difficult to get GRUB to boot reliably. You may want to check out these questions and answers on AskUbuntu if you run into such problems: