Expanding encrypted LUKS partitions
It is very easy, but not very simple, because you need to make too many steps.
First of all, LUKS (Linux Unified Key Setup) is used to encrypt partitions.
A few words about how to create an encrypted partition
The process is very simple. You need a partition (we work on Debian, so from now on, everything is Linux), like /dev/sdb1.
First step is to prepare the partition to use with LUKS.
cryptsetup luksFormat /dev/sdb1
This will destroy all the data you have on this partition and it will also ask you to provide an encryption password (you can have more than one).
Then to use this partition, you need to open it:
cryptsetup luksOpen /dev/sdb1 cryptvolume
“cryptvolume” can be any name that will identify your partition. I usually use something like crypt_sdb1, so in my case
cryptsetup luksOpen /dev/sdb1 crypt_sdb1
If this is the first time, then you need to format the partition before you can attach it.
mkfs.ext4 /dev/mapper/crypt_sdb1
mount /dev/mapper/crypt_sdb1 /mnt
What if the partition is smaller than you need? You have to make it bigger, of course :). Condition is that you need to have space on your hard drive to do so.
First, detach and close the encrypted volume if necessary:
cryptsetup luksClose /dev/mapper/crypt_sdb1
Use parted to resize the partition.
resizepart <partition number> <end>
Open the partition again:
cryptsetup luksOpen /dev/sdb1 cryptvolume
Run e2fsck to check the filesystem:
e2fsck -f /dev/mapper/cryptvolume
Run resize2fs to resize it:
resize2fs /dev/mapper/cryptvolume
mount /dev/mapper/cryptvolume /mnt