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 pseudo-device that is able to redirect and transforms data that goes through its "loop". It is mostly used for encryption of a file system, but since any regular file can be associated with a loop device, it makes it possible to turn any file into a pseudo-device.
Since loop devices allow seeing a regular file as a device, they allow for mounting those regular files that contain an entire filesystem. Files of this kind that are often used are CD ISO images and floppy disc images. Mounting a file containing a filesystem via such a loop mount makes the files within that filesystem accessible as regular files, located on the mount point directory.
Contents |
[edit] Examples
Mounting a file on a directory requires two steps:
- the file is associated with a loop device node, which is a special file
- the loop device is mounted on the directory
These two operations can be performed either using two separate commands, or by letting the mount command perform the first step before actually doing the mount. The first operation can be executed by a specific command such as losetup in Linux. As an example, if example.img
is a regular file containing a filesystem 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 as the whole mounted directory.
An alternative way of doing the same is to let mount handle the setting up of the loop device:
mount -o loop example.img /home/you/dir
In this case, the mount command performs both the association of the file with the loop device and the mount itself.
[edit] Uses of loop mounting
After mounting a file containing a filesystem, the files within the filesystem can be accessed with normal tools, so that one can copy file from and to using cp, edit them using vi or GIMP, etc. All these tools work without the ability of reading and writing to ISO images and such. One can also run mkfs commands to create an image file without needing the media the image will eventually be written to.
Loop devices might be capable of encryption.
[edit] Availability
Various Unix-like operating system provide the loop device functionality under different names. In Linux, the device is called loop device and generally named /dev/loop0, /dev/loop1, etc. In BSD, is called virtual node device or vnd, and generally located at /dev/vnd0, /dev/rvnd0 or /dev/svnd0, etc. In SunOS, is called loopback file interface or lofi, and located at /dev/lofi/1, etc.
In Linux, the losetup described above is part of the util-linux package, which can be found here or here, or with the package manager of your Linux distribution. The latest version is 2.13-pre7 from 5th March 2006. In BSD, configuration is done by the vnconfig program. SunOS has the lofiadm program for configuration.
Loop mounting is not natively available on Microsoft Windows, though it is often added using third-party applications such as DAEMON Tools and Alcohol 120%.
A freely-available [1] tool from VMware can also be used to achieve similar functionality.
[edit] See also
- Loopback interface, a different concept with a similar name
- Disk image emulator
[edit] References
- losetup manual page
- Using a loop device from the Dwarf's Guide to Debian GNU/Linux
- Mounting a disk image using the loop device from the Bochs User Manual
[edit] External links
Categories: Unix stubs | Unix | Linux