I know I can create and use a loopback device like this:
# Create the file
truncate disk.img --size 2G
# Create a filesystem
mkfs.ext4 disk.img
# Mount to use
mount disk.img /mnt
# Clean up
umount /mnt
However in this case the disk image is fixed at 2GB. It's 2GB when it's empty, and it's 2GB when it's full. It will not grow.
Is there a kind of loopback device that can grow in size? Or, is there a kind of loopback device that only needs as much space that it stores?