In
Unix-like
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
operating systems, a loop device, vnd (vnode disk), or lofi (loop file interface) is a
pseudo-device
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow a ...
that makes a
computer file
A computer file is a computer resource for recording data in a computer storage device, primarily identified by its file name. Just as words can be written to paper, so can data be written to a computer file. Files can be shared with and transfe ...
accessible as a
block device
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow an ...
.
Before use, a loop device must be connected to an extant file in the
file system
In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
. The association provides the user with an application programming interface (
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standa ...
) that allows the file to be used in place of a block special file (cf.
device file system
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow ...
). Thus, if the file contains an entire file system, the file may then be
mounted
Mount is often used as part of the name of specific mountains, e.g. Mount Everest.
Mount or Mounts may also refer to:
Places
* Mount, Cornwall, a village in Warleggan parish, England
* Mount, Perranzabuloe, a hamlet in Perranzabuloe parish, C ...
as if it were a disk device.
Files of this kind are often used for CD
ISO image
An optical disc image (or ISO image, from the ISO 9660 file system used with CD-ROM media) is a disk image that contains everything that would be written to an optical disc, disk sector by disc sector, including the optical disc file system. IS ...
s and
floppy disk
A floppy disk or floppy diskette (casually referred to as a floppy, or a diskette) is an obsolescent type of disk storage composed of a thin and flexible disk of a magnetic storage medium in a square or nearly square plastic enclosure lined w ...
images. Mounting a file containing a file system via such a loop mount makes the files within that file system accessible. They appear in the
mount point
Mounting is a process by which a computer's operating system makes files and directories on a storage device (such as hard drive, CD-ROM, or network share) available for users to access via the computer's file system.
In general, the process o ...
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 file system.
Uses of loop mounting
After mounting a file that holds a file system, the files in that system can be accessed through the usual file system interface of the operating system, without any need for special functionality, such as reading and writing to ISO images, in applications.
Loop mounting has several uses. It is a convenient method for managing and editing file system images offline, that are later used for normal system operation. This includes CD or DVD images or installation systems. It may be used to install an operating system onto a file system without repartitioning a disk. It also provides a permanent segregation of data, for example, when simulating removable media on a faster and more convenient hard disk or encapsulating encrypted file system.
Availability
Various Unix-like operating systems provide the loop device functionality using different names.
In Linux, device names are encoded in the symbol table entries of their corresponding device drivers. The device is called a "loop" device and device nodes are usually named ''/dev/loop0'', ''/dev/loop1'', etc. They can be created with
makedev
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow a ...
for the static device directory, dynamically by the facilities of the device file system (
udev
udev (userspace ) is a device manager for the Linux kernel. As the successor of devfsd and hotplug, udev primarily manages device nodes in the directory. At the same time, udev also handles all user space events raised when hardware devices ar ...
), or directly with
mknod
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow an ...
. The management user interface for the loop device is ''losetup'', which is part of the package
util-linux
is a standard package distributed by the Linux Kernel Organization for use as part of the Linux operating system. A fork, (with meaning "next generation"), was created when development stalled, but has been renamed back to , and is the offic ...
.
Sometimes, the loop device is erroneously referred to as
loopback
Loopback (also written loop-back) is the routing of electronic signals or digital data streams back to their source without intentional processing or modification. It is primarily a means of testing the communications infrastructure.
There are m ...
device, but this term is reserved for a networking device in operating systems. The concept of the ''loop'' device is distinct.
In BSD-derived systems, such as
NetBSD
NetBSD is a free and open-source Unix operating system based on the Berkeley Software Distribution (BSD). It was the first open-source BSD descendant officially released after 386BSD was forked. It continues to be actively developed and is a ...
and
OpenBSD
OpenBSD is a security-focused, free and open-source, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by forking NetBSD 1.0. According to the website, the OpenBSD project em ...
, 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 program ''vnconfig'' is used for configuration.
FreeBSD
FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
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 utility ''mdconfig''.
In
Solaris
Solaris may refer to:
Arts and entertainment Literature, television and film
* ''Solaris'' (novel), a 1961 science fiction novel by Stanisław Lem
** ''Solaris'' (1968 film), directed by Boris Nirenburg
** ''Solaris'' (1972 film), directed by ...
/
OpenSolaris
OpenSolaris () is a discontinued open-source computer operating system based on Solaris and created by Sun Microsystems. It was also, perhaps confusingly, the name of a project initiated by Sun to build a developer and user community around th ...
, the loop device is called "loopback file interface" or lofi, and located at ''/dev/lofi/1'', etc. SunOS has the configuration program ''lofiadm''. "lofi'' supports read-only compression and read-write encryption. Available is also a 3rd-party driver ''fbk'' (''File emulates Blockdevice''), for SunOS/Solaris since summer 1988.
UnixWare includes a dynamically loadable device driver ''marry''(7) and the utility ''marry''(1M). The marry driver allows a regular file to be treated as a device. The regular file can be accessed through either a block device, ''/dev/marry/regfile'', or as a character device, ''/dev/marry/rregfile''. The command ''marry'' also supports encrypting and decrypting of the regular file.
MacOS
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
implements a native image mounting mechanism as part of its random access disk device abstraction. The command ''hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount
'' causes a block device to appear in ''/dev'' as a regular disk device and subdevices for recognized partitions. 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. MacOS can handle disk (.dmg or .iso), CD-ROM or DVD images in various formats.
Loop mounting was not available on Microsoft Windows
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
operating systems until , where this functionality is natively implemented, and available through the diskpart
In computing, diskpart is a command-line disk partitioning utility included in Windows 2000 and later Microsoft operating systems, replacing its predecessor, fdisk. The command is also available in ReactOS.
Overview
The diskpart is a utility ...
utility. However, the facility is often added using third-party applications such as ''Daemon Tools
DAEMON Tools is a virtual drive and optical disc authoring program for Microsoft Windows and Mac OS.
Overview
DAEMON tools was originally a successor of ''Generic SafeDisc emulator'' and incorporated all of its features. The program claims t ...
'' and ''Alcohol 120%
Alcohol 120% is a disk image emulator created by Alcohol Soft. It can create and mount disc images in the proprietary Media Descriptor File format. Images in this format consist of a pair of .mds and .mdf files. Alcohol 120% can also convert imag ...
''. Freely-available tools fro
VMware (Disk Mount Utility)
an
can also be used to achieve similar functionality. Under Windows XP and Vista it is also possible to use the virtual hard disk feature by adding some component from Microsoft Virtual Server 2005 R2.
In A2, formerly AOS then Bluebottle, a file-based virtual disk is created with ''VirtualDisks.Create''. A file system can be installed in such a "disk" with ''VirtualDisks.Install''.
Example
Mounting a file containing a disk image on a directory requires two steps:
# association of the file with a loop device node
A device is usually a constructed tool. Device may also refer to:
Technology Computing
* Device, a colloquial term encompassing desktops, laptops, tablets, smartphones, etc.
* Device file, an interface of a device driver
* Peripheral, any devic ...
,
# 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 ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
, or ''lofiadm''lofiadm, Sun System Administration Command manual
in SunOS. As an example, if example.img
is a regular file containing a file system and /home/you/dir
is a Linux user's directory, the superuser
In computing, the superuser is a special user account used for system administration. Depending on the operating system (OS), the actual name of this account might be root, administrator, admin or supervisor. In some cases, the actual name of t ...
(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.
To identify an available loop device for use in the above commands, the superuser (root) can use:
losetup -f
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
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standa ...
), the association and disassociation of a file with a loop device is performed with the ioctl
In computing, ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; th ...
system call
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
on a loop device.
See also
* Device file system
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow ...
* Network block device
On Linux, network block device (NBD) is a network protocol that can be used to forward a block device (typically a hard disk or partition) from one machine to a second machine. As an example, a local machine can access a hard disk drive that is a ...
* cloop
* Disk image
A disk image, in computing, is a computer file containing the contents and structure of a disk volume or of an entire data storage device, such as a hard disk drive, tape drive, floppy disk, optical disc, or USB flash drive. A disk image is us ...
References
External links
Mounting a disk image using the loop device
from the ''Bochs
Bochs (pronounced "box") is a portable IA-32 and x86-64 IBM PC compatible emulator and debugger mostly written in C++ and distributed as free software under the GNU Lesser General Public License. It supports emulation of the processor(s) (includin ...
User Manual''
* {{man, 8, losetup, die.net
Unix file system technology
Linux kernel features