Linux › Section E · How the Linux kernel boots › Topic E.4
UEFI secure boot and chainloading
Malware that runs before the operating system is hard to detect and hard to remove. UEFI Secure Boot answers it with a chain of digital signatures from the firmware to the kernel. This topic follows that chain, shows how Linux fits into a system built around Microsoft's keys, and how GRUB hands control to another operating system.
Why sign the boot path?
Whatever runs first controls everything after it. A bootkit, malware hidden in the boot loader or early boot code, can hide itself from the operating system and from security software that starts later. UEFI Secure Boot closes that gap: when it is enabled, the firmware runs an EFI program, such as a boot loader, only if the program carries a valid signature from a trusted key, or its hash is explicitly allowed. Each stage then checks the next before running it, forming a chain of trust. Secure Boot does not encrypt anything or protect a running system; it only decides which code is allowed to start.
Keys held by the firmware
The firmware stores several signature databases in its non-volatile memory. The Platform Key (PK) belongs to the platform owner, usually the manufacturer, and controls changes to the Key Exchange Key list (KEK). Holders of a KEK may update the two lists that matter at boot: db, the allowed certificates and hashes, and dbx, the forbidden ones, which wins over db. Most PCs ship with Microsoft certificates in KEK and db: one for Windows and one, the UEFI third-party CA, used to sign other vendors' boot loaders. Linux distributions rely on that third-party certificate, because they cannot expect every PC to carry their own keys.
shim: the bridge to Linux
Rather than have Microsoft sign every GRUB and kernel build, distributions use shim, a small first-stage boot loader. Microsoft signs each distribution's shim with the third-party CA, and shim contains the distribution's own certificate. The firmware checks shim against db; shim then checks GRUB against its built-in certificate; GRUB, through shim's verification service, checks the kernel. On disk you find files such as shimx64.efi, grubx64.efi and mmx64.efi (the MOK manager) in the distribution's directory on the EFI system partition, for example /boot/efi/EFI/ubuntu or /boot/efi/EFI/fedora. GRUB in this mode also refuses commands that could bypass the checks.
Worked example: following the chain
A laptop with Secure Boot on starts Fedora. 1. The firmware reads the boot entry pointing at shimx64.efi on the EFI system partition. 2. It checks shim's signature: made by Microsoft's third-party CA, which is in db, and not listed in dbx, so shim runs. 3. shim loads grubx64.efi and checks it against Fedora's certificate built into shim. 4. GRUB reads its configuration and loads the kernel; the kernel's signature is checked the same way before it runs. 5. The kernel starts, notes that Secure Boot is active and, on many distributions, enables lockdown. If any check fails, that stage refuses to run the next file and the firmware or shim shows an error, which is the intended outcome when a file has been tampered with.
Machine Owner Keys and mokutil
Sometimes you need to trust code your distribution did not sign, such as a driver module you compiled. shim keeps a second list, the Machine Owner Keys (MOK), which the machine's owner controls. To add one, run mokutil --import key.der, with the certificate in DER format; mokutil asks for a one-time password and records a pending request. At the next boot shim starts MokManager, which asks you, at the physical console, to confirm the enrolment with that password. The console step stops malware enrolling its own key silently. mokutil --list-enrolled shows enrolled keys, and mokutil --sb-state reports whether Secure Boot is enabled.
Lockdown and kernel modules
Many distribution kernels go further when Secure Boot is active and enter lockdown mode, closing ways that root could change the running kernel, such as loading unsigned modules or writing raw kernel memory. The visible effect is that a driver built outside the distribution, for example by DKMS for a graphics or virtualisation package, will not load until it is signed with a trusted key, typically an enrolled MOK; modprobe fails and dmesg reports a key problem. The cure is to sign the module and enrol the key, not to switch off security for good.
Revocation and the 2026 certificate change
Signing only helps if bad code can be withdrawn. When a signed boot loader turns out to be exploitable, its hash or certificate can be added to dbx, and SBAT, a generation number embedded in shim and GRUB, lets whole vulnerable releases be revoked at once. Certificates also age: Microsoft's 2011 third-party UEFI CA expired on 27 June 2026. Microsoft states that machines without the new certificates keep starting normally, so shims already signed with it keep booting, but new shims are signed with Microsoft's 2023 CA. A machine whose db lacks that certificate needs a firmware or db update, often delivered through fwupd or the vendor, before it can boot the new shim.
Turning Secure Boot off
Secure Boot can be disabled in the firmware set-up screens to run unsigned kernels or experimental loaders. That works, but it removes protection against boot-level malware, and some software, such as certain anti-cheat systems and corporate policies, expects it on. For custom work it is usually better to keep it enabled and sign your builds with an enrolled MOK. Some firmware lets an owner replace all the keys with their own; that gives full control, but removing the wrong keys can stop other systems or add-in cards from starting.
Chainloading another system
Chainloading means that, instead of loading a Linux kernel, GRUB loads another boot loader and passes control to it. On BIOS systems the other system's loader often sits in the first sector of its partition, so a GRUB entry sets root to that partition and runs chainloader +1, which loads that sector. On UEFI it is simpler: every operating system keeps its own boot loader as a file on the EFI system partition, and GRUB chainloads that .efi file. You can also skip GRUB entirely: the firmware's own boot menu, usually reached with a function key that varies by maker, can start any registered loader.
Worked example: a Windows entry on UEFI
Task: add Windows Boot Manager to the GRUB menu on a UEFI Ubuntu machine where os-prober is off. 1. Back up /etc/grub.d/40_custom, then below its existing lines add a block that opens with menuentry "Windows Boot Manager" { and contains, one per line: insmod part_gpt, insmod fat, insmod chain, search --no-floppy --file --set=root /EFI/Microsoft/Boot/bootmgfw.efi and chainloader /EFI/Microsoft/Boot/bootmgfw.efi, closed by }. 2. The insmod lines load GPT, FAT and chainloading support; search finds the partition holding that file; chainloader starts it. 3. Run update-grub. 4. grep Windows /boot/grub/grub.cfg confirms the entry was included. 5. Reboot and choose it. With Secure Boot on, this works because Windows Boot Manager carries Microsoft's signature.
Common mistakes to avoid
First, thinking Secure Boot encrypts the disk or protects a running system: it only controls what starts. Second, disabling it permanently to load one unsigned driver, instead of signing the module with an enrolled MOK. Third, approving a MokManager enrolment you did not start yourself. Fourth, chainloading with BIOS-style chainloader +1 on a UEFI system, where the target is an .efi file. Fifth, adding entries to grub.cfg instead of 40_custom. Sixth, assuming the 2011 certificate's expiry stops existing installations from booting; the risk is with new shims on firmware that lacks the 2023 certificate.
Key takeaways
Secure Boot lets the firmware run only EFI programs signed by keys in db and not revoked in dbx; PK and KEK control who may change those lists. Distributions use a Microsoft-signed shim, which verifies GRUB, which verifies the kernel. Owners add their own keys as MOKs with mokutil --import, confirmed in MokManager at boot. Under lockdown, unsigned modules will not load. dbx and SBAT revoke vulnerable loaders; since June 2026 new shims rely on Microsoft's 2023 CA. Chainloading lets GRUB start another loader: chainloader +1 on BIOS, the .efi file on UEFI, added through 40_custom.
Flashcards
Flashcard
UEFI feature that runs only EFI programs signed by trusted keys
Test your understanding
Question 1 of 5
With Secure Boot on, which program does the firmware itself verify on a typical Ubuntu or Fedora machine?
Question 2 of 5
A driver you compiled yourself refuses to load on a Secure Boot machine. What is the best fix?
Question 3 of 5
After mokutil --import mykey.der, what must happen before the key is trusted?
Question 4 of 5
On a UEFI machine, how does GRUB usually chainload Windows?
Question 5 of 5
Microsoft's 2011 third-party UEFI CA expired in June 2026. What is the main practical effect?
