Well that kind of depends on what kind of filesystem is used for the loopback file. But each filesystems should have tools to get that done. Anyways here is how I did it for an ext2 filesystem:
Code:
# cd /tmp
# mkdir mnt
# dd if=/dev/zero of=image bs=1k count=1024
1024+0 records in
1024+0 records out
# mke2fs -i 1024 -b 1024 -m 5 -F -v image
mke2fs 1.24a (02-Sep-2001)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
1024 inodes, 1024 blocks
51 blocks (4.98%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# mount image mnt -t ext2 -o loop
# dd if=/dev/zero of=image bs=1k count=1024 seek=1024
1024+0 records in
1024+0 records out
# e2fsck -f image
e2fsck 1.24a (02-Sep-2001)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
image: *** WARNING: Filesystem still has errors ***
image: 11/1024 files (0.0% non-contiguous), 135/1024 blocks
# resize2fs image 2048
resize2fs 1.24a (02-Sep-2001)
The filesystem on image is now 2048 blocks long.
# mount image mnt -t ext2 -o loop
# cd mnt
# df -k .
Filesystem 1k-blocks Used Available Use% Mounted on
/tmp/image 1915 2 1852 1% /tmp/mnt
# cd ..
# umount mnt
# rm -rf mnt image
#