Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminblack/f082e0a6c43ad223cf18ae58cdabfd76 to your computer and use it in GitHub Desktop.
Save benjaminblack/f082e0a6c43ad223cf18ae58cdabfd76 to your computer and use it in GitHub Desktop.
Booting (Debian) Linux directly from the UEFI boot manager

With a modern UEFI motherboard, it is possible to boot Linux directly from the UEFI boot manager, without relying on a boot loader like GRUB.

First, the kernel has to be compiled with the "EFI boot stub" option enabled, which modifies the kernel so that it can be directly executed by the UEFI boot manager.

Debian enables this flag: grep CONFIG_EFI_STUB /boot/config-*

Second, the EFI System Partition (ESP) must be large enough to hold the kernel and the initrd image. The UEFI boot manager executable files must be on the ESP; therefore, the kernel and initrd must be on the ESP, since the kernel is the EFI executable, and the kernel requires the initrd to be somewhere it can find it.

The ESP in Debian is usually 100-250 MB, which is fine.

When GRUB is installed, it inserts its own entry into the UEFI boot manager, and installs an EFI executable on the ESP. To boot the kernel directly from the boot manager, I'll add a new boot manager entry just as GRUB does, but which "executes" the kernel, instead of the GRUB EFI executable.

Copy the kernel and initrd to the ESP: cp /{vmlinuz,initrd.img} /boot/efi/

Install the efibootmgr package, which is a command-line utility to modify the UEFI boot manager firmware.

The efibootmgr command (as root) to add a new item to the menu to boot the kernel from the ESP:

efibootmgr --disk /dev/[ESP device] --part [ESP partition #] --create --label "[Label]" --loader /[kernel image] --unicode "root=[root partition] initrd=/[initrd image] [extra options]"

For example, for a Debian Stretch (2017-01-01) system, sda boot device with the ESP first and the root partition second,

efibootmgr --disk /dev/sda --part 1 --create --label "Linux" --loader /vmlinuz-4.8.0-2-amd64 --unicode "root=/dev/sda2 initrd=/initrd.img-4.8.0-2-amd64 ro quiet"

Reboot, and the new UEFI boot manager entry should appear, and boot directly into Linux with no GRUB.

Copy link

additional info you can pass root=UUID=<uuid> instead of that then the root can be anywhere as long initrd can find it

Copy link

et-rnal commented Mar 9, 2023

greetings, do you know of any way to automate this via kernel hooks similar to how other distros do it? as in when the kernel is updated, it'll automatically generate the correct files and update the boot entry. thanks in advance.

Copy link

had to mount -t efivarfs efivarfs /sys/firmware/efi/efivars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment