About loopback devices

You can think of a loopback device as a filesystem within a filesystem. It provides a convenient method for working with a filesystem destined for a small device like a floppy.

From the outside, the filesystem is contained within a single file (often gzipped to fit on a floppy). This is often called an image file since it contains a complete image of a filesystem. When mounted, you can access it like any other filesystem.

Prerequisites

The kernel requires loopback support. You can compile support directly into the kernel, or as a module.

You also need one or more loop devices. BasicLinux provides four: /dev/loop0 through /dev/loop3.

Mounting a Loopback Device

Mounting a loopback device is simple:

  1. If loopback support is a separate module on your system, load it (using insmod loop).
  2. If the loopback filesystem is gzipped, unzip it.
  3. Mount the filesystem: mount -o loop filename /mnt

The filesystem looks exactly like a small disk partition, including having a fixed size. Treat it like any other filesystem. When you unmount it, the image file saves any changes you made to the filesystem.

Creating an Image File

Creating an image is fairly simple:

  1. Create the file itself: dd bs=1024 count=blocks if=/dev/zero of=filename
    Replace blocks with the desired size of the image (in kilobytes) and filename with the name of the image file.
  2. Make the file system: mke2fs filename
    mke2fs confirms that you want to make the filesystem on a non-block device before proceeding.
  3. Mount the image file as described above and proceed.