Add disks to a setup with a LUKS container on a LVM volume without losing data
If neither LUKS nor LVM says anything to you, I have no idea what you are reading this for. If they do, here is my very short way to make use of extra disk space.
Doing 4K video is space hungry. Thanks to a recent sale, I got some pretty good disks. So just adding them to the existing ones sounded like the way to go, but it took a bit trial and error to get there. I didn’t want more partitions, but extend my big data partition instead.
Always backup your data first! Don’t come crying to me if you didn’t!
Now for me, this worked like a charm and I didn’t loose any data, so it should work without data loss. But again, don’t just walk blind into this, make backups first.
To keep things straight, sde and sdf are the new physical disks, vg-01 is the volume group, lvdata is the logical volume inside vg-01 and luksdata is the name under which I’m mounting the luks container.
# Create physical volumes
pvcreate /dev/sde /dev/sdf
# Extend volume group to include new disks
vgextend vg-01 /dev/sde /dev/sdf
# Extend logical volume to get all the space
lvresize -l +100%FREE /dev/vg-01/lvdata
# Open luks container
cryptsetup luksOpen /dev/vg-01/lvdata luksdata
# Extend the luks container to use all the space available
cryptsetup resize luksdata
# Remount folder (so the system knows what file system this actually is)
mount -t xfs /dev/mapper/luksdata /mnt/data
# Grow filesystem
xfs_growfs /dev/mapper/luksdata
I’m using XFS here, but you could use other file systems. The mount command will be different of course as will the grow command. For ext based systems it’s resize2fs for example.
Now hopefully I don’t have to search all over the place again to find this in the future when I will add more space to my server.