The EFI Boot Stub¶
On the x86 and ARM platforms, a kernel zImage/bzImage can masqueradeas a PE/COFF image, thereby convincing EFI firmware loaders to loadit as an EFI executable. The code that modifies the bzImage header,along with the EFI-specific entry point that the firmware loaderjumps to are collectively known as the “EFI boot stub”, and live inarch/x86/boot/header.S and arch/x86/boot/compressed/eboot.c,respectively. For ARM the EFI stub is implemented inarch/arm/boot/compressed/efi-header.S andarch/arm/boot/compressed/efi-stub.c. EFI stub code that is sharedbetween architectures is in drivers/firmware/efi/libstub.
For arm64, there is no compressed kernel support, so the Image itselfmasquerades as a PE/COFF image and the EFI stub is linked into thekernel. The arm64 EFI stub lives in arch/arm64/kernel/efi-entry.Sand drivers/firmware/efi/libstub/arm64-stub.c.
By using the EFI boot stub it’s possible to boot a Linux kernelwithout the use of a conventional EFI boot loader, such as grub orelilo. Since the EFI boot stub performs the jobs of a boot loader, ina certain sense itIS the boot loader.
The EFI boot stub is enabled with the CONFIG_EFI_STUB kernel option.
How to install bzImage.efi¶
The bzImage located in arch/x86/boot/bzImage must be copied to the EFISystem Partition (ESP) and renamed with the extension “.efi”. Withoutthe extension the EFI firmware loader will refuse to execute it. It’snot possible to execute bzImage.efi from the usual Linux file systemsbecause EFI firmware doesn’t have support for them. For ARM thearch/arm/boot/zImage should be copied to the system partition, and itmay not need to be renamed. Similarly for arm64, arch/arm64/boot/Imageshould be copied but not necessarily renamed.
Passing kernel parameters from the EFI shell¶
Arguments to the kernel can be passed after bzImage.efi, e.g.:
fs0:> bzImage.efi console=ttyS0 root=/dev/sda4
The “initrd=” option¶
Like most boot loaders, the EFI stub allows the user to specifymultiple initrd files using the “initrd=” option. This is the only EFIstub-specific command line parameter, everything else is passed to thekernel when it boots.
The path to the initrd file must be an absolute path from thebeginning of the ESP, relative path names do not work. Also, the pathis an EFI-style path and directory elements must be separated withbackslashes (). For example, given the following directory layout:
fs0:> Kernels\ bzImage.efi initrd-large.img Ramdisks\ initrd-small.img initrd-medium.img
to boot with the initrd-large.img file if the current workingdirectory is fs0:Kernels, the following command must be used:
fs0:\Kernels> bzImage.efi initrd=\Kernels\initrd-large.img
Notice how bzImage.efi can be specified with a relative path. That’sbecause the image we’re executing is interpreted by the EFI shell,which understands relative paths, whereas the rest of the command lineis passed to bzImage.efi.
The “dtb=” option¶
For the ARM and arm64 architectures, a device tree must be provided tothe kernel. Normally firmware shall supply the device tree via theEFI CONFIGURATION TABLE. However, the “dtb=” command line option canbe used to override the firmware supplied device tree, or to supplyone when firmware is unable to.
Please note: Firmware adds runtime configuration information to thedevice tree before booting the kernel. If dtb= is used to overridethe device tree, then any runtime data provided by firmware will belost. The dtb= option should only be used either as a debug tool, oras a last resort when a device tree is not provided in the EFICONFIGURATION TABLE.
“dtb=” is processed in the same manner as the “initrd=” option that isdescribed above.