Add disks to a setup with a LUKS container on a LVM volume without losing data
Need to expand disk space on a system using LUKS encryption over LVM? Here’s how to do it without losing any data.
Prerequisites: Make sure you have backups before proceeding.
Setup:
- Physical disks:
sde,sdf(new disks to add) - Volume group:
vg-01 - Logical volume:
lvdata - LUKS container:
luksdata
Steps
First, create physical volumes on the new disks and extend the volume group:
pvcreate /dev/sde /dev/sdf
vgextend vg-01 /dev/sde /dev/sdf
Resize the logical volume to use all available free space:
lvresize -l +100%FREE /dev/vg-01/lvdata
Open the LUKS container and resize it:
cryptsetup luksOpen /dev/vg-01/lvdata luksdata
cryptsetup resize luksdata
Mount and grow the filesystem:
mount -t xfs /dev/mapper/luksdata /mnt/data
xfs_growfs /dev/mapper/luksdata
Note: I’m using XFS in this example. If you’re using an ext-based filesystem, you would use resize2fs instead of xfs_growfs.
That’s it! The commands above successfully expanded my storage without any data loss.