I moved the disk with my debian installation to another computer, and it wouldn't boot. Using systemrescuecd I mounted my uefi partition (512 MB, vfat filesystem, has EFI directory) and did cd /mnt/sda1 && mkdir BOOT && cp debian/grubx64.efi BOOT/bootx64.efi, and it booted fine. (got the advice at Askubuntu) Now how do I register debian/grubx64.efi file with my system so that I can get rid of BOOT/bootx64.efi?
3 Answers
You can list and manipulate the EFI boot entries with efibootmgr on Linux.
Once you've successfully booted the system manually, make sure that efibootmgr is installed:
apt-get install efibootmgr
Then make sure the efivars pseudo-filesystem is mounted RW:
mount -o remount,rw -t efivarfs efivarfs /sys/firmware/efi/efivars
If that command fails, or if running efibootmgr results in a message like EFI variables are not supported on this system. then you did not boot in EFI mode. Reboot and try again.
Finally, add debian/grubx64.efi to the EFI boot list and make it the default:
efibootmgr -c -p 1 -d /dev/sda -L "GRUB" -l '\efi\debian\grubx64.efi'
The -p 1 and -d /dev/sda options specify the partition and block device containing the EFI system partition where you created the BOOT sub-directory. -L is a label for the entry being created, and -l is the path to the boot-loader.
You can delete entries you don't want with efibootmgr -b <boot-entry> -B.
You can get a detailed list of the current EFI boot entries with efibootmgr -v.
See man efibootmgr for details. I recommend reading it thoroughly and googling or asking here for clarification before running any of the above commands.
-
1note: this is how to do it manually. Running
grub-installorupdate-grubshould do much of the above automatically if you havegrub-efi-amd64(orgrub-efi-ia32on a 32-bit x86 machine) installed. You may need to manually mount the EFI partition user /boot manually, I can't recall exactly.cas– cas2018-03-07 05:34:18 +00:00Commented Mar 7, 2018 at 5:34 -
grub-installwith appropriate options did itCrabMan– CrabMan2018-03-07 19:51:23 +00:00Commented Mar 7, 2018 at 19:51 -
Could be just
grub-installin a chroot with /dev, /proc and maybe /sys (bind)mounted.Michael Shigorin– Michael Shigorin2018-03-11 10:35:48 +00:00Commented Mar 11, 2018 at 10:35
After having read https://wiki.archlinux.org/index.php/GRUB#UEFI_systems and man grub-install I did sudo grub-install --efi-directory $MY_ESP_MOUNTPOINT --target=x86_64-efi and now I have a "debian" boot target listed and working.
I'd suggest the command
sudo grub-install --efi-directory $MY_ESP_MOUNTPOINT --force-extra-removable --recheck
With --force-extra-removable Debian will (as Redhat does) create the BOOT directory in the EFI directory just along with the Debian directory. Most BIOS (like HP BIOS for example and I feel recent Dell BIOS) use this BOOT directory to find the file BOOTX64.EFI and automatically create the Boot entry making the UEFI boot automatically.
The --target option is not mandatory as you Debian will automatically set the right value if you run the grub-install from the same binary type as the system you want to boot
--recheck is here just to recreate the UEFI table and clear old boot entries no longer relevant as you could do with -B option in efibootmgr.