Skip to content

Unlocking at Boot

Outcome: a second disk that opens itself during boot — by asking you, or by key file — using /etc/crypttab and /etc/fstab. Label first: the lab's sandbox cannot boot anything, so this chapter is documented-only — built from the cryptsetup and systemd documentation, using only concepts the earlier chapters proved live. On a real machine each step is checkable as you go, and the checks are named.

Two files, two jobs

Booting with encrypted disks is a division of labour:

  • /etc/crypttab answers which vaults exist and how each one opens: its name, its device, and where its key comes from.
  • /etc/fstab answers the ordinary question it always answers: once a filesystem exists, where is it mounted — asked here about the /dev/mapper/... device that opening creates.

The usher between them is the init system: on modern distributions, systemd reads crypttab early in boot (through its cryptsetup generator), opens each vault — prompting on the console if a vault's key source is "ask" — and only then does the fstab mounting proceed. The disk your system boots from is a special case handled one step earlier, inside the initramfs, and is normally arranged by your installer; this chapter is about the disks you add yourself.

crypttab, field by field

One line per vault, four fields:

vault  UUID=032cf058-d263-40fe-9005-257e1e2752ad  none  luks
  1. Name — vault: the name the mapping gets, /dev/mapper/vault. The same name you chose by hand in chapter 5.
  2. Device — written as UUID=..., never /dev/sdb1. Device letters are assigned in discovery order and change — a disk that is sdb today is sdc after you plug in a USB stick. The UUID is the one from luksUUID (chapter 4), and it cannot wander.
  3. Key source — none means ask me: at boot, the console prompts for a passphrase for this vault. A path instead of none means use this key file — the arrangement below.
  4. Options — luks states the obvious-but-required: this is a LUKS device. Common companions: nofail (boot on without it if the device is absent — right for a sometimes-attached external disk, wrong for one your home directory lives on) and discard (pass TRIM through to an SSD — a performance and wear choice with a small privacy footnote: the device then reveals which blocks are unused).

The prompt-at-boot arrangement

With the line above, boot pauses and asks for the passphrase of vault, exactly as cryptsetup open would. Then fstab takes its turn:

/dev/mapper/vault  /mnt/vault  ext4  defaults  0  2

Nothing here is LUKS-specific — by the time fstab reads the line, the vault is simply a device that exists. That separation is why a mistyped crypttab line fails at the prompt stage while a mistyped fstab line fails at the mount stage, and the error messages will tell you which act of the play you are in.

The no-typing arrangement: a key file on the root disk

If the system disk is itself encrypted (opened by a passphrase you type), a second disk can borrow that protection: put its key file on the encrypted root filesystem, where it is ciphertext at rest like everything else, and name it in crypttab:

data  UUID=<the data disk's UUID>  /root/data-key.bin  luks

Chapter 7's housekeeping applies with full force: the key file is root-owned, mode 400, and it exists in exactly one place besides your backup of it. Understand what this arrangement decides: both disks now stand or fall with the system disk's passphrase. That is usually precisely the intent — one secret typed, the whole machine opens — and it equally means the second disk alone, stolen with its sibling, is protected only by that same passphrase. Convenience and exposure are the same feature read from two sides; choose it on purpose.

Checks, in boot order

  • cryptsetup luksUUID <device> — the UUID you paste is the UUID the header actually holds.
  • A reboot with your hand near the console the first time; a typo here is discovered at the least convenient moment by design, so schedule the discovery.
  • If boot does not ask, or asks and fails: the vault can still be opened by hand from a rescue shell with chapter 5's commands — nothing in this chapter changes the header, only who reads it, and when.