dyne/Tomb — Issue #57: Tomb resize
Author: jaromil
Created: 2011-10-27 17:15:34+00:00
State: open

Example here:
https://wiki.archlinux.org/index.php/System_Encryption_with_LUKS#Resizing_the_loopback_filesystem

yet this works only for ext2/3/4 and things get complicated as we start allowing more filesystem typess... however:

Resizing the loopback filesystem

First we should unmount the encrypted container:

umount /mnt/secret

cryptsetup luksClose secret

losetup -d /dev/loop0 # free the loopdevice.

After this we need to create a second file with the size of the data we want to add:

dd if=/dev/zero of=zeros bs=1M count=1024

You could use /dev/urandom instead of /dev/zero if you're paranoid, but /dev/zero should be faster on older computers. Next we need to add the created file to our container. Be careful to really use TWO ">", or you will override your current container!

cat zeros >> /bigsecret

Now we have to map the container to the loopdevice:

losetup /dev/loop0 /bigsecret

cryptsetup luksOpen /dev/loop0 secret

After this we will resize the encrypted part of the container to the maximum size of the container file:

cryptsetup resize secret

Finally we can resize the filesystem. Here is an example for ext2/3/4:

e2fsck -f /dev/mapper/secret # Just doing a filesystem check, because it's a bad idea to resize a broken fs

resize2fs /dev/mapper/secret

You can now mount your container again:

mount /dev/mapper/secret /mnt/secret