Creating and mounting a loopback filesystem in Linux
To mount a file as an device you can follow the steps below. This can be used for CD ISO images.
First create an example filesystem in a file:
dd count=1024 if=/dev/zero of=/tmp/file1
Set "count" to the correct size of the filesystem you need. On my system "count=1024x2" gave me 1Mb
Then format the file:
mkfs -t ext2 /tmp/file1
mke2fs 1.37 (21-Mar-2005)
/tmp/file1 is not a block special device.
Proceed anyway? (y,n) y
Now mount the new filesystem:
mount -t ext2 -o loop /tmp/file1 /mnt/newfs
Finally to check:
df -h /mnt/newfs
Filesystem Size Used Avail Use% Mounted on
/tmp/file1 1003K 13K 939K 2% /mnt/newfs
Last updated: 04/01/2006