Backup! Backup!

This week, I learnt that even slightly modi­fy­ing the header of a LUKS pro­tec­ted hard-disk will res­ult in the com­plete and irre­triev­able destruc­tion of all data on the disk. And I learnt it the hard way.

My old 1TB Seag­ate external hard-drive was dam­aged before by a write cycle that wouldn’t die a few years ago. At the time, I man­aged to res­cue all the data with the check­disk tool because it was using the NTFS filesystem.

This year, I reformat­ted the entire disk and exper­i­mented with a LUKS encryp­ted hard-disk run­ning the ext4 filesys­tem. Two days ago, the worst came to pass, and my hard-disk began to make click­ing noises the likes of which told me it would not be mount­able properly.

Without read­ing any­thing about LUKS at the time, I pro­ceeded to repeatedly attempt to decrypt my disk long enough to run fsck on the disk.

Which turned out in ret­ro­spect, to be the worst thing I could have done. As the FAQ for cryptsetup states:

First, disks die. The rate for well-treated (!) disk is about 5% per year, which is high enough to worry about. There is some indic­a­tion that this may be even worse for some SSDs. This applies both to LUKS and plain dm-crypt partitions.

Second, for LUKS, if any­thing dam­ages the LUKS header or the key-stripe area then decrypt­ing the LUKS device can become impossible. This is a fre­quent occurrence.

Whether it was appar­ently dam­aged, or that I ran fsck which wrote things into the header, I had effect­ively found myself with a key to a doorknob that had mutated into an Eldritch hor­ror. Whatever that was behind that door, is for all pur­poses, lost to all.

So let this be a warn­ing to any­one using a LUKS encryp­ted drive. Backup your disk head­ers so that one day, should you find your­self under the unfor­tu­nate cir­cum­stances of a dam­aged hard drive, you will be able to change the doorknob with the one that worked with your key.