Encrypt a volume and destroy it by its key
Task
Create a LUKS-encrypted volume, add a second passphrase, back up the header, and then destroy the data instantly by erasing the key rather than overwriting the disk. Along the way, see why the header backup is not optional.
Steps
- Format the loop file as LUKS2 with a passphrase:
cryptsetup luksFormat --type luks2 /tmp/crypt.img. Note that LUKS2 uses Argon2, which is memory-hard. - Open it, create a filesystem inside, mount it, and write a recognisable file.
- Add a second passphrase to a new key slot with
cryptsetup luksAddKeyand confirm both open the volume. Readcryptsetup luksDumpand find the two populated slots. - Back up the header:
cryptsetup luksHeaderBackup /tmp/crypt.img --header-backup-file /root/crypt.header. This is the step people skip. - Simulate header damage: overwrite the first megabyte of the image with
dd if=/dev/zero of=/tmp/crypt.img bs=1M count=1 conv=notrunc. Confirm the volume can no longer be opened -- the data is intact but unreachable. - Restore the header from your backup and confirm the volume opens again. State what would have happened without the backup.
- Now destroy it properly:
cryptsetup luksErase /tmp/crypt.img, which destroys the key slots. Confirm the data is unrecoverable instantly, regardless of medium, and without overwriting 128MB.
Verify
cryptsetup luksDump /tmp/crypt.img | grep -c 'luks2' # while it exists
cryptsetup open /tmp/crypt.img lab <<<"wrongpass" 2>&1 | grep -qi 'no key' && echo "wrong pass refused"
# after luksErase:
cryptsetup open /tmp/crypt.img lab 2>&1 | grep -qi 'device.*not.*valid\|no.*luks' && echo "keys destroyed"
The final check confirms cryptographic erasure: the ciphertext is still on the disk, but with the key slots gone it is permanently unreadable. That is why encrypting a disk from first use makes its eventual decommissioning a one-command job.
Notes
Step 4 is the one that matters most in practice. The master key lives in the header, encrypted under your passphrase. Corrupt those first few megabytes -- a stray dd, a partition tool writing a new table -- and every byte on the volume is gone, passphrase or not. luksHeaderBackup takes two seconds.