Mounting an encrypted LVM volume in Ubuntu

For whatever reason, finding simple instructions on mounting an encrypted LVM volume with Ubuntu is hard. Setting up encryption at install time and then unlocking the volume at boot time is very simple and transparent. If you take the hard drive out and attempt to mount on another machine, it isn’t so simple (or maybe I’m just doing this wrong).

1. Run fdisk and make sure you can see the partitions. In my case the drive showed up as sdd.

# fdisk -l /dev/sdd
Disk /dev/sdd: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a29e1

Device Boot Start End Blocks Id System
/dev/sdd1 * 2048 499711 248832 83 Linux
/dev/sdd2 501758 488396799 243947521 5 Extended
/dev/sdd5 501760 488396799 243947520 83 Linux

In a typical Ubuntu installation, the /dev/sdx5 partition is what you want to mount.

2. Run cryptsetup to unlock the volume

# cryptsetup luksOpen /dev/sdd5 olddrive
Enter passphrase for /dev/sdd5:

3. vgscan will show you the volume groups contained in the encrypted volume.

# vgscan
Reading all physical volumes. This may take a while...
Found volume group "dt" using metadata type lvm2

The volume groups you find will likely be the same as your hostname (e.g. johns-laptop)

4. Activate the volumes and mount the old root.

# vgchange -a y
2 logical volume(s) in volume group "dt" now active
# lvscan
ACTIVE '/dev/dt/root' [224.76 GiB] inherit
ACTIVE '/dev/dt/swap_1' [7.88 GiB] inherit
# mkdir /media/olddrive; mount /dev/dt/root /media/olddrive

5. Your old root volume is now available at /media/olddrive.

What’s going on here? Maybe this helps?

# lsblk
sdd 8:48 0 232.9G 0 disk
├─sdd1 8:49 0 243M 0 part
├─sdd2 8:50 0 1K 0 part
└─sdd5 8:53 0 232.7G 0 part
└─olddrive (dm-1) 252:1 0 232.7G 0 crypt
├─dt-root (dm-2) 252:2 0 224.8G 0 lvm
└─dt-swap_1 (dm-3) 252:3 0 7.9G 0 lvm

All done? Unmount.

# umount /media/olddrive
# vgchange -a n dt
0 logical volume(s) in volume group "dt" now active

At this point you should be able to do the following.

# cryptsetup luksClose olddrive

… however I seem to have run into a bug that reports the device is busy.