Skip to content

LUKS for Mere Mortals

A stolen laptop is a bad day. A stolen laptop whose disk can be read by whoever picks it up — your mail, your photos, your saved passwords, your work — is a much worse one. LUKS is how Linux closes that gap: it encrypts a whole disk or partition, so the data on it is unreadable noise until someone types a passphrase you chose. No passphrase, no data — not slowed down, not hidden, gone, in the only sense cryptography can offer.

This guide explains what LUKS is and what it honestly protects against, then builds one: a small encrypted vault in an ordinary file, formatted, opened, and taken apart again. Along the way it covers the parts other guides rush past: the header that holds the keys and why you back it up, the key slots that let several passphrases — or a key file, or a TPM chip — unlock the same disk, what happens at boot, what it costs in speed, and the sentence every LUKS user should read twice: if every passphrase is lost, the data is unrecoverable, by design.

The lab that wrote this guide ran the real thing: cryptsetup 2.7.0, the standard Ubuntu package, against a 64 MB file standing in for a disk. It formatted LUKS2 and LUKS1 vaults, read their headers field by field, added, changed and destroyed keys, built a key file, backed a header up, smashed a copy of that header on purpose and restored it, and benchmarked the ciphers on the machine's own processor.

What the lab could not do, it did not fake. Its machine is a sandbox with no real disks at all — no loop devices, no device-mapper — so the one step that needs the kernel to open the vault could not run there. The guide teaches that step from the documentation, labels it as such wherever it appears, and keeps the sandbox's own error message in the lab transcripts as the receipt. Everything on either side of that boundary — formatting, keys, headers, benchmarks — was run for real, and criteria.md keeps the full ledger of which is which.

What this guide covers

  • What LUKS is — the threat model stated honestly: what disk encryption stops, what it never will, and why "the laptop was off" is the load-bearing sentence
  • The moving parts — the header, the master key, the key slots, the data segment, and device-mapper — and which part holds what
  • Installing cryptsetup — the package, the version check, and the throwaway file that stands in for a disk throughout the lab
  • Formatting your first vault — luksFormat for real, and reading the result with luksDump until the header makes sense
  • Opening, mounting, closing — turning a passphrase into a readable device, putting a filesystem on it, and putting it away again
  • Passphrases and key slots — adding, changing and killing keys: eight slots in LUKS1, thirty-two in LUKS2, each one tested in the lab
  • Keyfiles — a file that is the key: making one, adding one, and the housekeeping that keeps it from becoming the weakest link
  • The header and its backup — why the first 16 MB of the device is the whole ballgame, backing it up, and what a destroyed header costs
  • Unlocking at boot — /etc/crypttab and /etc/fstab: asking for the passphrase at startup, or opening a second disk without one
  • Unlocking with a TPM — letting the machine's TPM chip hold the secret, what that buys, and what it quietly gives up
  • Speed and cipher choice — the benchmark, run on the lab's own CPU: AES-NI, why XTS, and why the honest answer is usually "the default"
  • Resizing and other surgery — growing a vault, and the operations that need care because the header is watching
  • Recipes — encrypt a USB stick end to end, add a spare passphrase before a trip, rotate a passphrase, and wipe a device so nothing comes back
  • The neighbours — VeraCrypt, BitLocker and FileVault, ZFS's own encryption, and file-level tools like age: what each does that LUKS doesn't, and vice versa
  • Limits — the lost passphrase with no back door, the running machine that is already unlocked, the header as a single point of failure, and the rest of the fine print
  • Troubleshooting — the wrong passphrase message, the device that will not open, the slot that will not die, and the mistakes this guide's lab made so you don't have to
  • Glossary — the terms, collected in one place

What it doesn't cover

Encrypting the disk your system already boots from, after the fact. That is an installer-time decision on every major distribution, and retrofitting it means rebuilding the system around the encryption — a different project from this guide's second disks, USB sticks and vault files. Network unlock (a server handing over the key at boot), smart-card and FIDO2 unlock, and multi-machine key escrow are real LUKS features with real documentation; they are pointed at, not taught. Forensic recovery of damaged headers beyond a clean backup restore is out — chapter 8 is plain about why there is usually nothing to recover.

How to use this guide

Read chapter 1 for the threat model and chapter 2 before formatting anything — knowing which part holds the keys turns later confusion into a named problem. Chapters 3 to 5 build and open your first vault; chapters 6 to 8 are the ones to read slowly even if you never plan to touch a key slot, because the header and its backup decide whether a bad day is an inconvenience or a total loss. The lab's transcripts live in luks-lab/transcripts/. Every command in the lab runs against a file in a scratch folder, never a real disk — keep it that way in your own practice until the commands are boring.


Part of the series

This guide is one of the For Mere Mortals guides: plain-language guides to the tools programmers and makers use.

Related guides:

License

The writing in this guide is licensed under CC BY 4.0. Code examples and lab scripts are licensed under the MIT License.