May 14, 2013

Grow LUKS encrypted LVM /home partition

 

I run Fedora in VMware Fusion and needed more space in /home than I had initially anticipated. Luckily I had some space left on my Mac and shut shutdown the VM, went into the Fusion settings then increased the VMs disk size by 10GB after that I needed to apply the space to my /home patition which was an encrypted LV.

First step was to reboot into Single User Mode, from there I created a new ext2 partition (doesn’t really matter that it’s ext2, we’ll deal with that) with parted using the new free space this was /dev/sda3 You could also just extend the existing physical partition, but I felt safer doing it like this, and hey, that’s what LVM is for.

Take a look at your /etc/fstab and you’ll see the /dev/mapper/luks-biglonguuid device that is your encrypted partition

# Unmount the partition in question
umount /home
# Check the FS on the fedora-named luks device
fsck.ext4 -C 0 -f /dev/mapper/luks-biglonguuid
# Close the luks device
cryptsetup luksClose luks-biglonguuid
# After growing my VMWare virtual disk, I created a new partition with parted (/dev/sda3)
# Make the new partition a PV, then extend your VG to the PV
pvcreate /dev/sda3
vgextend vg_jordanfedora /dev/sda3
# Extend the home LV to take the extra space you need
lvextend -L+10G /dev/vg_jordanfedora/lv_home
# Open the crypt mounted on a temp device, here called "mytempdevice"
cryptsetup luksOpen /dev/vg_jordanfedora/lv_home mytempdevice
# Resize the crypt temp device
cryptsetup --verbose resize mytempdevice
# Mount it and make sure your files are there
mount /dev/mapper/mytempdevice /home
# It worked! Unmount it
umount /home
# Another fsck
e2fsck -f /dev/mapper/mytempdevice
# Grow the FS to match the size of the device
resize2fs /dev/mapper/mytempdevice
# Reboot the machine so fedora can do it's luks-biglonguuid decryption on boot
reboot

And there you have it!

Originally learned this from here and expanded on the explanations a bit http://blog.gauner.org/blog/2010/01/23/resize-a-luks-partition-on-lvm/

Leave a Reply