Fixing initrd to Regain Ubuntu Encrypted Root Prompt on Boot

Recently, I upgraded my Ubuntu 12.04 server, which uses an encrypted root directory (with LVM and LUKS). Unfortunately, somewhere along the way the upgrade broke the boot process - next time I booted, it hung for 5 seconds, then timed out and dropped to a BusyBox prompt. I quickly found a workaround which allowed me to manually intervene and continue the boot each time:

cryptsetup luksOpen /dev/sda5 root

Of course, however, I didn’t want to intervene on every boot, especially since this is normally a headless server. To fix it longterm, I eventually found this link, which hinted at the problem. Essentially, I had to locate the mapper name for the partition containing my LVM physical volume which contained the boot logical volume. I found this in /etc/crypttab, and in my case it was flash_crypt:

flash_crypt UUID=xxxxx none luks

So I rebooted, and used the workaround above with the correct name:

cryptsetup luksOpen /dev/sda5 flash_crypt

Once I’d booted the system, I regenerated the initrd image:

update-initramfs -u -k all

I knew it worked successfully, because I didn’t see this error, which I had seen before when running update-initramfs:

cryptsetup: WARNING: invalid line in /etc/crypttab -

Rebooting the system, everything now went back to normal.