Efibootmgr - hpaluch/hpaluch.github.io GitHub Wiki

Efibootmgr

Linux EFI boot manager - manages UEFI boot entries that are stored in NVRAM (Non-Volatile RAM).

NOTE: many recent UEFI implementations have "autodiscovery" feature - they scan ESP partition for bootloaders and automatically show found entries. However it is good practice to add boot entries using standard tools.

  • listing entries: efibootmgr or efibootmgr -v (different implementations have different details):

    # on SUSE -v is required to get paths:
    
    $ efibootmgr -v
    BootCurrent: 0000
    Timeout: 0 seconds
    BootOrder: 0002,0001,0000,0003
    Boot0000* opensuse-secureboot	HD(1,GPT,da572218-769b-4d2f-af59-a193be758a66,0x800,0x100000)/File(\EFI\opensuse\shim.efi)
    Boot0001* Plan9	HD(1,GPT,09435737-cdb5-46b3-b0fc-c48428df98d8,0x800,0x180000)/File(\EFI\plan9\bootx64.efi)
    Boot0002* FreeBSD	HD(1,GPT,da572218-769b-4d2f-af59-a193be758a66,0x800,0x100000)/File(\EFI\freebsd\loader.efi)
    Boot0003* UEFI OS	HD(4,GPT,a943da0d-4206-45f6-b645-cfb8ecc35145,0x6fc00800,0x4b06000)/File(\EFI\BOOT\BOOTX64.EFI)..BO
    
  • those long identifiers are GPT partition UUIDs, you can get them using fdisk -x /dev/DISK, for example:

$ fdisk -x /dev/sda

Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: Samsung SSD 870 Units: sectors of 1 * 512 = 512 bytes ... Disklabel type: gpt ...

Device Start End Sectors Type-UUID UUID Name Attrs /dev/sda1 2048 1574911 1572864 C12A7328-F81F-11D2-BA4B-00A0C93EC93B 09435737-CDB5-46B3-B0FC-C48428DF98D8
/dev/sda2 2099200 1807747071 1805647872 516E7CBA-6ECF-11D6-8FF8-00022D09712B 3D3A9EB1-8499-4EAA-A5B1-142F8571F77B
/dev/sda3 1807747072 1874855935 67108864 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F F5FBC163-B0AD-4056-ADFD-179C085ABE02
/dev/sda4 1874855936 1953523711 78667776 C91818F9-8025-47AF-89D2-F030D7000C2C A943DA0D-4206-45F6-B645-CFB8ECC35145 Plan 9


- second UUID column (named just `UUID`) is that one that must match UUID in `efibootmgr -v` output.
In my case `/dev/sda` has ESP partition `/dev/sda1` and thus partition UUID is `09435737-CDB5-46B3-B0FC-C48428DF98D8`.
So boot entry from `/dev/sda` disk looks like:

Boot0001* Plan9 HD(1,GPT,09435737-cdb5-46b3-b0fc-c48428df98d8,0x800,0x180000)/File(\EFI\plan9\bootx64.efi)


- add entry on default `/dev/sda` disk (path must exists on EFI partition on such disk)

```shell
# EFI partition is expected on /dev/sda (!)
efibootmgr -c -L Plan9 -l '\EFI\plan9\bootx64.efi'
  • if you want to add entry from different disk - typically NVMe you need to specify -d /dev/DISK, in my example:

    efibootmgr -c -L FreeBSD -d /dev/nvme0n1 -l '\EFI\freebsd\loader.efi'
    
  • deleting Boot entry: efibootmgr -b BOOT_NUMBER -B, where BOOT_NUMBER is number extracted from BootXXXX entry.

Issues

Issues: wrong partition number with Legacy BIOS

WARNING! Efibootmgr uses 1st partition as Default for boot path, which is wrong if you have, for example, hybrid boot layout with GRUB's legacy-bios partition as 1st one:

$ fdisk -l /dev/vda | sed -n '/^Disklabel/,$p'
Disklabel type: gpt
Disk identifier: B907DF9D-8F95-432B-B401-61C0CD48DF87

Device        Start      End  Sectors  Size Type
/dev/vda1      2048     4095     2048    1M BIOS boot
/dev/vda2      4096  1003519   999424  488M EFI System
/dev/vda3   1003520 36159487 35155968 16.8G Linux filesystem
/dev/vda4  36159488 41940991  5781504  2.8G Linux swap

# here are UUIDs that are used for efibootmgr:

$ fdisk -x /dev/vda | sed -n '/^Device/,$p' | awk '{print $1,$6}'

Device UUID
/dev/vda1 263B4ADF-9969-4BC8-B8DA-02E38CC717A0
/dev/vda2 42C0EAE3-5DD3-4ACB-AEA3-D2956B3CDFDA
/dev/vda3 E3255EA4-D657-47C9-A915-0A9C093E5D68
/dev/vda4 8818CFD9-AA5B-4813-83CB-E2AA23103A0B

In above case efibootmgr will specify path to /dev/vda1 (see UUID right after ,GPT, word) which is wrong.

In that case you should specify both main disk (-d) and partition number (-p):

efibootmgr -c -p 2 -d /dev/vda -L "Debian 13" -l '\EFI\debian13\shimx64.efi'

And verify that these numbers matches default boot entry ("debian" - create on install):

$ efibootmgr | grep -i debian

Boot0003* debian        HD(2,GPT,42c0eae3-5dd3-4acb-aea3-d2956b3cdfda,0x1000,0xf4000)/File(\EFI\debian\shimx64.efi)
Boot0008* Debian 13     HD(2,GPT,42c0eae3-5dd3-4acb-aea3-d2956b3cdfda,0x1000,0xf4000)/File(\EFI\debian13\shimx64.efi)