Loop device

From Wikipedia, the free encyclopedia

In Unix-like operating systems, a loop device, loopback device, vnd (vnode disk), or lofi (loopback file interface) is a device node that represents a regular file. The same names are also used for the device drivers that control the devices. Loop devices are mostly used for being mounted on a directory, which produces the same effect of mounting a disk whose image is identical to the file associated to the device on that directory.

Contents

[edit] Examples

Mounting a file on a directory can be done in one of two different ways. The first one involves two steps:

  1. The file is associated with a loop device node using a specific command (losetup in Linux, for example);
  2. Then, the device node is mounted on the directory as for any other block device. For example, if example.img is a regular file and /home/you/dir is a directory on a Linux box, the root user can mount the file on the directory by executing the following two commands:
losetup /dev/loop0 example.img
mount /dev/loop0 /home/you/dir

The first command associates the loop device node /dev/loop0 with the regular file example.img. This association can be later destroyed by executing losetup -d /dev/loop0. The second command mounts the device on the directory /home/you/dir.

The global effect of executing these two commands is that the content of the file is used for storing the whole mounted directory.

The second way lets mount handle the setting up of the loop device:

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

The loop device is capable of encryption, the type and strength depend on version of kernel and of util-linux.

losetup is part of the util-linux package, which can be found here or here, or with the package manager of your distro. The latest version is 2.13-pre7 from 5th March 2006.

[edit] See also

[edit] References

[edit] External links

In other languages