Virtual filesystem from a file

Alessandro Dotti Contra <alessandro@hyboria.org>
Revision: 1.3 (last updated: 20050928)



How to create a virtual filesystem from a regular file

Create the file

First of all, we need to create a suitable file to hold the filesystem. Let's suppose we want to create a 20 megabytes file:

  $ dd if=/dev/zero of=/home/adotti/temp/troiai/vffs count=20 bs=1M

We can use a different size specification as well; we just need to specify the correct values for block size (bs) and count options.

Create the filesystem

Now we can create the filesystem we want on our brand new file:

  $ /sbin/mkfs -t ext3 /home/adotti/temp/troiai/vffs

WARNING

mkfs will warn you that vffs is not a block device and asks if it has to proceed anyway. It is safe to answer yes.

Mount and use the filesystem

To use the new virtual filesystem first we need to create the mount point:

  $ mkdir /home/adotti/scratch

The filesystem will be mounted using the new directory as the mount point and a loop device. Super user's privileges are needed:

  # mount -o loop /home/adotti/temp/troiai/vffs /home/adotti/scratch