Skip to content

The Moving Parts

Outcome: you can look at any LUKS device and name the five parts inside it — and say which part each command in this guide touches. Nothing here needs a terminal yet; chapter 4 puts every part on the screen at once.

The device, in order

A LUKS device is laid out in a line:

[ header ][ ........ encrypted data ........ ]

The header is small — 16 MB in LUKS2, 2 MB in LUKS1 — and the data segment is everything after it: your filesystem, encrypted. The header is at the very start, always, which is why copying a device's first megabytes copies its fate (chapter 8), and why "the disk is 1 TB" and "the usable space is 1 TB minus 16 MB" are both true.

The header

The header is a structured description of the vault, written in plain, readable form — luksDump prints it, and chapter 4 reads a real one field by field. It records the LUKS version, a UUID naming the device, the cipher in use, where the data segment begins, and the state of every key slot. In LUKS2 the descriptive part is stored as JSON text, and the header exists twice: a second copy sits near the end of the header area, so damage to the first copy is survivable — the lab proved this by zeroing the first 4 KB of a vault and watching it open its header anyway (transcript t05). What the second copy cannot survive is losing the keyslot area between the two copies, which is why the whole 16 MB still gets backed up.

The master key

Somewhere in the header's keyslot area sits the master key: a long random key — 512 bits in every vault this guide builds — that actually encrypts the data segment. The data is encrypted once, with this key, at format time. Nothing you do with passphrases ever re-encrypts the data, because the master key never changes. (There is an exception — cryptsetup reencrypt, a deliberate, hours-long operation — named in chapter 12 and otherwise left alone.)

Key slots and wrapped copies

The master key itself is never stored in the clear. Instead, the header holds several key slots, and each occupied slot holds a copy of the master key, encrypted with a key derived from one passphrase (or key file). LUKS1 has 8 slots; LUKS2 has 32 — not a figure of speech: the lab put a key in slot 31 and was told, asking for slot 32, Key slot 32 is invalid, please select between 0 and 31 (transcript t09).

Unlocking is unwrapping: you offer a passphrase, cryptsetup slowly stretches it into a candidate key (next section), and tries it against each occupied slot until one copy of the master key decrypts and checks out. That is why any of several passphrases can open the same disk, why adding one takes a second while formatting takes minutes of writing nothing at all, and why killing a slot — overwriting its wrapped copy — retires that passphrase completely and instantly.

The slow stretch: PBKDF and Argon2

Guessing passphrases is the obvious attack on a stolen disk, so the stretching step — the key derivation function — is deliberately expensive. LUKS1 uses PBKDF2, running a hash millions of times; the lab's LUKS1 vault calibrated itself to 2,496,608 iterations. LUKS2 defaults to Argon2id, which is expensive in memory as well as time — the lab's vault used about 100 MB of RAM per attempt — so a guessing machine cannot run millions of tries in parallel on cheap hardware. cryptsetup measures your machine at format time and tunes the cost to roughly two seconds per try. That two seconds is a shrug when you log in, and a wall when an attacker wants to try a dictionary: chapter 11 shows the benchmark numbers behind it.

Device-mapper: the part that opens

Formatting, keys and headers are all bookkeeping that cryptsetup does by reading and writing the header — no kernel help needed, which is why this guide's lab could do all of it on a machine with no disks. Opening is different. To open a vault, cryptsetup hands the unwrapped master key to the kernel's device-mapper, which creates a new, virtual block device — /dev/mapper/<name> — that encrypts and decrypts on the fly as other programs read and write it. Your filesystem lives on that device, and closing the vault removes it again. Chapter 5 teaches that step; the lab could not run it, and its transcript t08 keeps the exact error its machine produced instead, because a sandbox with no device-mapper is a fact to report, not a step to fake.

Who does what

  • cryptsetup — the only program the guide drives: formats, opens, closes, manages slots, backs up headers.
  • The kernel (dm-crypt) — does the actual encrypting while a vault is open. You never command it directly.
  • systemd and crypttab — optional ushers that open vaults at boot (chapter 9).
  • The filesystem — ext4, XFS, Btrfs, whatever you choose; it lives inside the data segment and neither knows nor cares that it is encrypted.