brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: cryptsetup luksHeaderBackup saves the one part of a LUKS disk you cannot rebuild

Backup
~/tips/tip-security-cryptsetup-luksheaderbackup

sudo cryptsetup luksHeaderBackup /dev/sdb1 --header-backup-file /root/sdb1-header.img

Saves the LUKS header and keyslots to a file, so a damaged header does not mean lost data.

On an encrypted LUKS disk, a small area at the start decides whether your data can be read at all. I want a copy of it somewhere safe.

The cryptsetup man page is direct about it: if the header of a LUKS volume gets damaged, all data is permanently lost unless you have a header backup. The backup command stores the header and the keyslot area in a file.

sudo cryptsetup luksHeaderBackup /dev/sdb1 --header-backup-file /root/sdb1-header.img

Replace /dev/sdb1 with your encrypted device, and check it with lsblk first so you name the right one. The matching restore command is:

sudo cryptsetup luksHeaderRestore /dev/sdb1 --header-backup-file /root/sdb1-header.img

Warning: restore replaces all keyslots on the device, and only the passphrases from the backup work afterwards. Use it only when you are sure of the device and the file.

The same man pages carry a warning that people miss. The backup file together with a passphrase valid at the time of the backup opens the data area, even if that passphrase was changed or removed later. You also lose the ability to wipe the device securely by overwriting the header and keyslots. You have to erase every header backup too, or overwrite the encrypted data area. So keep the file somewhere private, away from the disk and out of any shared folder, and make a fresh backup after you change a passphrase.

Further reading: cryptsetup(8) man page, cryptsetup-luksHeaderBackup(8), cryptsetup-luksHeaderRestore(8)

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link