Resize Luks on LVM

Resize Luks on LVM

As usual make sure you backup your disk.

I recommend a full dd backup/clone https://wiki.archlinux.org/index.php/Dd#Disk_cloning_and_restore

This guide is for increasing the space on your LUKS encrypted partition that sits in a LVM partition. In order to decrease the same should (untested) work but you have to change the order in which you do things.

This is quite simple. Let’s run lvscan to find out the name of our luks partition.

sudo lvscan 
  ACTIVE            '/dev/UbuntuCrypt/root'

You should see something like the above, write down the name right after dev. In my case UbuntuCrypt.

Also take not of the partitions you have here. I only have one but if you have more than one then you need to pay attention and decide which one (ones) you want to increase.

From there let’s restart into a live usb. A Ubuntu/Lubuntu live usb should suffice.

Once booted into the live usb, let’s bring up gparted and resize the partition which contains our lvm, with luks in it. Just go ahead and resize it using gparted to take up as much space as much space as you want. This will increase your LVM partition.

In my case this was nvme0n1p3

Now we largely follow https://unix.stackexchange.com/questions/320957/extend-a-luks-encrypted-partition-to-fill-disk

cryptsetup luksOpen /dev/nvme0n1p3 UbuntuCrypt

Use the name we got with lvscan.

cryptsetup resize UbuntuCrypt
vgchange -a y UbuntuCrypt-root
pvresize /dev/mapper/UbuntuCrypt

Use the vgchange for all partitions that you need to change.
These are the partitions listed previously with lvscan instead of the / swap for a -.

UbuntuCrypt/root becomes UbuntuCrypt-root

Beaware this next step resize the partition inside the LUKS partition.
In my case I am telling it to take up all of the free space. If you have more than one you might want to split the space between them or something else.

lvresize -l+100%FREE /dev/UbuntuCrypt/root
e2fsck -f /dev/mapper/UbuntuCrypt-root
resize2fs /dev/mapper/UbuntuCrypt-root

Do the above for each of your partitions in the LUKS partition, and modify -l+100%FREE accordingly.

Once done reboot and you should be good to go.

Leave a Reply

Please Login to comment
  Subscribe  
Notify of