Wednesday, April 22, 2015

Grow encrypted LVM

Build/format/mount encrypted LVM volume

cryptsetup -y -v luksFormat /dev/sdc1
cryptsetup luksOpen /dev/sdc1 encrypted-sdc1
pvcreate /dev/mapper/encrypted-sdc1
vgcreate MAIN /dev/mapper/encrypted-sdc1
lvcreate -n LVMAIN -l 100%FREE MAIN
mkfs.ext4 /dev/MAIN/LVMAIN
mount /dev/MAIN/LVMAIN /mnt/lvmtest

Build expansion volume

cryptsetup -y -v luksFormat /dev/sdc2
cryptsetup luksOpen /dev/sdc2 encrypted-sdc2
pvcreate /dev/mapper/encrypted-sdc2

Extend the volumegroup and Logical Volume

vgextend MAIN /dev/mapper/encrypted-sdc2
vgdisplay (and look for the free PE's)
lvextend -l +1830 /dev/MAIN/LVMAIN

(Online) grow the filesystem

resize2fs /dev/MAIN/LVMAIN

Shutdown procedure

umount /mnt/lvmtest
vgchange -an MAIN
cryptsetup luksClose /dev/mapper/encrypted-sdc2
cryptsetup luksClose /dev/mapper/encrypted-sdc1

Start again

cryptsetup luksOpen /dev/sdc1 encrypted-sdc1
cryptsetup luksOpen /dev/sdc2 encrypted-sdc2
vgscan --mknodes
vgchange -ay
mount /dev/MAIN/LVMAIN /mnt/lvmtest