systemd-stub, sd-stub, linuxx64.efi.stub, linuxia32.efi.stub, linuxaa64.efi.stub - A simple UEFI kernel boot stub
/usr/lib/systemd/boot/efi/linuxx64.efi.stub
/usr/lib/systemd/boot/efi/linuxia32.efi.stub
/usr/lib/systemd/boot/efi/linuxaa64.efi.stub
ESP
/.../foo
.efi.extra.d/*.addon.efi
ESP
/.../foo
.efi.extra.d/*.cred
ESP
/.../foo
.efi.extra.d/*.raw
ESP
/loader/addons/*.addon.efi
ESP
/loader/credentials/*.cred
systemd-stub (stored in per-architecture files linuxx64.efi.stub, linuxia32.efi.stub, linuxaa64.efi.stub on disk) is a simple UEFI boot stub. An UEFI boot stub is attached to a Linux kernel binary image, and is a piece of code that runs in the UEFI firmware environment before transitioning into the Linux kernel environment. The UEFI boot stub ensures a Linux kernel is executable as regular UEFI binary, and is able to do various preparations before switching the system into the Linux world.
The UEFI boot stub looks for various resources for the kernel invocation inside the UEFI PE binary itself. This allows combining various resources inside a single PE binary image (usually called "Unified Kernel Image", or "UKI" for short), which may then be signed via UEFI SecureBoot as a whole, covering all individual resources at once. Specifically it may include:
·
A ".linux" section with the ELF Linux kernel image.
·
An ".osrel" section with OS release information, i.e. the contents of the os-release(5) file of the OS the kernel belongs to.
·
A ".cmdline" section with the kernel command line to pass to the invoked kernel.
·
An ".initrd" section with the initrd.
·
A ".splash" section with an image (in the Windows .BMP format) to show on screen before invoking the kernel.
·
A ".dtb" section with a compiled binary DeviceTree.
·
A ".uname" section with the kernel version information, i.e. the output of uname -r for the kernel included in the ".linux" section.
·
An ".sbat" section with SBAT[1] revocation metadata.
·
A ".pcrsig" section with a set of cryptographic signatures for the expected TPM2 PCR values after the kernel has been booted, in JSON format. This is useful for implementing TPM2 policies that bind disk encryption and similar to kernels that are signed by a specific key.
·
A ".pcrpkey" section with a public key in the PEM format matching the signature data in the the ".pcrsig" section.
If UEFI SecureBoot is enabled and the ".cmdline" section is present in the executed image, any attempts to override the kernel command line by passing one as invocation parameters to the EFI binary are ignored. Thus, in order to allow overriding the kernel command line, either disable UEFI SecureBoot, or dont include a kernel command line PE section in the kernel image file. If a command line is accepted via EFI invocation parameters to the EFI binary it is measured into TPM PCR 12 (if a TPM is present).
If a DeviceTree is embedded in the ".dtb" section, it replaces an existing DeviceTree in the corresponding EFI configuration table. systemd-stub will ask the firmware via the "EFI_DT_FIXUP_PROTOCOL" for hardware specific fixups to the DeviceTree.
The contents of eight of these nine sections are measured into TPM PCR 11. It is otherwise not used and thus the result can be pre-calculated without too much effort. The ".pcrsig" section is not included in this PCR measurement, since it is supposed to contain signatures for the output of the measurement operation, and thus cannot also be input to it.
When ".pcrsig" and/or ".pcrpkey" sections are present in a unified kernel image their contents are passed to the booted kernel in an synthetic initrd cpio archive that places them in the /.extra/tpm2-pcr-signature.json and /.extra/tpm2-pcr-public-key.pem files. Typically, a tmpfiles.d(5) line then ensures they are copied into /run/systemd/tpm2-pcr-signature.json and /run/systemd/tpm2-pcr-public-key.pem where they remain accessible even after the system transitions out of the initrd environment into the host file system. Tools such systemd-cryptsetup@.service(8), systemd-cryptenroll(1) and systemd-creds(1) will automatically use files present under these paths to unlock protected resources (encrypted storage or credentials) or bind encryption to booted kernels.
For further details about the UKI concept, see the UKI specification[2].
systemd-boot(7), systemd.exec(5), systemd-creds(1), systemd-sysext(8), Boot Loader Specification[5], Boot Loader Interface[4], ukify(1), systemd-measure(1), TPM2 PCR Measurements Made by systemd[6]