Skip to content

About

Arch Linux Secure Boot with a signed UKI (booster-um, sbctl) and a TPM2 PCR 7 LUKS2 token.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Secure Boot, UKI, and TPM2 on Arch Linux

UEFI loads one signed UKI. booster-um builds it with booster and ukify, sbctl signs it, and a TPM2 token bound to PCR 7 unlocks the LUKS2 root. Example machine: HP EliteBook. Firmware menus differ by vendor.

A UKI is one UEFI PE file: stub, kernel, initramfs, and command line. https://wiki.archlinux.org/title/Unified_kernel_image

booster-um is an AUR package for systemd Arch Linux systems. It writes esp/EFI/Linux/<os_id>-<pkgbase>.efi. With ID=arch in /etc/os-release and the linux package, that file is arch-linux.efi. linux-lts becomes arch-linux-lts.efi.

Filename and package scope: https://github.com/Zile995/booster-um

Leave the current bootloader in place until the UKI entry has booted with Secure Boot on. Then remove that bootloader by its own method.

1. Record the boot state

# bootctl status > /root/bootctl-before-sb.txt
# cat /proc/cmdline > /root/cmdline-before-sb.txt
# esp=$(bootctl --print-esp-path)
# cp -a "$esp" /root/esp-backup-$(date +%Y%m%d)

The copy sits on the encrypted root, not on the ESP.

$ lsblk -o NAME,TYPE,UUID,FSTYPE,MOUNTPOINTS

<LUKS-UUID> below is the UUID of the crypto_LUKS device, not the UUID of the filesystem inside it.

bootctl --print-esp-path fails when this boot is not UEFI or the ESP is not mounted. Do not copy a guessed path. The copy is the current boot files. It is not a copy of the LUKS header, which section 9 rewrites. https://man.archlinux.org/man/bootctl.1

2. Install

# pacman -S booster sbctl tpm2-tss efibootmgr

Install booster-um from the AUR. It depends on systemd-ukify. efibootmgr is optional in that package and required here because the UKI is booted as an EFI entry.

https://aur.archlinux.org/packages/booster-um https://wiki.archlinux.org/title/Arch_User_Repository https://wiki.archlinux.org/title/Systemd-cryptenroll

mkinitcpio can stay installed. Do not remove it before the UKI entry boots.

The AUR is unsupported. Review the booster-um PKGBUILD before building it. Installing these packages does not change the firmware boot order. The current bootloader remains the entry that boots until the signed UKI is first and Secure Boot is on. https://wiki.archlinux.org/title/Arch_User_Repository

3. Enroll keys

Reboot into the firmware setup and clear the Platform Key so the machine is in Setup Mode. sbctl expects Secure Boot mode left enabled while those keys are cleared. Custom Mode, where the firmware only stops checking signatures, is not Setup Mode.

# systemctl reboot --firmware-setup

After logging in again:

$ sbctl status
# sbctl create-keys
# sbctl enroll-keys -m -f

-m enrolls Microsoft certificates. -f enrolls the firmware's built-in db and KEK defaults.

$ sbctl status

Setup Mode is disabled after a successful enroll. Secure Boot is not necessarily enforcing until the next reboot. If enrollment stops with File is immutable, clear the immutable bit on the efivar files named in that error and run sbctl enroll-keys again.

Do not reboot after sbctl enroll-keys until section 7 has a signed UKI and that entry is first in the boot order. The next boot can start enforcing signatures. Dropping -m or -f leaves option ROMs or the OEM keys unchecked. On some machines that blocks a firmware update, or leaves the firmware setup unreachable. This enrollment changes PCR 7, so a TPM2 token created earlier no longer unseals. The signing keys are unencrypted files under /var/lib/sbctl/keys. sbctl's default file key type is meant for an encrypted root. https://man.archlinux.org/man/sbctl.8 https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot

4. Command line and crypttab

/etc/kernel/cmdline is the command line ukify embeds. Do not put initrd=, vmlinuz, or microcode paths in it. booster-um also reads this file when cmdline is unset in its own config.

For a LUKS root named by crypttab, the command line points at the mapper node:

root=/dev/mapper/cryptroot rw

If / is btrfs, copy subvol= or subvolid= from the / line in /etc/fstab into rootflags=. booster does not assume a subvolume name.

root=/dev/mapper/cryptroot rw rootflags=subvol=<subvol>

/etc/crypttab:

cryptroot UUID=<LUKS-UUID> none x-initrd.attach

booster reads /etc/crypttab and bundles entries marked x-initrd.attach. When a crypttab entry and rd.luks.* name the same UUID, the crypttab entry wins. TPM2 tokens created by systemd-cryptenroll are taken from the LUKS2 header. https://github.com/anatol/booster/blob/master/docs/manpage.md

/etc/crypttab.initramfs is the mkinitcpio file. booster's default path is /etc/crypttab. https://wiki.archlinux.org/title/Systemd-cryptenroll

booster reads the TPM2 token from the LUKS2 header. The crypttab line has no tpm2-device= option. That option is for systemd-cryptsetup.

/etc/kernel/cmdline and /etc/crypttab are read when the UKI is built. Edits made after booster-um -G stay unused until the next build. The name in crypttab and the name in root=/dev/mapper/... have to be the same string. If they differ, booster stops before mounting, with no unlock spec for that mapper. On btrfs, leaving out subvol= or subvolid= mounts the filesystem's default subvolume, which may not be this installation. An initrd=, vmlinuz, or microcode path in the embedded command line points at a file outside the signed UKI. https://github.com/anatol/booster/blob/master/docs/manpage.md https://github.com/Zile995/booster-um

5. booster-um configuration

/etc/booster-um.yaml:

efistub: true
remove_leftovers: false
efistub_config:
  default_entry: linux

efistub defaults to false. true creates an EFI boot entry. default_entry is the kernel package name (linux, or linux-lts if that is the entry to boot). New entries are appended to the end of the boot order (append_entries defaults to true). Check the order in section 7 before rebooting.

remove_leftovers defaults to true and deletes vmlinuz-* and booster-* under /boot on each build. Leave it false while the previous bootloader still loads those files.

Signing is already the default when sbctl is installed: sign_uki: true, sbsign: false. The UKI splash image defaults to /usr/share/systemd/bootctl/splash-arch.bmp. Plymouth is a second splash, in section 6.

A missing or invalid /etc/booster-um.yaml is ignored and the defaults are used: efistub off, remove_leftovers on. That build deletes vmlinuz-* and booster-* under /boot and creates no EFI entry. universal: true in /etc/booster.yaml makes booster-um generate only fallback UKIs, whatever generate_fallback is set to here. default_entry is the kernel package name, not the .efi filename. New entries are appended to the boot order, so the previous bootloader stays first until section 7 moves it. https://github.com/Zile995/booster-um

6. Plymouth (optional)

Plymouth is a separate splash, drawn by the initramfs after the firmware has shown the UKI bitmap. Install the package and tell booster to bundle it. The Plymouth instructions on the ArchWiki that edit mkinitcpio hooks do not apply.

# pacman -S plymouth

/etc/booster.yaml:

enable_plymouth: true
modules_force_load: <gpu-module>

<gpu-module> is the kernel module in use for the GPU (lspci -k). Append quiet splash to /etc/kernel/cmdline. Do not set booster.log=console in that command line; booster then uses Plymouth's text plugin.

Leave quiet splash off until one UKI boot has shown whether the passphrase prompt appears. Those parameters hide booster's messages, including a failed unlock. Without the GPU module in modules_force_load, the image has no KMS driver for Plymouth. booster.log=console selects Plymouth's text plugin. booster does not read mkinitcpio's plymouth hook. https://github.com/anatol/booster/blob/master/docs/manpage.md https://wiki.archlinux.org/title/Plymouth

7. Build the UKI

Keys from section 3 must already be enrolled. crypttab from section 4 must already exist, so the image contains it.

# booster-um -G
# sbctl verify
# efibootmgr -v

sbctl verify should report the UKI signed. The file is <esp>/EFI/Linux/arch-linux.efi for the linux package. The EFI label defaults to the NAME in os-release plus the package, Arch Linux (linux).

booster-um -C deletes <esp>/EFI/Linux and the old initramfs and vmlinuz files. Do not run it as part of this setup.

booster-um -C deletes every UKI under esp/EFI/Linux, including one belonging to another system that shares the ESP. sbctl verify lists EFI binaries it finds on the ESP. An unsigned file that this UKI does not load is not a file to delete. Two Arch installations on one ESP both default to arch-linux.efi and the later build overwrites the earlier file. Set os_id when the ESP is shared. https://github.com/Zile995/booster-um https://man.archlinux.org/man/sbctl.8

If the UKI entry is not the first boot entry, move it there before the reboot that turns enforcement on. efibootmgr prints the entry numbers and BootOrder; efibootmgr -o sets that order.

https://man.archlinux.org/man/efibootmgr.8

8. Reboot and confirm Secure Boot

# reboot
$ sbctl status

After that reboot, sbctl status should show Secure Boot enabled and Setup Mode disabled. sbctl(8) states that this reboot is enough and that the firmware does not need a further change. If Secure Boot is still disabled, turn it on in the firmware setup and reboot again. Enroll the TPM token only after status shows Secure Boot enabled and Setup Mode disabled.

https://man.archlinux.org/man/sbctl.8

The first boot with Secure Boot on still asks for the LUKS passphrase. The TPM token does not exist yet.

This reboot is the one that starts enforcing signatures. If the first boot entry is still an unsigned bootloader, or the UKI is not signed, the firmware stops. Disable Secure Boot in the firmware setup to boot the previous entry. Do not enroll the TPM token while sbctl status still shows Secure Boot disabled or Setup Mode enabled. PCR 7 would be bound to that other state. https://man.archlinux.org/man/sbctl.8 https://www.freedesktop.org/software/systemd/man/latest/systemd-cryptenroll.html

9. Enroll the TPM2 token

PCR 7 changes when Secure Boot is enabled or disabled, and when PK, KEK, db, or dbx changes. --tpm2-pcrs= defaults to binding no PCRs; this setup passes 7.

Enroll only while Secure Boot is enabled and Setup Mode is disabled. A token bound only to pre-boot PCRs, including PCR 7 alone, can be unsealed by another system that leaves those PCRs unchanged. https://www.freedesktop.org/software/systemd/man/latest/systemd-cryptenroll.html https://wiki.archlinux.org/title/Systemd-cryptenroll https://github.com/anatol/booster/blob/master/docs/manpage.md

Back up the LUKS header first. Enrollment writes a new key slot into it, and the header backup contains those slots, so keep the file on the encrypted root and off the ESP. --tpm2-device=auto requires exactly one TPM; if list shows more than one, pass that device path. The volume must be LUKS2. Do not pass --wipe-slot=password or --wipe-slot=all. The passphrase slot is the recovery path. A later firmware or dbx update can change PCR 7. The passphrase still opens the volume, and the token has to be enrolled again. https://man.archlinux.org/man/cryptsetup-luksHeaderBackup.8 https://wiki.archlinux.org/title/Systemd-cryptenroll

# cryptsetup luksHeaderBackup /dev/disk/by-uuid/<LUKS-UUID> --header-backup-file /root/luks-header-backup
# chmod 600 /root/luks-header-backup
$ systemd-cryptenroll --tpm2-device=list
# systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/disk/by-uuid/<LUKS-UUID>

The command asks for an existing passphrase, adds a new LUKS2 key slot, and seals that key to the TPM. The passphrase slot stays. The new token is stored in the LUKS2 header, and the crypttab entry is already in the UKI, so this step does not need another booster-um -G.

# cryptsetup luksDump /dev/disk/by-uuid/<LUKS-UUID>

The dump lists a systemd-tpm2 token next to the existing key slots.

# reboot

The volume should open without a passphrase. The passphrase still works when the TPM refuses the token.

10. After the UKI boots

Remove the previous bootloader only after this boot. Leave <esp>/EFI/Linux/ in place.

When nothing still loads vmlinuz-* or booster-* from /boot, remove_leftovers can be set to true and the UKI rebuilt with booster-um -G.

On later upgrades, booster's hook rebuilds the initramfs and booster-um's hook rebuilds the UKI when booster, microcode, DKMS modules, or firmware packages change. sbctl's pacman hook signs UKIs that are already in its file database. A UKI that is not in that database yet is signed by booster-um when it is created.

Do not remove the previous bootloader before this Secure Boot boot has succeeded. That entry is the way back if the UKI does not start. After a kernel upgrade, run sbctl verify on the new UKI before rebooting. booster-um leaves signing of those rebuilt images to the sbctl hook, and an unsigned UKI does not boot while Secure Boot stays on. A firmware update can change PCR 7. The passphrase still works, and the token then has to be enrolled again. booster-um -C still deletes esp/EFI/Linux. https://github.com/Zile995/booster-um https://github.com/Foxboron/sbctl/blob/master/contrib/pacman/ZZ-sbctl.hook https://wiki.archlinux.org/title/Systemd-cryptenroll

If boot or unlock fails

What happens What to do
The machine does not boot the UKI In the firmware, disable Secure Boot and boot the previous bootloader if it is still installed.
The passphrase prompt appears Type the passphrase. If firmware keys or the Secure Boot switch changed, PCR 7 no longer matches. Re-enroll from the enabled, user-mode state: systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 --wipe-slot=tpm2 /dev/disk/by-uuid/<LUKS-UUID>
The enrolled keys are wrong Clear the Platform Key in the firmware, or run sbctl reset, return to Setup Mode, and repeat section 3. Rebuild and sign the UKI before the next enforcing boot. Re-enroll the TPM token after Secure Boot is enabled again.

Turning Secure Boot off changes PCR 7. A token enrolled while Secure Boot was on does not unseal again until Secure Boot is enabled and, if the firmware keys changed, until the token is enrolled again. https://www.freedesktop.org/software/systemd/man/latest/systemd-cryptenroll.html

sbctl reset clears the Platform Key and takes the machine out of Secure Boot so keys can be enrolled again. https://man.archlinux.org/man/sbctl.8

--wipe-slot=tpm2 removes TPM2 key slots. Combined with a new enrollment, the slot just added is kept. https://www.freedesktop.org/software/systemd/man/latest/systemd-cryptenroll.html

Checklist

  • ESP and command line copied under /root
  • booster, sbctl, tpm2-tss, efibootmgr, and AUR booster-um installed
  • Firmware was in Setup Mode; sbctl enroll-keys -m -f completed
  • /etc/kernel/cmdline and /etc/crypttab written
  • /etc/booster-um.yaml has efistub: true and remove_leftovers: false
  • booster-um -G produced a signed UKI, and that entry is first in the boot order
  • After reboot, sbctl status shows Secure Boot enabled and Setup Mode disabled
  • LUKS header backed up under /root before TPM enrollment
  • TPM2 token enrolled with --tpm2-pcrs=7 only after that status
  • Following boot unlocks without a passphrase
  • Previous bootloader removed only after that boot

About

Arch Linux Secure Boot with a signed UKI (booster-um, sbctl) and a TPM2 PCR 7 LUKS2 token.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors