Fixing a broken UEFI Grub boot loader
I recently installed Arch Linux on a new Dell Laptop with hybrid GPUs and UEFI. The firmware did not allow switching to legacy MBR boot mode, which I normally prefer because it is easier to install, so I had no choice in this case. To aggravate things, the newly created UEFI partition wasn’t recognised by the firmware and the computer didn’t boot. If you are in a similar situation, the following instructions might help.
I assume that you have created an UEFI partition of at least 300 MB using type “EFI SYSTEM” and GUID partition table on /dev/sdb1. Your actual device may differ, for example it could be /dev/sda1 or /dev/sda2. I also assume that you have mounted the the UEFI partition as follows:
1 | mkdir /boot/efi |
Furthermore, I assume that you have installed Grub successfully with:
1 | grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot/efi |
Normally this should leave you with a bootable system. In my case, however, I had old “ghost” bootloader entries left which were invalidated by recreating the UEFI partition. I first had to manually remove these. For this purpose, I used efibootmgr. Invoking the command without parameters shows a list of boot loader entries. For example:
1 | efibootmgr |
Let’s assume that 0002 is an invalid entry. You can delete it with:
1 | efibootmgr -b 2 -B |
Not that 2 is written without preceding zeros. You can also change the boot order or activate and deactivate single boot loaders with the same command. If this should not work, it can also be done using the firmware user interface in most cases.
Before I got my system to boot from my SSD, I executed two more steps to help the computer locating the Grub bootloader. First, I copied the bootloader itself to an alternative location. Keep in mind that /boot/efi still refers to the mounted UEFI partition (/dev/sdb1
in my case).
1 | mkdir /boot/efi/EFI/BOOT |
Second, I created a boot startup script:
1 | vi /boot/efi/startup.nsh |
Of course, you can use another editor such as nano if you prefer. The script contains only one line:
1 | bcf boot add 1 fs0:\EFI\GRUB\grubx64.efi “Grub Bootloader”</pre> |
After saving, unmounting, and rebooting the system, I was able to boot from the SSD.