10

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 then grub-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.
9

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 Windows bcdedit command can alter the NVRAM-based boot order. Specifically, opening an Administrator Command Prompt window and typing bcdedit /set "{bootmgr}" path \EFI\ubuntu\shimx64.efi (optionally followed by bcdedit /set "{bootmgr}" description "ubuntu" to keep the description sensible) should do the trick.
  • efibootmgr -- This Linux tool can adjust the boot order. Begin by typing sudo efibootmgr alone to see the options. Note the number (Boot####) associated with the ubuntu entry, and the current boot order (on the BootOrder line). You can then enter a new boot order with the ubuntu entry at the top by using the -o option. For instance, if the current boot order is 0000,0003,0007,0004 and ubuntu is 0007, you'd type sudo 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 as sudo ./refind-mkdefault -L ubuntu or sudo ./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:

  • As I described in the question, the EFI setup utility wouldn't let me pick ubuntu as a default, although it let me do that in manual boot menu. It would just let me pick the drive, and then starts Windows from that. efibootmgr attempted to change the boot order, but BIOS didn't pay attention on reboot. EasyBCD didn't work -- it didn't let me add more menu items. However, "BCDEDIT" in an admin shell actually did work, so thanks for that option! – Jon Watte Sep 8 '17 at 3:29
  • Note that EasyBCD and EasyUEFI are two different programs from the same vendor. Sadly it seems that the free version of EasyUEFI is no longer available - only trial versions are offered. However, BOOTICE is another free program that can edit the UEFI boot settings: original Chinese site, English-language site with description and screenshots. – telcoM Oct 14 '18 at 15:40
1

I've been having this exact problem the past few weeks. I figured it out using these options. Before doing any of these things I recommend you to go into your BIOS/UEFI and check the boot order and make sure where grub is installed is first in order.

So how I see it is you have two options.

Option 1

What I would recommend to you is install Windows 10 first. Then install ubuntu. But I know it is kinda taboo to just say "reinstall your software" so I'll offer an alternative too.

Option 2

With your current setup I would recommend you to boot into a Live Ubuntu CD/flash drive and install and run boot-repair. Click the "Recommended Repair" option and follow the instructions given. Go through it carefully and read all the commands before executing. This will override the current grub installation with a new one which should hopefully fix it.

  • Thansk for the suggestions, but I had already tried those. The first time I installed things, I went Windows 10 first, then Ubuntu 17.04, then Boot Repair. It still defaulted to Windows, and then I wiped and re-installed with Ubuntu first, which brings me to where I am now. – Jon Watte Sep 7 '17 at 1:13
  • I assume you've tried to adjust the boot order in your UEFI, right? – taterbotz Sep 7 '17 at 6:24
  • Yes, as I say: "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" – Jon Watte Sep 8 '17 at 3:12
1

I see several solutions:

  1. Edit your UEFI to adjust the default. On linux you can use efibootmgr. On Windows I'm not sure but I think you can boot into a recovery option that lets you configure the UEFI. Or you might prefer to install something like rEFInd.
  2. Change the folder name on the EFI partition. I think it prefers, or falls back to, a folder called boot.
  3. Just use the Windows boot loader, I think it can be configured to boot other OSes.
  • I could edit boot order using efibootmgr, but the BIOS ignores it and starts Windows anyway. Changing the boot folder name (or even copying grub into "boot") doesn't work until I remove the Microsoft one. The Windows boot loader doesn't boot non-Windows OS-es (at least not unsigned ones.) – Jon Watte Sep 8 '17 at 3:20
  • @JonWatte Maybe the uefi bootloader is different, I remember booting ubuntu from windows 7 bootloader on a 32-bit bios machine. Maybe it can still chainload grub2? Since efibootmgr doesn't work, I know I won't be buying MSI. – jiggunjer Sep 8 '17 at 4:12
  • Yeah, this MSI motherboard has some other problems too and is going back to Amazon in exchange for a Gigabyte. – Jon Watte Sep 8 '17 at 4:21
-1

A possible solution would be manually editing the /etc/default/grub file.

sudo vim /etc/default/grub

The default entry is determined by the GRUB_DEFAULT= setting in /etc/default/grub. The first "menu entry" has a value of "0". If Ubuntu is the second entry in the boot screen then set GRUB_DEFAULT=1.

Afterward, you would need to run the command to update grub config: update-grub

Another option would be installation grub-customizer and use its GUI to configure boot priority.

  • The problem is not with Grub. As I said in the post, if I can make the BIOS choose the Grub UEFI boot option, then I get the Grub boot-up menu, which lets me choose Windows or Ubuntu. This is the menu I want by default. Unfortunately, the BIOS chooses Windows Boot Manager by default. – Jon Watte Sep 7 '17 at 1:14
  • As I said, you can fix it in grub boot order by configuring Ubuntu as the first system to start. Use grub-customizer to do this using GUI. linuxandubuntu.com/home/… – Mr. Raspberry Sep 7 '17 at 8:21
  • Again, Grub doesn't even get started by the BIOS. Grub boot order doesn't matter. GRUB_DEFAULT doesn't matter. That's not the problem here. – Jon Watte Sep 8 '17 at 3:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.