Goal: have an encrypted loop device containing a btrfs filesystem. Be able to extend this filesystem.
Create a file to be used as the encrypted container
dd if=/dev/zero of=/data/dsk1 bs=1M count=500
Assign a loop device
losetup /dev/loop1 /data/dsk1
Crypt the device :
cryptsetup -c aes --verify-passphrase create dsk1 /dev/loop1
Format filesystem encrypted in the loop device
mkfs.btrfs /dev/mapper/dsk1
Now we can mount it
mount -t btrfs /dev/mapper/dsk1 /mnt/tmp
umount /mnt/tmp cryptsetup remove dsk1 losetup -d /dev/loop1
losetup /dev/loop1 /data/dsk1 cryptsetup create dsk1 /dev/loop1 mount /dev/mapper/dsk1 /mnt/tmp
Get size :
df -h|grep dsk1 /dev/mapper/dsk1 500M 56K 408M 1% /mnt/tmp
Make the file bigger
dd if=/dev/zero of=/data/dsk1 bs=1M count=300 conv=notrunc oflag=append
Resize the btrfs file system
btrfs filesystem resize max /mnt/tmp
Here we are :
df -h|grep dsk1 /dev/mapper/dsk1 800M 56K 708M 1% /mnt/tmp
Encrypted filesystem resized mounted.