Notes on Encryption
Recently I have been running out of hard disk space. I hummed and hawed a bit before deciding to upgrade - there's only so much porn you can delete, after all. Over the past few days I have been banging my head against a variety of issues - issues which are finally solved. Herein I leave a note for myself should I ever want to set this stuff up again, and maybe even help some people in the future who stumble over this in Google. As a result: expect lameness and boredom. Feel free to skip it.
1. The old setup and the upgrade plan.
I had a PC with 2x 200GB IDE drives and a 500GB external drive for backup. I'd set it up so that this external drive was encrypted - it's pretty easy to swipe an external drive, after all, and I wouldn't want other people to get at my passwords, financial details, and naked pictures of the exes. The original plan was just to upsize this setup - get 2 500GB drives and a 1TB external drive for backup. This wouldn't give me any overhead for incremental backups (where you store, say, 3 days' worth of system images but only the changes between them are stored) but I'm not planning to fill them all up, so I could do the incremental backup for a few more years yet.
Then through some conversations with colleagues and online I reconsidered. Turns out it would cost me less to get 4x 500GB internal drives. I could get more disk space for less money, and build a RAID array for redundancy. Instead of backing up the whole system I could back up the bits that matter - programming, music, photographs - on the existing 500GB external drive. I can generate 8GB of files from a photoshoot but even then the 500GB would give me some overhead. A cockup at this point meant that where I thought my motherboard had 4 IDE channels it actually only has two, so I had to go get a PCI IDE controller to keep ysing my DVD drive. £20 from Maplins - not the cheapest, but the most convenient.
I had copies of all my data on the backup drive, and I was removing the 2 200GB drives with the existing system on them. Normally when I upgrade hard disks I end up copying the old system onto the new one, so it results in the same system but with more space available to it. I figured that this time, though, trying to jibble a system image into something that will boot and set up RAID was about as much effort as doing a fresh install and copying /home to the new system so I'd do that instead. After about 6 years of using Debian and having to wrestle it whenever I wanted to do something new I thought I'd give Ubuntu a shot. The software seems newer and the configuration more straightforward.
Oh, there was one more thing: I wanted the whole system to be encrypted.
2. The new setup, and how to achieve it.
So I now had a PC with 4x 500GB hard disks, an Ubuntu 7.10 install CD, and a plan. We'd take a slice of 300MB from the beginning of each disk. On the first two disks we'd use this as a RAID1 array (mirroring) for /boot. This would be the only unencrypted partition. On the last two disks the 300MB slices would form a RAID0 array (striping) that would be used for encrypted swap. The remaining large partitions on the 4 disks would be used for a RAID5 array (striping with distributed parity). On top of this sits LUKS/dm-crypt for full-disk encryption, and on top of this sits LVM for resizing purposes. Diagramatically:
Raw devices -> Software RAID -> Encryption -> LVM -> filesystem.
(Instructions on installing using the alternative installer here)
You'd think that this would be all you need, right? Well, no. The installer fucks up and this system won't boot. It'll appear to hang before announcing it can't find vg-root. You need to edit your GRUB commandline (hit esc during startup and follow the instructions) to add the following magic:
cryptopts=source/dev/md1,target=filesystem
source is the device where your encrypted root filesystem lives; target is just a friendly name, as far as I know. Boot this and it'll prompt you for the passphrase you set up during the install, and you should find your new system boots. This wasn't documented anywhere, by the way - one had to delve into the initrd to find out what it was trying to read and what it was expecting.
Once it's booted up, run sudo vim /boot/grub/menu.lst and change the two lines that begin # kopt so they include the cryptopts line above. Save and quit, then run sudo update-grub to write this to your boot sector.
You can now set up your encrypted swap. This one's a doddle: edit /etc/crypttab so it looks like this:
#