Skip to content

efibootmgr

Linux Tux Logo

Gentoo EFI Booting Without a Bootloader

Direct‑to‑Firmware Linux Engineering for Minimalist Power Users


A surgically clean Gentoo setup where GRUB has been thrown overboard and replaced by a custom‑compiled kernel with a built‑in command line, initramfs, LUKS, and LVM - All injected directly into UEFI.

Minimalism on steroids. No middlemen. No magic. Just pure control, raw performance, and a system that boots as if it were hard‑coded into the machine itself.


The combination that completely eliminates GRUB which must be enabled directly in the kernel

CONFIG_EFI_STUB=y
CONFIG_CMDLINE_BOOL=y
  • Note that when CONFIG_CMDLINE_BOOL is activated [Y] in kernel the commandline will appears below and its here you will enter the commandline from grub we going to extract soo

Enter arguments here that should be compiled into the kernel image and used at boot time

1) If the boot loader provides a command line at boot time, it is appended to this string toform the full kernel command line, when the system boots. │ 2) However, you can use the CONFIG_CMDLINE_OVERRIDE option to change this behavior and add the GRUB_DEFUALT command directly without problem. 3) Add the kernel commandline from GRUB_CMDLINE_LINUX_DEFAULT if you used sys-boot/grub:2 earlier

Optional: If you use sys-boot/grub:2 as I did before I moved over to efibootmgr you can get the values from GRUB_CMDLINE_LINUX_DEFAULT

awk -F'"' '/^GRUB_CMDLINE_LINUX_DEFAULT=/ {print $2}' /etc/default/grub
  • Output should be something similiar as shown
crypt_root=UUID=6917c185-a82f-42a8-b4a1-9a62902a7f19 dolvm rd.lvm.vg=rootfs root=/dev/mapper/elitedesk-rootfs rootfstype=ext4 rootwait loglevel=7 pcie_aspm=off usbcore.autosuspend=-1 cpufreq.default_governor=performance energy_perf_bias=performance i915.enable_psr=0 i915.enable_fbc=0

Compile Kernel so we are up to date

export NUMCPUS=$(nproc)
export NUMCPUSPLUSONE=$((NUMCPUS + 1))

cd /usr/src/linux
make -j${NUMCPUSPLUSONE} -l${NUMCPUSPLUSONE}
make modules_install
cp arch/x86/boot/bzImage /boot/vmlinuz-6.19.6-gentoo-x86_64

Create initramfs - I prefer to use use genkernel over dracut here for the sake of simplicity

genkernel --luks --lvm --install initramfs

Now create /boot/EFI/gentoo folder

mkdir -vp /boot/EFI/gentoo

Now it´s time to copy our kernel image and initramfs image to EFI partition we just created

cp /boot/vmlinuz-6.19.6-gentoo-x86_64 /boot/efi/EFI/gentoo/vmlinuz.efi
cp /boot/initramfs-6.19.6-gentoo-x86_64.img /boot/efi/EFI/gentoo/initramfs.img

Its crucial to set the boot drive correct and also it´s partitions number, you can find it with findmt

findmnt /boot | awk 'NR > 1 {print $2}'

Now we must Register the kernel and initramfs and boot partitions number in UEFI

  • Notice: You will see the output from the efibootmgr command once you create it

bash efibootmgr --create \ --disk /dev/sdb \ --part 2 \ --label "Gentoo 6.19.6" \ --loader '\vmlinuz-6.19.6-gentoo-x86_64' \ --unicode 'initrd=\initramfs-6.19.6-gentoo-x86_64.img'

We Verify that the record was created correctly

efibootmgr -v | grep -A2 "Gentoo 6.19.6"

Output from the verify command should be similiar to

Boot0003* Gentoo 6.19.6 HD(2,GPT,525cbfeb-c4bb-43c9-9070-75931eb00100,0x1000,0x1dc000)/\vmlinuz-6.19.6-gentoo-x86_6469006e0069007400720064003d005c0069006e0069007400720061006d00660073002d0036002e00310039002e0036002d00670065006e0074006f006f002d007800380036005f00360034002e0069006d006700
  dp: 04 01 2a 00 02 00 00 00 00 10 00 00 00 00 00 00 00 c0 1d 00 00 00 00 00 eb bf 5c 52 bb c4 c9 43 90 70 75 93 1e b0 01 00 02 02 / 04 04 40 00 5c 00 76 00 6d 00 6c 00 69 00 6e 00 75 00 7a 00 2d 00 36 00 2e 00 31 00 39 00 2e 00 36 00 2d 00 67 00 65 00 6e 00 74 00 6f 00 6f 00 2d 00 78 00 38 00 36 00 5f 00 36 00 34 00 00 00 / 7f ff 04 00
data: 69 00 6e 00 69 00 74 00 72 00 64 00 3d 00 5c 00 69 00 6e 00 69 00 74 00 72 00 61 00 6d 00 66 00 73 00 2d 00 36 00 2e 00 31 00 39 00 2e 00 36 00 2d 00 67 00 65 00 6e 00 74 00 6f 00 6f 00 2d 00 78 00 38 00 36 00 5f 00 36 00 34 00 2e 00 69 00 6d 00 67 00

Check the boor order efibootmgr|grep BootOrder

Note: The output is BootOrder: 0003,0004,0000 so our new Gentoo 6.19.6 that is Boot0003 gonna boot 1th Note: You can verify the BootXXXX numbers with efibootmgr command

BootCurrent: 0000
Timeout: 0 seconds
BootOrder: 0003,0004,0000
Boot0000  USB 3.0 Device USB 3.0 Device 000000004BA8    PciRoot(0x0)/Pci(0x14,0x0)/USB(17,0)4eac0881119f594d850ee21a522c59b21180000049535048
Boot0001  USB 3.0 Device USB 3.0 Device 000000004BA8    PciRoot(0x0)/Pci(0x14,0x0)/USB(17,0)4eac0881119f594d850ee21a522c59b21180000049535048
Boot0002* \EFI\BOOT\grub.efi    PciRoot(0x0)/Pci(0x14,0x0)/USB(18,0)/HD(2,MBR,0xd2447f09,0xe58d88,0x10000)/\EFI\BOOT\grub.efi0000000049535048
Boot0003* Gentoo 6.19.6 HD(2,GPT,525cbfeb-c4bb-43c9-9070-75931eb00100,0x1000,0x1dc000)/\vmlinuz-6.19.6-gentoo-x86_6469006e0069007400720064003d005c0069006e0069007400720061006d00660073002d0036002e00310039002e0036002d00670065006e0074006f006f002d007800380036005f00360034002e0069006d006700
Boot0004* Seagate Expansion Desk NAABL96K       PciRoot(0x0)/Pci(0x14,0x0)/USB(16,0)4eac0881119f594d850ee21a522c59b21180000049535048

Misc

Put new entry first in boot order (replace 0003 with your new boot number)

efibootmgr --bootorder 0003,0002,0001

Safety net — don't remove GRUB yet

  • On reboot — select new UEFI entry manually via F9/F10/F12 on HP EliteDesk
  • Verify that it boots correctly with LUKS prompt
  • Check afterwards:
cat /proc/cmdline

Delete a number by label

efibootmgr -b 0000 -L 'Gentoo Linux'

Delete all old entries that are bothering you

efibootmgr -b 0000 -B
efibootmgr -b 0001 -B
efibootmgr -b 0002 -B