Install ext2fs libarary (includes from linux)
sudo apt-get install e2fslibs-dev
Working with filesystem
# create file
mkfs.ext2 file 1000
# mount it
sudo mkdir /mnt/file
sudo mount -t ext2 -o loop file /mnt/file
# check if mounted
mount -t ext2
# unmount
# save the filesystem to file
sudo umount /mnt/file