Modify Grub EFI file location with Multi-Boot OS

New to Debian (Or Linux in general)? Ask your questions here!

Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-06-12 19:15

Dear Debian Users,

Ever since I started using linux, I have had trouble getting the Grub Boot Loader to work. It is probably cause I don't understand how to configure it correctly.
With some searching I have found some helpful tools that have fixed problems I had, but I have had no success getting Grub to boot as default on an HP Pavillion X360 laptop.

What I am interested in doing is finding out how to change the default efi file used with the Grub Boot loader, and how to set it as default.
Almost every time I reboot my computer I have to hit the F9 key to change boot options and select the correct boot loader.

My configuration is as follows:

/dev/sda1 - EFI system partition
/dev/sda2 - Windows 10
/dev/sda3 - /dev/sda10 (Various linux distributions: Kali, Elementary, Debian, Manjaro, MX Linux, etc..)

I would like Debian as the default boot loader (/EFI/Debian/grubx64.efi) which is on /dev/sda8

How would I be able to set this and use Debian as the default Grub Boot Loader.

Thanks,
Simon
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby Dai_trying » 2019-06-12 19:53

Have you looked at efibootmgr? it can be used to re-order your boot menu as well as add/delete/rename etc.

If you type efibootmgr -v it will give you the boot entries and also show you the boot order and you can use the boot entry numbers for re-ordering them to your preference.
Dai_trying
 
Posts: 791
Joined: 2016-01-07 12:25

Re: Modify Grub EFI file location with Multi-Boot OS

Postby p.H » 2019-06-12 20:53

LechonLover wrote:I have to hit the F9 key to change boot options and select the correct boot loader.

How ? By name ("debian"), by path (\EFI\debian\grubx64.efi)... ?

LechonLover wrote:I would like Debian as the default boot loader (/EFI/Debian/grubx64.efi) which is on /dev/sda8

grubx64.efi must be in an EFI system partition. Do you mean that /dev/sda8 is an EFI system partition ?

FWIW, the few UEFI HP laptops I have used had a broken UEFI boot implementation. It just ignored any EFI boot entry created by efibootmgr and only booted using the fallback path bootloader at /EFI/boot/bootx64.efi. This is Windows fallback bootloader by default. If you have such broken UEFI firmware, you have to replace it with GRUB, for example with the following command :
Code: Select all
grub-install --removable

If Debian uses a different EFI partition than Windows, this command will probably have no effect because the first EFI partition takes precedence.
p.H
 
Posts: 1156
Joined: 2017-09-17 07:12

Re: Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-06-15 00:11

Thank you for the reply, and sorry for the confusion.

When I get into the boot menu, I select the volume label, then navigate through the efi directory and find debian folder, and then select the grubx64.efi which then loads the Debian Grub boot loader.

I have dev/sda1 as the main EFI partition which is used for both Windows and My Linux OS.

If I try the command you mentioned, grub-install --removable will my Windows OS on the same EFI partition be able to boot. Also, what exactly does that command do, I understand the first part, but what is --removable mean

Thanks.
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby p.H » 2019-06-15 07:55

By default, grub-install installs GRUB's core image as EFI/debian/grubx64.efi in the EFI partition mounted on /boot/efi and registers a boot entry pointing to it in EFI variables. You can see EFI boot entries Boot#### with the command "efibootmgr" (-v for more details). Normally, a UEFI firmware tries to boot using these boot entries in the order defined by the BootOrder variable. If the "debian" entry is not first in order, then it will not boot by default. If Windows boot manager is first, the boot order can be changed with efibootmgr (see man page) or running grub-install without argument again.

With the --removable option, grub-install installs GRUB's core image as EFI/boot/bootx64.efi, which is called the "removable device path" and does not register an EFI boot entry. A UEFI firmware uses this special pathname as a fallback boot loader when no registered EFI boot entry can be used or for booting an external (removable) drive such as an installer or a live system.

During the installation of Windows, the Windows Boot Manager is installed both as EFI/Microsoft/boot/bootmgfw.efi with a registered boot entry and in the removable device path, so that it can boot if the EFI boot entry does not work.

Running grub-install with --removable will overwrite the existing EFI/boot/bootx64.efi installed by Windows and, hopefully, will make GRUB appear at boot. Windows should be present in GRUB's menu. You can make a backup copy of bootx64.efi for safety before running the command. Also you can still boot Windows using the F9 boot menu and selecting bootmgfw.efi.

There are other possible explanations that GRUB does not appear at boot :
- No EFI boot entry was created (check with efibootmgr)
- The debian boot entry is not first in the boot order (ditto)
- The boot loader path is hardcoded for Windows in the UEFI firmware (and the above will not help)
p.H
 
Posts: 1156
Joined: 2017-09-17 07:12

Re: Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-06-17 13:39

Thanks for the details and explanations, it helps a lot. I was able to make a backup copy of my EFI directory before performing the command.

I checked efibootmgr, and by default debian is not loading first, so I will need to fix that, below is what it shows:

BootOrder: 0000,3000,2001,0003,2002,2004
Boot0000* ubuntu
Boot0003* Windows Boot Manager
Boot0004* kali
Boot0005* UEFI Hard drive
Boot0006* debian
Boot000A* Manjaro
Boot000B* Windows Boot Manager
Boot000C* MX18.3
Boot000D* feren
Boot2001* EFI USB Device
Boot3000* Internal Hard Disk or Solid State Disk

Also, when I ran the command "grub-install --removable" I received an error "bash: grub-install: command not found

I have received similar errors before, which had to do with my sources file not pulling from the correct repository, so I am not sure if this might be the case with this as well. I will check later and see what I can find.
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby p.H » 2019-06-18 07:51

LechonLover wrote:I checked efibootmgr, and by default debian is not loading first

The "debian" boot entry number (0006) is not even present in the BootOrder. Conversely, the BoorOrder contain boot entry numbers which do not even exist...

According to the BootOrder, Ubuntu should be loaded by default. Does this happen ?

You can try to add Debian to the boot order in first position with a command such as
Code: Select all
efibootmgr -o 0006,0000,3000,2001,0003,2002,2004


LechonLover wrote:Also, when I ran the command "grub-install --removable" I received an error "bash: grub-install: command not found

Did you run the command as root ? If you used "su" to get a root shell, did you add the "-", "-l" or "--login" option to set up a proper environment (with usual root $PATH) ?
p.H
 
Posts: 1156
Joined: 2017-09-17 07:12

Re: Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-06-19 03:40

Thank you for the reply.

Debian is boot entry # 0006. Although Ubuntu is loaded by default, it does not load automatically, it bypasses it and goes straight to windows. The only way to get the grub menu is to press F9 to load the boot options, in which case it lists 2 boot managers, Ubuntu and Windows Boot Manager.

On another note, I was able to fix the "command not found error". I found another user who had the same issue and re-installing grub-pc did the trick "sudo apt-get install --reinstall grub-pc". After that I ran the command grub-install --removable

Then I changed the boot order to only boot debian (0006), which it did change. I then attempted to restart my computer, and still went straight to Windows Boot Manager. Below is a copy of my efibootmgr entries

simon@HP-X360:~$ efibootmgr
BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,3001,0000,2001,2002,2004
Boot0000* Windows Boot Manager
Boot0001* ubuntu
Boot0003* Windows Boot Manager
Boot0004* kali
Boot0005* UEFI Hard drive
Boot0006* debian
Boot000A* Manjaro
Boot000B* Windows Boot Manager
Boot000C* MX18.3
Boot000D* feren
Boot2001* EFI USB Device
Boot3001* Internal Hard Disk or Solid State Disk

simon@HP-X360:~$ sudo efibootmgr -o 6
[sudo] password for simon:

BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0006
Boot0000* Windows Boot Manager
Boot0001* ubuntu
Boot0003* Windows Boot Manager
Boot0004* kali
Boot0005* UEFI Hard drive
Boot0006* debian
Boot000A* Manjaro
Boot000B* Windows Boot Manager
Boot000C* MX18.3
Boot000D* feren
Boot2001* EFI USB Device
Boot3001* Internal Hard Disk or Solid State Disk

One thing that confuses me is that is says boot current is 0001, which is Ubuntu, but I am running debian. Is there a way to change boot current to 0006. I have not found any topics on how to do that.

Thanks again for your assistance.
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby Head_on_a_Stick » 2019-06-19 16:57

LechonLover wrote:Then I changed the boot order to only boot debian (0006), which it did change. I then attempted to restart my computer, and still went straight to Windows Boot Manager.

Instruct Windows to start Debian's bootloader by running this command from an Administrator prompt in PowerShell:
Code: Select all
bcdedit /set "{bootmgr}" path "\EFI\debian\grubx64.efi"

This may be reset after major upgrades, just run the command again if that happens.
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10607
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-06-26 04:40

Sorry for the delay, but I have had a busy week, and didn't get around to trying your command until now, which unfortunately didn't work.

I loaded Windows, opened the powershell with "Run as Administrator" and entered the following command bcdedit /set "{bootmgr}" path "\EFI\debian\grubx64.efi" rAfter that I restarted the computer, and by default the Windows Boot Loader started.

I am wondering if maybe the only way to fix this is to install the Linux OS first, and then install Windows. So hopefully, by default the system will load Linux Boot loader first.

Previously I did use Boot-Repair in Ubuntu, which has helped me fix a lot of boot errors. I also used it to set the default boot device, which worked once, but when I restarted the system, it went back to using the Windows Boot Manager. Is it possible that during boot, their might be a system check that defaults to Windows no matter what you do?
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby p.H » 2019-06-27 06:55

LechonLover wrote: I found another user who had the same issue and re-installing grub-pc did the trick "sudo apt-get install --reinstall grub-pc".

That was wrong.
1) grub-install is part of grub2-common, not grub-pc.
2) You have an EFI boot setup so you must install grub-efi-amd64 (if 64-bit UEFI) or grub-efi-ia32 (if 32-bit UEFI, unlikely), instead of grub-pc which is meant for BIOS/legacy boot setup.

Can you post the output of
Code: Select all
efibootmgr -v

showing the EFI executable path associated with each boot entry ?

Here are possible causes I can think of that the UEFI firmware always boots Windows boot manager and the expected solutions :
- ignores EFI boot entries and uses the "removable device path" -> replace /EFI/BOOT/bootx64.efi (with grub-install --removable)
- uses the boot entry labelled "Windows Boot Manager" regardless of boot order -> bcdedit
- uses the hardwired Windows boot manager pathname -> replace /EFI/Microsoft/bootmgfw.efi
p.H
 
Posts: 1156
Joined: 2017-09-17 07:12

Re: Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-07-02 12:10

p.H wrote:
Here are possible causes I can think of that the UEFI firmware always boots Windows boot manager and the expected solutions :
- ignores EFI boot entries and uses the "removable device path" -> replace /EFI/BOOT/bootx64.efi (with grub-install --removable)
- uses the boot entry labelled "Windows Boot Manager" regardless of boot order -> bcdedit
- uses the hardwired Windows boot manager pathname -> replace /EFI/Microsoft/bootmgfw.efi


This is most likely the cause, but if you have experienced this and know how to fix it, I would appreciate it if you could explain it to me.

Thanks
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby GarryRicketson » 2019-07-02 12:20

by p.H »Can you post the output of:
Code: Select all
efibootmgr -v

showing the EFI executable path associated with each boot entry ?

If you want people to help you , please post the output of commands as requested, the output is needed to see how to proceed.
User avatar
GarryRicketson
 
Posts: 5877
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Modify Grub EFI file location with Multi-Boot OS

Postby LechonLover » 2019-07-04 03:44

My apologies, I do appreciate everyone's help on the forums, I will make sure to read through the suggestions properly moving forward. I did see the code and ran it, but didn't realize at the time, I needed to provide an output of the code. So, as requested, here is the code from efibootmgr -v

simon@HP-X360:~$ efibootmgr -v
BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0000,3000,2001,0001,2002,2004
Boot0000* Windows Boot Manager HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)RC
Boot0001* ubuntu HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\ubuntu\shimx64.efi)
Boot0002* Windows Boot Manager HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)RC
Boot0003* sparky HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\sparky\grubx64.efi)
Boot0004* Windows Boot Manager HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\Debian\grubx64.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0005* UEFI Hard drive HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\Boot\bootx64.efi)
Boot0006* debian HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\debian\shimx64.efi)
Boot000A* Manjaro HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\Manjaro\grubx64.efi)
Boot000C* MX18.3 HD(1,GPT,041dbf90-92cc-4b19-b0bb-89ccf64084c1,0x800,0x82000)/File(\EFI\MX18.3\grubx64.efi)
Boot000D* feren HD(13,GPT,7877efd7-da44-4246-8ed3-042cbb2693f4,0x608f1800,0x7d000)/File(\EFI\feren\shimx64.efi)
Boot2001* EFI USB Device RC
Boot3000* Internal Hard Disk or Solid State Disk RC

Something must clearly be changing the efi default boot, because in one of my previous posts, I had listed this output (it might not have been -v detailed version), but what I noticed was that I changed the boot order to boot only Debian - Boot0006 but after a reboot it somehow changed itself back to the previous state, similar to what is show above.

Also, on another note, I did install the grub-efi-amd64

Thank you,
Simon
LechonLover
 
Posts: 13
Joined: 2019-06-07 03:16

Re: Modify Grub EFI file location with Multi-Boot OS

Postby Head_on_a_Stick » 2019-07-05 17:16

The bcdedit command wasn't passed successfully because the Windows boot entries should point to the Debian .efi loader, did you see any error messages after running my suggested command?

Have you tried p.H's other suggestions?
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10607
Joined: 2014-06-01 17:46
Location: /dev/chair

Next

Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable