EFI stub

The (U)EFI firmware present in many newer computers can function as bootloader, allowing you to boot without installing a separate bootloader.

Partitioning
You need to create a partition of type "EFI System partition", which is EF00 on GPT and EF on MBR. Example using :

Create a FAT32 filesystem inside:

If you don't have mkfs.vfat (part of ) installed, you can use busybox:

Configuration
In order to boot directly from UEFI, the kernel needs to have CONFIG_EFI_STUB support enabled.

UEFI does not pass kernel parameters to the kernel during normal boot, so you need to hardcode them via CONFIG_CMDLINE. Example for the root partition on :

For GPT systems, using root=PARTUUID=... might be preferable. To find out, you can use gdisk:

Initramfs
EFI Stub can load an initramfs and pass it to the kernel, but this requires passing a parameter from the EFI bootloader (ie. initrd=\efi\boot\myinitrd.img). This parameter cannot be built into CONFIG_CMDLINE as outlined above. This may defeat the purpose of using EFI stub as many users prefer it as a way to avoid the necessity of a bootloader and/or dealing with efi bootmgr. Another possibility is to embed the initramfs directly in the kernel image. In order to do this:


 * Generate the initramfs using your preferred method (Genkernel, Dracut, etc.)
 * Ensure the image is not compressed (just a cpio archive). Genkernel and Dracut both have command line switches for this.
 * Rename the initramfs with a .cpio extension, the kernel requires this to embed a cpio archive. The kernel image (with the cpio archive within it) will still be compressed as usual.
 * Ensure that the initramfs has the correct read-permissions for the user building the kernel. Most users build the kernel as the root user and may skip this step.  Dracut makes the initramfs image readable only by the root user, so if you build the kernel as any other user adjust its permissions first. Failing to do so, and ignoring the kernel build warnings will result in a kernel with no embedded initramfs and potentially an unbootable system.


 * Install the kernel on the EFI partition.

Installation
Now build the kernel and copy the image to your EFI partition as. Example (with your EFI partition mounted to ):

Adding more kernels
You can optionally make additional kernels known to UEFI. This is especially useful if you want to test more kernels or dual-boot with another operating system. These will be shown in the boot selection prompt, normally shown after you press a hotkey at the right time during system initialization.

Ensure that you have CONFIG_EFI_VARS enabled in your kernel, install and make them known to your UEFI.

External resources

 * EFI Stub - booting without a bootloader Blog posting which this article is partially based on.
 * GPT fdisk homepage with information and tutorials about GPT partitioning.
 * EFI bootloaders listing alternative ways to boot an (U)EFI system.