Content:
Nearly all PCs/laptops purchased in the last decade will feature UEFI support.
UEFI introduced a more robust method of booting. While the older BIOS relied on data stored in each partition on the drive (known as the Master Boot Record), UEFI stores core boot files (such as a bootloader) in a separate partition.
With more control over the boot process, UEFI implementations generally include a boot menu, allowing the user to select a boot option at boot time.
It’s possible to use this directly in place of a separate bootloader, if your system is set up correctly. This involves configuring your kernel as an EFISTUB, which can then be identified and loaded by your UEFI.
Before going any further, you’ll need to make a note of the drive you want to boot. You can use the drive path (e.g. /dev/sda1), but it’s safer to use either the UUID or PARTUUID of the partition instead. This ensures that the system will still boot, even if the drive path changes.
To find this, run blkid, and identify the correct partition.
/dev/nvme0n1p1: UUID="82a9a6db-ebfd-497a-bc8d-50bcd38ba679" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="63e8a3c1-d28c-c2ac-8441-190c8dac04d8"
You can use either the UUID or PARTUUID – we recommend the latter.
Make a note of this to use later on.
Setting Up Your Kernel
If you’re compiling your own kernel, you can use the kernel command line to set your boot partition. If not, skip to the next section.
To do this, find the kernel option called ‘Built-in kernel command line’ (CONFIG_CMDLINE_BOOL) under ‘Processor Type and Features’ and ensure it’s enabled.
The kernel command line needs to set the root parameter to the partition you want to boot.
Take either the UUID or PARTUUID noted earlier, and add them to the kernel command line.
root=PARTUUID=63e8a3c1-d28c-c2ac-8441-190c8dac04d8
Be sure to exclude any quotation marks.
If you want to add any other boot parameters, such as quiet, you can add them to the end of the command line.
root=PARTUUID=63e8a3c1-d28c-c2ac-8441-190c8dac04d8 quiet mitigations=off
Anything you’d usually add to your bootloader command line can be added here.
If you use an initramfs, it’s also possible to build this into the kernel.
Once this is set, compile your kernel, and ensure it is installed in your EFI boot partition.
Adding Your Boot Option
There are a couple of options available to add a boot entry for your EFISTUB kernel.
The main one we’ll be looking at here is EFIBOOTMGR. This is a tool that allows EFI boot entries to be managed, from simple creations and deletions to setting the boot order.
The other option we’ll look at is using your UEFI system menu directly to add the boot entry. Support for this option is system/config dependent, so will not be available for most users.
Using EFIBOOTMGR
You’ll first need to ensure that the EFI variables filesystem (efivars) is both accessible, and writable. This filesystem contains EFI data that can be altered by the OS.
To find your efivars partition, run
mount | grep efivars
You should see an output similar to the below.
efivarfs on /sys/firmware/efi/efivars type efivarfs (ro,relatime)
Using the path from this output, mount the efivars partition.
mount -o remount,rw -t efivarfs efivarfs /sys/firmware/efi/efivars
Your system is now ready to start altering the EFI boot data.
To create an boot entry, you can use the following command, replacing the parameters as required.
efibootmgr -c -L "Linux OS" -l '\EFI\bootx64.efi' -u 'root=PARTUUID=63e8a3c1-d28c-c2ac-8441-190c8dac04d8'
- -c: Create a boot entry.
- -L: Set the label of the boot entry to the following string. This will show up in your EFI boot menu.
- -l: Set the path of the kernel to boot. This path must be relative to your EFI system partition, and formatted using backslashes.
- -u: The boot command line. Should contain the root parameter, with the path to your boot partition (unless it’s set in the kernel from the previous section).
If your kernel is set to use the built-in command line from the previous section, you can omit the -u parameter unless you have additional options to pass through. In this case, you don’t need to specify the root parameter, just add your additional parameters.
It’s possible to add an initramfs path to your boot command line, along with any other boot parameters you require.
efibootmgr -c -L "Linux OS" -l '\EFI\bootx64.efi' -u 'root=PARTUUID=63e8a3c1-d28c-c2ac-8441-190c8dac04d8 initrd=\EFI\initramfs.img quiet mitigations=off'
Something to note is that not all UEFI implementations allow the passing of command line parameters to the kernel. This will vary by system, depending on how compliant with UEFI specification your system is.
If your system is unable to find the root partition, and you’re certain it’s set correctly, this is likely to be the issue. In this case, you’ll need to use the built-in command line outlined in the previous section.
Using Your System UEFI
If your system and setup supports it, this is probably the easiest way to add your boot entry.
Note that while this is entirely system dependent, it will usually require a kernel with the command line set up, with no additional parameters required.
Boot your system, and enter the UEFI setup. Check if your system has an option available to add a boot entry.
If so, locate your kernel on your EFI system partition (ESP), and select it.
That’s all there is to it. Your boot entry should now be set. Save and exit setup, and check that your system boots correctly.
As previously stated, this is very much system/config dependent. If your system supports it, and your setup is basic, it’s a great way to manage your boot entries without requiring a command line tool.
