Lanzaboote Secure Boot Setup

Target(right): machine on which NixOS is installed

Executor(left): machine where you’ll run commands from

Lanzaboote replaces systemd-boot with signed Unified Kernel Images (kernel, initrd and command line in one EFI binary). A host opts in by listing lanzaboote.nix in its includedFeatures in flake.nix; every other host boots plain systemd-boot. Only the desktop opts in at the moment.

flowchart LR
    A[add lanzaboote.nix] --> B[rebuild]
    B --> C[first boot: keys generated]
    C --> D[firmware: setup mode]
    D --> E[next boot: systemd-boot enrolls keys]
    E --> F[firmware: Secure Boot on]

The opt-in lives in version control because an evaluation that misses it installs an unsigned systemd-boot, and firmware enforcing Secure Boot refuses to start it: the machine stops at the firmware’s Secure Boot violation screen. For the same reason, turn Secure Boot off in firmware before removing the module from a host.

Enable Lanzaboote

Add "lanzaboote.nix" to the host’s includedFeatures in flake.nix, then deploy

rebuild <target_machine_IP>

Reboot once. generate-sb-keys.service creates the keys in /var/lib/sbctl (persisted), and prepare-sb-auto-enroll.service re-signs the ESP and places the enrollment files under /efi/loader/keys/auto

sudo sbctl status
sudo sbctl verify

kernel- files and .conf or initrd files report as unsigned or with invalid pe header: expected, only the nixos-generation-*.efi images need a signature. Don’t delete them, the host won’t boot without them.

Enroll Keys

Enrollment happens in firmware Setup Mode: systemd-boot finds the files on the ESP and writes them to the firmware, together with the Microsoft keys. Those stay enrolled because GPU and NIC option ROMs are signed by Microsoft; without them the firmware refuses to run the GPU’s ROM and stops at boot.

Reset the firmware to Setup Mode

Desktop

  1. Reboot, spam F2 during boot

  2. Switch to Advanced Mode (F2)

  3. Navigate to Boot → Secure Boot

  4. Set Secure Boot Mode to Custom

  5. Enter Key Management

  6. Set Factory Key Provision to Disabled

    Otherwise the firmware puts its factory keys back

  7. Select Reset to setup mode

  8. Don’t confirm

  9. Navigate to Save & Exit

  10. Select Save & Exit Setup

  11. Confirm

Server

  1. Reboot, spam Del during boot
  2. Navigate to Security → Secure Boot
  3. Set Secure Boot Mode to Custom
  4. Enter Key Management
  5. Select Reset to setup mode
  6. Confirm, confirm again

Boot once more so systemd-boot enrolls the keys, then confirm

sudo sbctl status

Expected output

Setup Mode:    ✓ Disabled
Secure Boot:   ✗ Disabled

Enable Secure Boot

Turn on enforcement

Desktop

  1. Reboot, spam Del during boot
  2. Switch to Advanced Mode (F2)
  3. Navigate to Boot → Secure Boot
  4. Set Secure Boot to Enabled
  5. Navigate to Save & Exit
  6. Select Save & Exit Setup
  7. Confirm

Server

  1. Reboot, spam Del during boot
  2. Navigate to Security → Secure Boot
  3. Set Secure Boot to Enabled
  4. Hit Esc
  5. Navigate to Save & Exit
  6. Select Save Changes and Reset
  7. Confirm
bootctl status

Expected output

Secure Boot: enabled (user)

TPM2 LUKS Binding

The TPM releases the LUKS key only while the chosen PCRs (Platform Configuration Registers) hold the values they had at enrollment. The initrd SSH unlock stays available as a fallback whenever it refuses.

PCR Measures Changes when
0 Firmware code BIOS update
7 Secure Boot state and enrolled keys Secure Boot toggled, keys changed
11 Unified kernel image Every generation with a new kernel, initrd or command line

Bind to PCRs 0 and 7. PCR 11 would refuse the key after almost every rebuild. Without Secure Boot enforced, PCR 7 is the same for any OS booted from USB, so the binding only protects the disk once it leaves the machine; with Secure Boot on, only signed images reach the point where the key is released.

Find the LUKS partition, then enroll; it asks for the LUKS passphrase

ls /dev/disk/by-partlabel/ | grep luks
sudo systemd-cryptenroll --wipe-slot=tpm2 --tpm2-device=auto --tpm2-pcrs=0+7 \
  /dev/disk/by-partlabel/<disk>-luks

For more information, reference: https://www.freedesktop.org/software/systemd/man/latest/systemd-cryptenroll.html

Re-run the same command after a BIOS update, or after enabling Secure Boot or changing its keys: PCR 0 or 7 moved, so the TPM refuses until it is enrolled against the new values.