Penguin
Note: You are viewing an old revision of this page. View the current version.

Under some OperatingSystems (especially Unix-like ones), you can mount(8) a single file onto your VirtualFileSystem. There are several reasons why you might want to do this:

  • You have a cdrom ISO or other disk image, and want to access it
  • You want to have access to a particular filesystem type
  • You want to simulate a filesystem condition, such as low disk space, to test your software

Example under Linux

This is what I did to make sure to test that my software failed gracefully when disk space ran out.

1) Create a file containing a filesystem

  create a 2 MB file with an ext2 filesystem
  $ dd if=/dev/zero of=/tmp/loop.fs bs=1M count=2
  $ mke2fs -F /tmp/loop.fs

2) mount it as a loop back device (must be done as root)

  load the loop.ko kernel module if support is not compiled into the kernel
  # modprobe loop
  where I want it to be mounted
  # mount /tmp/loop.fs /mnt/directory -o loop

Now /mnt/directory will only allow around 2MB (minus filesystem overhead) of data to be written to it, and then the device will be out of space.