# Linux Secure Boot Luks

> Use when deploying Secure Boot and LUKS full-disk encryption on Linux systems you administer. Covers Secure Boot state verification and Machine Owner Key enrollment, shim and bootloader signing, TPM2-backed LUKS unlocking with systemd-cryptenroll, passphrase and recovery key management, LUKS key slot rotation, and recovery planning for failed boot or lost keys. Defensive boot integrity and encryption for laptops, workstations, and servers.

- Skill: `mizazhaider-ceh/linux-secure-boot-luks` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/linux-secure-boot-luks`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/linux-secure-boot-luks/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/linux-secure-boot-luks

---


Secure Boot and LUKS protect different parts of the same story. LUKS
encrypts data at rest, so a stolen disk yields nothing without a key.
Secure Boot verifies the boot chain, so a tampered bootloader or kernel
does not run in the first place. Either one alone leaves a gap: an
encrypted disk with an unverified boot chain can be booted with a
tampered kernel that captures the passphrase, and a verified boot chain
with an unencrypted disk gives up its data to anyone who removes the
drive. Deploy them together, plan recovery before you need it, and
never let a single lost passphrase become a data-loss incident.

## Quick Workflow

1. Verify Secure Boot state and firmware mode (UEFI, not legacy BIOS)
   before changing anything.
2. Confirm the boot chain: shim signed by the distribution key, boot
   loader and kernel signed, and any out-of-tree modules enrolled via
   a Machine Owner Key (MOK) you control.
3. Set up LUKS on the target volume with a strong passphrase, then
   verify the header and key slots before putting data on it.
4. Enroll a second unlocking method (TPM2 for unattended servers, or a
   recovery key stored offline) so one lost passphrase is not fatal.
5. Back up the LUKS header to offline storage and record the recovery
   key in the vault, never in the same place as the machine.
6. Test recovery: reboot, unlock with each method, and simulate a lost
   passphrase against a test volume before relying on the setup.
7. Monitor: alert on Secure Boot state changes, failed unlocks, and
   key slot changes.

## 1. Verifying Secure Boot state

Secure Boot only works on UEFI systems with the firmware in Secure
Boot mode and the distribution keys enrolled. Check the firmware state
from the OS, confirm the boot loader actually used Secure Boot, and
check whether any custom keys are enrolled. A machine that reports
Secure Boot as disabled but was assumed protected is a finding, not a
configuration detail.

```bash
mokutil --sb-state
bootctl status 2>/dev/null | head -20
mokutil --list-enrolled | head -20
efibootmgr -v 2>/dev/null | head -20
```

Expected on a protected host: `SecureBoot enabled`, a `bootctl`
report showing the system booted via UEFI with Secure Boot active,
and an enrolled key list containing the distribution key (and your
MOK, if you enrolled one). If the firmware was reset or the keys
cleared, Secure Boot stops protecting the chain even though the OS
looks unchanged, so include this check in your provisioning and
periodic compliance scans.

## 2. Machine Owner Keys for out-of-tree modules

Signed distributions ship a shim signed by Microsoft's third-party
UEFI key, which then trusts the distribution key for the boot loader
and kernel. Out-of-tree kernel modules (for example, proprietary
graphics drivers or DKMS modules) are not signed by the distribution
key, so Secure Boot refuses to load them unless you sign them with a
key you enroll as a Machine Owner Key. Generate the MOK on an offline
machine, enroll it through the firmware's MOK manager at next boot
(which requires physical presence, by design), sign the modules, and
keep the private key offline.

```bash
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 3650 -subj "/CN=Example Org Secure Boot Signing/"
mokutil --import MOK.der
# reboot, complete enrollment in the MOK manager, then sign modules:
/usr/src/kernels/$(uname -r)/scripts/sign-file sha256 MOK.priv MOK.der /lib/modules/$(uname -r)/extra/mymodule.ko
mokutil --test-key MOK.der
```

The physical-presence requirement is a feature: it means a remote
attacker cannot silently enroll a key. Never enroll a MOK from a key
generated on the machine being protected and left on its disk, and
never share one MOK private key across an entire fleet without
understanding that its compromise forces re-enrollment everywhere.

## 3. LUKS setup and verification

LUKS2 is the current format, with Argon2id as the key derivation
function and support for up to 32 key slots. Format a volume with a
strong passphrase, open it, create a filesystem, and verify the header
before trusting it. Choose the cipher explicitly rather than relying
on defaults you have not reviewed, and use a passphrase with real
entropy: LUKS key derivation slows guessing but does not rescue a
weak passphrase.

```bash
cryptsetup luksFormat --type luks2 --cipher aes-xts-plain64 --key-size 512 /dev/sdX
cryptsetup luksDump /dev/sdX | head -30
cryptsetup open /dev/sdX secure-data
mkfs.ext4 /dev/mapper/secure-data
cryptsetup status secure-data
```

Verify from `luksDump` that the type is LUKS2, the key derivation
function is Argon2id, and exactly the key slots you expect are
enabled. An unexpected enabled slot is a finding: someone (or some
earlier process) added a key you do not know about, and it must be
explained or removed before the volume holds sensitive data. Never
run `luksFormat` on a device without triple-checking the device name;
it destroys existing data immediately and without confirmation beyond
the passphrase prompt.

## 4. TPM2-backed unlocking

On servers that must reboot unattended, a passphrase prompt at every
boot is an availability problem. TPM2 enrollment binds unlocking to
the platform state: `systemd-cryptenroll` seals the LUKS key to PCR
measurements of the firmware and boot chain, so the disk unlocks
automatically only when the machine boots the expected firmware and
kernel. If the boot chain changes (firmware update, kernel change),
the PCR values change and unlocking fails until you re-enroll, which
is the protection working as designed, not a bug.

```bash
systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/sdX
cryptsetup luksDump /dev/sdX | grep -A2 "Keyslot"
systemd-cryptenroll --wipe-slot=tpm2 /dev/sdX
```

Bind to PCR 7 (Secure Boot state) at minimum, and consider PCRs 0, 2,
and 4 for firmware and boot loader measurements depending on how often
your fleet updates firmware. Every firmware or kernel update in the
measured set requires a re-enrollment plan, or the next unattended
reboot becomes an outage with a passphrase prompt nobody is present
to answer. Always keep a passphrase slot enabled alongside TPM2, so a
PCR mismatch is recoverable rather than catastrophic.

## 5. Recovery planning and header backup

The LUKS header contains the key material encrypted under each slot's
key. Lose the header and you lose the data, even with the passphrase.
Lose every key and you lose the data, even with the header. Back up
the header to offline storage, store the recovery passphrase in the
vault (not on the machine, not in the same ticket system as the
machine's location), and test the restore procedure on a scratch
volume before you need it for real.

```bash
cryptsetup luksHeaderBackup /dev/sdX --header-backup-file /root/secure-data-header.img
sha256sum /root/secure-data-header.img
cryptsetup luksAddKey /dev/sdX
cryptsetup luksDump /dev/sdX | grep -E "Keyslot|Area"
```

Full key lifecycle detail, including slot rotation, header restore,
and TPM2 and FIDO2 token enrollment, lives in the
linux-luks-key-management sub-skill. The recovery drill to run
quarterly: restore a header backup to a test device, unlock with the
recovery key, and confirm the data is readable. A backup that has
never been restore-tested is a hope, not a plan.

## Edge cases

- Secure Boot does not protect against an attacker with physical
  access who can change firmware settings, so pair it with a firmware
  password and, for laptops, a chassis and boot-order policy.
- TPM2 unlocking on a machine whose firmware updates change PCR values
  will fail closed after the update, so schedule re-enrollment as part
  of the firmware update runbook, not as an afterthought.
- LUKS encryption protects data at rest only: once the volume is
  unlocked and mounted, a running attacker with sufficient privilege
  reads plaintext, so disk encryption is not a substitute for access
  control on a live system.
- Suspend-to-disk (hibernation) writes memory, including keys, to
  swap; on an encrypted system the swap partition must be encrypted
  too, or hibernation leaks plaintext to disk.
- A MOK enrolled for one purpose (for example, graphics drivers) can
  sign any kernel module, so protect the MOK private key as a signing
  key, not as a throwaway, and scope its lifetime.
- Dual-boot systems with another OS that writes to the EFI partition
  can disturb the boot chain and change PCR measurements, so test
  Secure Boot and TPM2 unlocking after any dual-boot change.
- `cryptsetup` device names (`/dev/sdX`) are not stable across
  reboots on multi-disk systems, so scripts and fstab entries must use
  UUIDs, never bare device names, for encrypted volumes.
- Header backups are as sensitive as the data itself: anyone with the
  header and any one key slot passphrase unlocks the volume, so store
  header backups with the same controls as the recovery keys.

## Key references

- cryptsetup and LUKS documentation: https://gitlab.com/cryptsetup/cryptsetup
- systemd-cryptenroll manual: https://www.freedesktop.org/software/systemd/man/systemd-cryptenroll.html
- systemd-cryptsetup manual: https://www.freedesktop.org/software/systemd/man/systemd-cryptsetup@.service.html
- UEFI Secure Boot documentation: https://uefi.org/specifications
- MITRE ATT&CK T1552 Unsecured Credentials (key material): https://attack.mitre.org/techniques/T1552/
- NIST SP 800-111 Guide to Storage Encryption: https://csrc.nist.gov/pubs/sp/800/111/final

