• How To: Extend a LUKS encrypted partition to fill disk

Some times it is necessary to expand an encrypted volume such as when you have exended the size of a virtual disk on a VM. Here are the steps to expand a LUKS encrypted volume...

First, take a look at the disk layout and partition sizes:

fdisk -l

lsblk

Perform a rescan of the physical disk to see the new space:

sudo apt-get install scsitools
sudo rescan-scsi-bus

or

echo 1 > /sys/class/block/sda/device/rescan

Check to see if the new space has been detected

fdisk -l

Open the encrypted volume:

cryptsetup luksOpen /dev/sda2 crypt-volume

Parted /dev/sda to extend the partition:

parted /dev/sda 
resizepart NUMBER END.

Stop using the VG:

vgchange -a n vg_backups

Close the encrypted volume:

cryptsetup luksClose crypt-volume

Open it again:

cryptsetup luksOpen /dev/sda2 crypt-volume

Automatically resize the LUKS volume to the available space.

cryptsetup resize crypt-volume

Activate the VG

vgchange -a y vg_backups

Resize the PV:

pvresize /dev/mapper/crypt-volume

Resize the LV for /home to 100% of the free space:

lvresize -l+100%FREE /dev/vg_backups/backups.

Resize the filesystem in /backups(automatically uses 100% free space)

e2fsck -f /dev/mapper/vg_backups
resize2fs /dev/mapper/vg_backups

This article was last modified: July 22, 2020, 3:12 p.m.

0 Comments

Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.

Share

Hacker News

Top