The Header and Its Backup
Outcome: a header backup made and proven — by destroying a copy of the vault's header in two stages and restoring it. This chapter is the most important one in the guide, and everything in it ran in the lab: transcript t05. If you read one chapter twice, read this one.
Why the header is the whole ballgame
Recall the layout from chapter 2: the first 16 MB of a LUKS2 device holds everything except the data — the metadata, the keyslot area with every wrapped copy of the master key, the cipher settings. The remaining gigabytes are ciphertext encrypted under that master key.
It follows with uncomfortable logic: if the header is destroyed, the data is gone, even though every byte of it is still sitting there. The passphrases are not in the data. The master key is not in the data. There is nothing to brute-force and nothing to appeal to; a headerless LUKS device is indistinguishable from random noise, because as far as the universe is concerned it is random noise with a long backstory. Disk encryption guides that skip this point are leaving out their subject's central fact.
The respectable ways a header dies in
real life are mundane: an installer or
partitioning tool writing to the wrong
device; a bootloader repair that
scribbles on the first megabytes of
the wrong disk; a dd aimed carelessly
(you will meet this one again in
chapter 16); gradual corruption in
exactly the wrong few megabytes.
The backup
cryptsetup luksHeaderBackup vault.img \
--header-backup-file vault-header.bak
ls -l vault-header.bak
The lab's result:
-r-------- 1 root root 16777216 vault-header.bak
16,777,216 bytes — the whole header area, byte for byte, created read-only. Two properties to understand before you file it away:
- The backup is exactly as powerful as the header. Anyone holding it can attack your passphrases offline at their leisure, and if they ever learn one, the backup is the vault for unlocking purposes. Guard it like a key file (chapter 7): encrypted storage, a password manager's vault, an offline medium you control.
- The backup is a snapshot of your slots, not of your intentions. It restores the key slots as they were when the backup was taken. Add or kill a slot afterwards and the backup neither knows nor cares: restore it, and the killed passphrase rises from the dead while the added one vanishes. Rule of the house: every slot change earns a fresh header backup, taken right after the change is proven.
Store the backup somewhere other than the device it describes. A backup on the encrypted disk itself is a librarian locked inside the library.
The two wounds, demonstrated
The lab made a copy of its practice
vault — vault-copy.img, identical
twin, same passphrase — and hurt it
twice.
Wound one: the first 4 KB zeroed.
This destroys the primary header's
magic and its start. luksDump
answered with a complete, normal
header dump. LUKS2 keeps a second
copy of its metadata near the end of
the header area, and cryptsetup fell
back to it without being asked. Small
damage near the front is survivable
by design — a LUKS2 kindness LUKS1
does not share.
Wound two: the whole 16 MB zeroed. Now both metadata copies and the entire keyslot area are zeros. The answers, verbatim:
$ cryptsetup luksDump vault-copy.img
Device vault-copy.img is not a valid LUKS device.
$ cryptsetup open --test-passphrase \
--key-file pass1.txt vault-copy.img
Device vault-copy.img is not a valid LUKS device.
Note the second refusal: the correct passphrase, offered to a device whose data segment is still fully intact and fully encrypted, gets nothing — there is no header left to check the passphrase against. This is the forgotten-passphrase problem's harder twin (chapter 15): not a lock you cannot pick, but a lock that no longer exists.
The restore
cryptsetup luksHeaderRestore \
vault-copy.img \
--header-backup-file vault-header.bak
cryptsetup makes you type YES —
this command overwrites a header,
which is surgery of exactly the kind
this chapter is about. Afterwards the
dump was whole again, the epoch and
UUID unchanged, and --test-passphrase
passed: the vault had returned from
the dead completely, because the
backup contained everything the data
segment needed.
Three honest qualifications:
- The restore works because the backup came from this device. Restoring a foreign header onto a device pairs that device with the wrong master key: it will then "open" and decrypt its data into garbage. cryptsetup checks what it can; the rest is on you.
- A restore is also the only remedy of its kind. There is no vendor, no recovery service, no clever tool that rebuilds a destroyed header from the data. The forensic literature is unanimous because the mathematics is.
- LUKS1 headers back up the same way (2 MB, one copy, no fallback twin) and restore the same way. If your estate includes an old LUKS1 disk, its header backup matters more, not less.
The habit to take away
Format a vault → make a header
backup, off the device. Change any
slot → prove the change → make a
fresh header backup. Once a year,
check the backup still reads
(luksDump works on a backup file's
header when restored to a scratch
copy — or keep the practice from
chapter 3 and test on a copy, never
the original). Ten minutes of
ceremony, against the one failure
this tool cannot forgive.