We can directly boot into the Linux kernel without any external bootloader (e.g. GRUB) by enabling support in the kernel for the EFI bootloader.
Processor type and features --->
[*] EFI runtime service support
[*] EFI stub support
[ ] EFI mixed-mode supportThe EFI bootloader also supports an initramfs to handle more complex tasks early in the boot process. Typically, mounting important filesystems that need specific kernel modules, mounting encrypted filesystems or loading firmware for hardware devices.
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
() Initramfs source file(s)
Processor type and features --->
[ ] Built-in kernel command line
Device Drivers --->
Generic Driver Options --->
[*] Maintain a devtmpfs filesystem to mount at /devThe initramfs image does not have to be embedded into the kernel with the option Initramfs source file(s), as it will be directly loaded by the EFI bootloader from the boot drive. Moreover, the initramfs will also take care of passing the appropriate command line options to the kernel, so it is not necessary to define any in the Built-in kernel command line configuration.
EFI bootloader setup
-
Compile the Linux kernel
cd /usr/src/linux make && make modules_install -
Copy the kernel image to the EFI System Partition
cp arch/x86/boot/bzImage /boot/efi/EFI/Gentoo/bzImage-x.y.z.efi -
Generate the initramfs with dracut (optionally compressed with ZSTD)
dracut --kver=x.y.z-gentoo --zstd -
Copy the new initramfs image to the EFI System Partition
cp /boot/initramfs-x.y.z-gentoo.img /boot/efi/EFI/Gentoo/initramfs-x.y.z.img -
Generate a new boot entry for this new kernel in the EFI bootloader
efibootmgr --create --disk /dev/nvme0n1 --part 1 --label 'Gentoo' --loader '\efi\gentoo\bzImage-x.y.z.efi' --unicode 'initrd=\efi\gentoo\initramfs-x.y.z.img'In this example, the partition
/dev/nvme0n1p1is the EFI System Partition and paths are relative to its root.
Btrfs root partition
The previous setup allows to easily boot from a Btrfs root partition by using the initramfs to mount it. Btrfs can be compiled into the kernel or added as module.
File systems --->
<*/M> Btrfs filesystemDracut will auto-detect the format of the root partition as long as it is already mounted. Alternatively, btrfs can be manually added to the initramfs image with the following option in the configuration of Dracut (e.g. /etc/dracut.conf)
filesystems+=" btrfs "