You can just set a new file size with truncate
, then cryptsetup resize
and resize2fs
.
For example, setting it to 200M:
truncate -s 200M cryptfile.img
Alternatively, if you prefer dd or other tools, you can just append another 100M of random data:
head -c 100M /dev/urandom >> cryptfile.img
Warning: if you truncate to a too small size, or if you typo and use >
instead of >>
, your data would be lost. dd
in particular likes to truncate files to 0 bytes by default, and it's easy to make mistakes, so I don't really recommend using it here.
The difference between truncate and appending random data is that truncate makes sparse files (zero, unallocated) while appending properly allocates space and initializes it with random data.
Then you can online resize the mapping (this might ask for your passphrase again):
cryptsetup resize cryptname
This would also happen automatically next time you cryptsetup open
the container normally.
At this point the encrypted block device (loop device, image file) should be properly resized to 200M (minus 16M or whatever is the size of your LUKS header).
That leaves the filesystem:
resize2fs /dev/mapper/cryptname