EFI stub kernel
The (U)EFI firmware present in many newer computers can function as bootloader, allowing you to boot without installing a separate bootloader.
Create a FAT32 filesystem inside:
If you don't have mkfs.vfat (part of sys-fs/dosfstools) installed, you can use busybox:
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 /dev/sda2:
For GPT systems, using root=PARTUUID=... might be preferable. To find out, you can use gdisk:
UEFI does not support loading a separate initramfs for your kernel. So if you need an initramfs, it has to be built into the kernel via CONFIG_INITRAMFS_SOURCE. It must be an uncompressed CPIO archive with .cpio filename extension. Example for a genkernel initramfs (replace zcat with xzcat or bzcat if you have changed the compression algorithm in the kernel configuration):
Now build the kernel and copy the image to your EFI partition as EFI/Boot/bootx64.efi. Example (with your EFI partition mounted to /mnt/EFI):
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 sys-boot/efibootmgr and make them known to your UEFI.