Loop Device - Example

Example

Mounting a file containing a disk image on a directory requires two steps:

  1. association of the file with a loop device node,
  2. mounting of the loop device at a mount point directory

These two operations can be performed either using two separate commands, or through special flags to the mount command. The first operation may be performed by programs such as losetup in Linux, or lofiadm in SunOS. As an example, if example.img is a regular file containing a filesystem and /home/you/dir is a Linux user's directory, the superuser (root) may mount the file on the directory by executing the following two commands:

losetup /dev/loop0 example.img mount /dev/loop0 /home/you/dir

The second command mounts the device on the directory /home/you/dir. The overall effect of executing these two commands is that the content of the file is used as a file system rooted at the mount point.

The mount utility is usually capable of handling the entire procedure:

mount -o loop example.img /home/you/dir

The device can then be unmounted with the following command:

umount /home/you/dir # or, after finding the associated loop number by e.g. mount | grep "/home/you/dir" # or losetup -a | grep example.img umount /dev/loop

At a lower level application programming interface (API), the association and disassociation of a file with a loop device is performed with the ioctl system call on a loop device.

Read more about this topic:  Loop Device

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)