Backup encrypted Ubuntu Linux harddisk

Some days ago, I switched from Ubuntu to Fedora 11. Before overwriting my old system I of course backed up the old one. What I did was simply a

dd if=/dev/sda of=/mnt/somedisk/mybackup.img

The tricky part now is to get access to your old data when you used „Full disk encryption“ for the old system. Here is what I had to do:

losetup /dev/loop1 /mnt/somedisk/mybackup.img
kpartx -a -v /dev/loop1
cryptsetup luksOpen /dev/loop1p1 foobar
lvchange -a y "/dev/oldhostname/root"
mkdir /mnt/oldsys
mount /dev/mapper/your_old_root /mnt/oldsys

If you can’t find the name of your old lv, use lvscan.