Loop device
Encyclopedia
In Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 operating systems, a loop device, vnd (vnode disk), or lofi (loopback file interface) is a pseudo-device that makes a file
Computer file
A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage. A file is durable in the sense that it remains available for programs to use after the current program has finished...

 accessible as a block device
Device file system
In Unix-like operating systems, a device file or special file is an interface for a device driver that appears in a file system as if it were an ordinary file. There are also special device files in MS-DOS and Microsoft Windows...

.

Before use, a loop device must be connected to an existing file in the filesystem. The association provides the user with an API that allows the file to be used in place of a block special file (cf. device file system
Device file system
In Unix-like operating systems, a device file or special file is an interface for a device driver that appears in a file system as if it were an ordinary file. There are also special device files in MS-DOS and Microsoft Windows...

). Thus, if the file contains an entire file system
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

, the file may then be mounted
Mount (computing)
Mounting takes place before a computer can use any kind of storage device . The user or their operating system must make it accessible through the computer's file system. A user can access only files on mounted media.- Mount point :A mount point is a physical location in the partition used as a...

 as if it were a disk device.

Files of this kind are often used for CD ISO image
ISO image
An ISO image is an archive file of an optical disc, composed of the data contents of every written sector of an optical disc, including the optical disc file system...

s and floppy disc images. Mounting a file containing a filesystem via such a loop mount makes the files within that filesystem accessible. They appear in the mount point directory.

A loop device may allow some kind of data elaboration during this redirection. For example, the device may be the unencrypted version of an encrypted file. In such a case, the file associated with a loop device may be another pseudo-device. This is mostly useful when this device contains an encrypted file system. If supported, the loop device is in this case the decrypted version of the original encrypted file and can therefore be mounted as if it were a normal filesystem.

Uses of loop mounting

After mounting a file that holds a filesystem, the files within the filesystem can be accessed through the usual filesystem interface of the operating system, without any need for special functionality, such as reading and writing to ISO images, in applications.

Uses include managing and editing filesystem images meant for later normal use (especially CD or DVD images or installation systems), installing an operating system without repartitioning a drive, and permanent segregation of data (for example, simulating removable media on a faster and more convenient hard disk or encapsulating encrypted filesystems).

Availability

Some confusion exists about the naming of the loop device under various operating systems.
Various Unix-like operating systems provide the loop device functionality under different names.

In Linux, device names are encoded in the symbol table entries of their corresponding device drivers. The device is called "loop" device and device nodes are usually named /dev/loop0, /dev/loop1, etc. They can be created by the makedev script for the static device directory, dynamically by the facilities of the device filesystem (udev
Udev
udev is the device manager for the Linux kernel. Primarily, it manages device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.-History:udev was new in Linux...

), or directly by the mknod command. The management user interface for the loop device is losetup and is part of the util-linux
Util-linux
util-linux is a standard package of the Linux operating system. A fork, util-linux-ng—with ng meaning "next generation"—was created when development stalled, but as of January 2011 has been renamed back to util-linux, and is the official version of the package.It includes the following...

 package.

Sometimes, the loop device is erroneously referred to as 'loopback' device, but this term is reserved for a networking device in the Linux kernel (cf. loopback
Loopback
Loopback describes ways of routing electronic signals, digital data streams, or flows of items from their originating facility back to the source without intentional processing or modification...

). The concept of the 'loop' device is distinct from that of 'loopback', although similar in name.

In BSD-derived systems, such as NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...

 and OpenBSD
OpenBSD
OpenBSD is a Unix-like computer operating system descended from Berkeley Software Distribution , a Unix derivative developed at the University of California, Berkeley. It was forked from NetBSD by project leader Theo de Raadt in late 1995...

, the loop device is called "virtual node device" or "vnd", and generally located at /dev/vnd0, /dev/rvnd0 or /dev/svnd0, etc., in the file system. The vnconfig program is used for configuration.

FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 followed the same conventions as other BSD systems until release version 5, in which the loop device was incorporated into the memory disk driver ("md"). Configuration is now performed using the mdconfig program.

In Solaris/OpenSolaris
OpenSolaris
OpenSolaris was an open source computer operating system based on Solaris created by Sun Microsystems. It was also the name of the project initiated by Sun to build a developer and user community around the software...

, the loop device is called "loopback file interface" or lofi, and located at /dev/lofi/1, etc. SunOS has the lofiadm configuration program. The "lofi" driver supports read-only compression and read-write encryption. There is also a 3rd party "fbk" (File emulates Blockdevice) driver available for SunOS/Solaris since summer 1988.

Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 implements a native image mounting mechanism as part of its random access disk device abstraction. The devices appear in /dev as regular disk devices; reads from and writes to those devices are sent to a user-mode helper process, which reads the data from the file or writes it to the file. In the user interface it is automatically activated by opening the disk image. OS X can handle disk (.dmg or .iso), CD-ROM or DVD images in various formats.

Loop mounting is not natively available on Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 operating systems (until version Windows 7, where this functionality is natively implemented, and available through the diskpart
Diskpart
In computing, diskpart is a command-line hard disk partitioning utility included in versions of the Windows NT operating system line from Windows 2000 onwards, replacing fdisk which was used in MS-DOS based operating systems....

 utility). However, the facility is often added using third-party applications such as Daemon Tools
Daemon Tools
Daemon Tools is a disk image emulator and optical disc authoring program for Microsoft Windows. Daemon Tools was originally a furtherance in the development of another program, Generic SafeDisc emulator, and incorporated all of its features. The program claims to be able to defeat most copy...

and Alcohol 120%. Freely-available tools from VMware and LTR Data (ImDisk) can also be used to achieve similar functionality.

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
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

, 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
Superuser
On many computer operating systems, the superuser is a special user account used for system administration. Depending on the operating system, the actual name of this account might be: root, administrator or supervisor....

 (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
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 (API), the association and disassociation of a file with a loop device is performed with the ioctl
Ioctl
In computing, ioctl, short for input/output control, is a system call for device-specific operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; the effect of a call depends completely on the request code. Request codes are...

 system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

 on a loop device.

See also

  • Device file system
    Device file system
    In Unix-like operating systems, a device file or special file is an interface for a device driver that appears in a file system as if it were an ordinary file. There are also special device files in MS-DOS and Microsoft Windows...

  • Virtual drive
    Virtual drive
    A virtual drive in computing is a device that to the operating system appears to be an ordinary physical disk drive, with disc images substituted for disc reading hardware through the use of software called a disk emulator...

  • Network block device
    Network block device
    In Linux, a network block device is a device node whose content is provided by a remote machine. Typically, network block devices are used to access a storage device that does not physically reside in the local machine but on a remote one...

     used when the file to associate with the device is on a remote computer
  • cloop
    Cloop
    The compressed loopback device or cloop is a module for the Linux kernel. It adds support for transparently decompressed, read-only block devices. It is not a compressed file system in itself....

     - a special compressed version of a loop device i.e. for live CDs
  • With similar name, but different concept, a loopback interface, or loopback device is network facility in UNIX-like operating systems
  • Disk image
    Disk image
    A disk image is a single file or storage device containing the complete contents and structure representing a data storage medium or device, such as a hard drive, tape drive, floppy disk, CD/DVD/BD, or USB flash drive, although an image of an optical disc may be referred to as an optical disc image...


External links

  • Mounting a disk image using the loop device from the Bochs
    Bochs
    Bochs is a portable x86 and x86-64 IBM PC compatible emulator and debugger mostly written in C++ and distributed as free software under GNU Lesser General Public License...

    User Manual
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK