Disk encryption with LUKS
How LUKS encrypts a block device under keyslots, the cryptsetup commands, unlocking at boot with crypttab, and TPM or network unlock in brief.
Disk encryption with LUKS
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Disk encryption protects data at rest: a stolen disk, a returned cloud volume, a decommissioned server. It does nothing once the volume is unlocked and the system is running.
- LUKS is a header on the device plus dm-crypt. Data is encrypted with one random volume key, and each keyslot holds a copy of that key encrypted under a passphrase, key file or token.
- Because of keyslots, you can add, change and remove passphrases without re-encrypting any data. LUKS2, the default format, allows up to 32.
- Keyslots are protected by a deliberately slow key derivation function, PBKDF2 or Argon2, so guessing passphrases is expensive.
- Lose the header and the data is gone, whatever passphrases you remember. Back it up with luksHeaderBackup and keep the backup off the disk.
- /etc/crypttab names devices to unlock at boot, the way fstab names filesystems to mount. The opened device appears under /dev/mapper/.
- Servers that reboot unattended unlock without a typed passphrase: from a TPM with systemd-cryptenroll, or from a network server with Clevis and Tang.
The disk that leaves the building
Permissions, firewalls and sudo rules all assume an attacker goes through the running system. A disk pulled from a server, a laptop left in a taxi, a cloud volume detached and reattached elsewhere, or a failed drive sent back under warranty skips all of that. Anyone with the disk can mount it on another machine and read everything.
Encrypting the block device closes that path. Without the key, the disk is random noise. That is the whole scope: once the volume is unlocked and mounted, the running system reads plaintext like any other, and encryption no longer stands between an attacker on that system and the data.
How LUKS is put together
dm-crypt is the kernel’s encryption layer: a device-mapper target that encrypts every block written to a device and decrypts every block read. LUKS, the Linux Unified Key Setup, is a standard header at the start of the device that stores how to do that and how to get the key. cryptsetup is the tool.
cryptsetup(8) describes the key design. The data is encrypted with a single random volume key. That key is stored in keyslots, each a copy of it encrypted under a different passphrase or key file. To unlock, LUKS tries the passphrase against the keyslots, recovers the volume key, and hands it to dm-crypt.
This indirection is why changing a passphrase is instant. A hotel analogy holds well: the safe has one combination, and the front desk keeps it in several sealed envelopes, each opened by a different guest’s PIN. Cancel a guest by shredding their envelope. The safe’s combination never changes.
cryptsetup-luksFormat(8) says LUKS2 is the default format and can have up to 32 keyslots, against 8 for LUKS1. LUKS2 also allows tokens, metadata that describes how to get a passphrase from a TPM or a network server.
Slow on purpose
A keyslot is protected by a password-based key derivation function: PBKDF2, or Argon2i or Argon2id, which LUKS2 supports. The man page says the LUKS2 default is set at compile time and shown by cryptsetup --help. The point of all of them is to make each guess expensive.
To show the scale, I timed PBKDF2-SHA256 with Python’s hashlib on this Mac. It is a measurement of the algorithm on Apple silicon, not of cryptsetup:
PBKDF2-SHA256, 1 iterations: 0.004 ms per guess, about 260,892 guesses/s on one core
PBKDF2-SHA256, 1,000 iterations: 0.258 ms per guess, about 3,877 guesses/s on one core
PBKDF2-SHA256, 1,000,000 iterations: 230.702 ms per guess, about 4 guesses/s on one core
cryptsetup benchmarks the machine at format time and picks parameters that take a set time to unlock. You wait a second once per boot. An attacker waits that second for every guess. Argon2 also demands memory per guess, which makes cheap parallel guessing hardware much less effective. A long passphrase still matters most.
The commands
From cryptsetup(8) and its sub-pages, cryptsetup 2.x. Not run here, as there is no Linux machine:
cryptsetup luksFormat /dev/sdb1 # destroys data; asks for YES and a passphrase
cryptsetup open /dev/sdb1 data # creates /dev/mapper/data
mkfs.ext4 /dev/mapper/data && mount /dev/mapper/data /srv/data
cryptsetup luksDump /dev/sdb1 # header: version, cipher, keyslots, tokens
cryptsetup luksAddKey /dev/sdb1 # another passphrase in a free keyslot
cryptsetup luksKillSlot /dev/sdb1 1 # remove keyslot 1
cryptsetup luksHeaderBackup /dev/sdb1 --header-backup-file sdb1-header.img
umount /srv/data && cryptsetup close data
The header backup deserves its own line. If the header is overwritten, by a mistaken mkfs or a damaged sector, the keyslots are gone and no passphrase can recover the data. Keep the backup somewhere safe and off that disk. It is sensitive too: it holds the keyslots as they were, so a passphrase removed later still opens a volume restored from that backup.
LUKS often sits under LVM or over RAID, and lsblk shows the stack: disk, partition, crypt, then lvm.
Unlocking at boot
/etc/crypttab is to encrypted devices what fstab is to filesystems. Per crypttab(5), each line is name device key-file options:
# name device key options
data UUID=3f2a6c1e-0000-0000-0000-000000000000 none luks,discard
That opens the LUKS device with that UUID as /dev/mapper/data and, because the key file is none, asks for a passphrase. Then /etc/fstab mounts /dev/mapper/data. Options like nofail and _netdev mean the same as in the fstab lesson. If the root filesystem is encrypted, unlocking happens in the initramfs, so the initramfs must be rebuilt after changes, which the initramfs lesson covered.
Servers that reboot by themselves
A passphrase typed at boot does not suit a server in a data centre. Two common answers, in brief:
TPM. The machine’s TPM chip can hold a key and release it only if the boot measurements in its PCR registers match. systemd-cryptenroll --tpm2-device=auto /dev/sdb1 adds a TPM-backed keyslot, and tpm2-device=auto in crypttab uses it. The PCR choice is the security decision. In systemd 262’s man page, the default when --tpm2-pcrs= is not given is to bind to no PCRs at all, so the TPM releases the key to whatever boots on that machine. Many guides say the default is PCR 7, the Secure Boot state. That was true until systemd 258, whose release notes say the default was dropped because Secure Boot policies now change about as often as firmware, which kept breaking literal PCR 7 bindings. They recommend systemd-pcrlock policies, or signed policies via --tpm2-public-key=, for binding to the boot state instead.
Network-bound disk encryption. Clevis on the client and a Tang server on the network: the disk unlocks only when it can reach the Tang server. A server stolen from the rack cannot reach it and stays locked. It is the usual choice in RHEL environments.
Whichever you use, keep a passphrase keyslot as a recovery path.
About the video
The embed is a clip, 4:55 to 22:34, of apalrd’s adventures’ “Full Disk Encryption (w/ TPM2) on Linux”, October 2026. The clip’s chapters are “LUKS Basics”, “What is a TPM?”, “Systemd-Cryptenroll” and “Full Disk Encryption”. It skips an intro, a sponsor read and a section about the presenter’s hardware. It is a recent, hands-on treatment of exactly the LUKS and TPM half of this lesson. It does not cover header backups, crypttab in general or Clevis and Tang, which the lesson adds, with two longer videos in deeper that do. English was judged from the channel and English auto-captions, the content from the chapters and description.
What was run: the PBKDF2 timing on macOS. LUKS behaviour is from the cryptsetup man pages on man7.org, crypttab(5) and the systemd 262 systemd-cryptenroll(1) page and systemd’s NEWS file, checked 2026-11-28. The crypttab line above is written from crypttab(5), with a placeholder UUID.
Where this fits
The last storage lesson leaves the local disk entirely: network filesystems: NFS and SMB.
Check yourself
An admin leaves the company. Their passphrase is one of three in the LUKS header. Do you need to re-encrypt the disk?
No. Remove their keyslot with cryptsetup luksKillSlot or luksRemoveKey. The volume key, and so the data, is unchanged, and their passphrase no longer opens anything. If they could have copied the volume key itself, re-encryption is the only full answer.
Why is a LUKS header backup sensitive, and why is it necessary?
It contains the keyslots, so anyone with it and an old passphrase can unlock the data even after that passphrase is removed from the disk. Without it, a damaged header makes the data unrecoverable.
What does the line `data UUID=3f2a... none luks,discard` in /etc/crypttab do?
At boot it opens the LUKS device with that UUID as /dev/mapper/data, asks for a passphrase because the key file is none, and allows discards to pass through.
A server's encrypted root is enrolled to the TPM with no PCRs selected. What does that protect against, and what not?
It stops someone who takes the disk out of the machine. It does not stop someone who boots the whole machine, possibly with a different OS, since the TPM releases the key without checking what booted.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.