Loop device

Last updated

In Unix-like operating systems, a loop device, vnd (vnode disk), or lofi (loop file interface) is a pseudo-device that makes a computer file accessible as a block device.

Contents

Before use, a loop device must be connected to an extant file in the file system. The association provides the user with an application programming interface (API) that allows the file to be used in place of a block special file (cf. device file system). Thus, if the file contains an entire file system, the file may then be mounted as if it were a disk device.

Files of this kind are often used for CD ISO images and floppy disk 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 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.

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 for the static device directory, dynamically by the facilities of the device file system (udev), or directly with mknod. The management user interface for the loop device is losetup, which is part of the package util-linux.

Sometimes, the loop device is erroneously referred to as loopback 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 and OpenBSD, 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 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. [1]

In Solaris/OpenSolaris, the loop device is called "loopback file interface" or lofi, [2] 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. [3]

UnixWare includes a dynamically loadable device driver marry(7) and the utility marry(1M). [4] 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 implements a native image mounting mechanism as part of its random access disk device abstraction. The command hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount <filename> 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 operating systems until Windows 7 , where this functionality is natively implemented, and available through the diskpart utility. [5] [6] However, the facility is often added using third-party applications such as Daemon Tools and Alcohol 120% . Freely-available tools from VMware (Disk Mount Utility) and LTR Data (ImDisk) 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. [7]

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:

  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 [8] in Linux, or lofiadm [9] 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 (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<N>

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.

See also

Related Research Articles

<span class="mw-page-title-main">Operating system</span> Software that manages computer hardware resources

An operating system (OS) is system software that manages computer hardware and software resources, and provides common services for computer programs.

<span class="mw-page-title-main">Disk partitioning</span> Creation of separate accessible storage areas on a secondary computer storage device

Disk partitioning or disk slicing is the creation of one or more regions on secondary storage, so that each region can be managed separately. These regions are called partitions. It is typically the first step of preparing a newly installed disk, before any file system is created. The disk stores the information about the partitions' locations and sizes in an area known as the partition table that the operating system reads before any other part of the disk. Each partition then appears to the operating system as a distinct "logical" disk that uses part of the actual disk. System administrators use a program called a partition editor to create, resize, delete, and manipulate the partitions. Partitioning allows the use of different filesystems to be installed for different kinds of files. Separating user data from system data can prevent the system partition from becoming full and rendering the system unusable. Partitioning can also make backing up easier. A disadvantage is that it can be difficult to properly size partitions, resulting in having one partition with too much free space and another nearly totally allocated.

fsck System tool for checking the consistency of a file system

The system utility fsck is a tool for checking the consistency of a file system in Unix and Unix-like operating systems, such as Linux, macOS, and FreeBSD. The equivalent programs on MS-DOS and Microsoft Windows are CHKDSK, SFC, and SCANDISK.

rsync File synchronization protocol and software

rsync is a utility for efficiently transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files. It is commonly found on Unix-like operating systems and is under the GPL-3.0-or-later license.

A home directory is a file system directory on a multi-user operating system containing files for a given user of the system. The specifics of the home directory are defined by the operating system involved; for example, Linux / BSD (FHS) systems use /home/⟨username⟩ or /usr/home/⟨username⟩ and Windows systems between 2000 and Server 2003 keep home directories in a folder named Documents and Settings.

<span class="mw-page-title-main">Virtual file system</span> Abstract layer on top of a more concrete file system

A virtual file system (VFS) or virtual filesystem switch is an abstract layer on top of a more concrete file system. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way. A VFS can, for example, be used to access local and network storage devices transparently without the client application noticing the difference. It can be used to bridge the differences in Windows, classic Mac OS/macOS and Unix filesystems, so that applications can access files on local file systems of those types without having to know what type of file system they are accessing.

dd is a command-line utility for Unix, Plan 9, Inferno, and Unix-like operating systems and beyond, the primary purpose of which is to convert and copy files. On Unix, device drivers for hardware and special device files appear in the file system just like normal files; dd can also read and/or write from/to these files, provided that function is implemented in their respective driver. As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining a fixed amount of random data. The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.

chroot is an operation on Unix and Unix-like operating systems that changes the apparent root directory for the current running process and its children. A program that is run in such a modified environment cannot name files outside the designated directory tree. The term "chroot" may refer to the chroot(2) system call or the chroot(8) wrapper program. The modified environment is called a chroot jail.

<span class="mw-page-title-main">Pseudoterminal</span>

In some operating systems, including Unix and Linux, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish asynchronous, bidirectional communication (IPC) channel between two or more processes. The master provides means by which a terminal emulator process controls the slave. The slave emulates a hardware text terminal device. PTY are similar to bidirectional pipes.

pax is an archiving utility available for various operating systems and defined since 1995. Rather than sort out the incompatible options that have crept up between tar and cpio, along with their implementations across various versions of Unix, the IEEE designed new archive utility pax that could support various archive formats with useful options from both archivers. The pax command is available on Unix and Unix-like operating systems and on IBM i, and Microsoft Windows NT until Windows 2000.

fstab is a system file commonly found in the directory /etc on Unix and Unix-like computer systems. In Linux, it is part of the util-linux package. The fstab file typically lists all available disk partitions and other types of file systems and data sources that may not necessarily be disk-based, and indicates how they are to be initialized or otherwise integrated into the larger file system structure.

CrossCrypt is an open-source on-the-fly encryption program for the Microsoft Windows XP/2000 operating systems. CrossCrypt allows a user to make virtual drives which encrypt any files stored on them, making the encryption process seamless to the user.

<span class="mw-page-title-main">File system</span> Format or program for storing files and directories

In computing, a file system or filesystem 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 large body of data with no way to tell where one piece of data stopped and the next began, or where any piece of data was located when it was time to retrieve it. By separating the data into pieces and giving each piece a name, the data are easily isolated and identified. Taking its name from the way a paper-based data management system is named, each group of data is called a "file". The structure and logic rules used to manage the groups of data and their names is called a "file system."

Filesystem in Userspace (FUSE) is a software interface for Unix and Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a bridge to the actual kernel interfaces.

rm (Unix) Unix command utility

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory. Typically, it is mapped to a mount point named /proc at boot time. The proc file system acts as an interface to internal data structures about running processes in the kernel. In Linux, it can also be used to obtain information about the kernel and to change certain kernel parameters at runtime (sysctl).

mount (Unix) Unix command to mount a filesystem

In computing, mount is a command in various operating systems. Before a user can access a file on a Unix-like machine, the file system on the device which contains the file needs to be mounted with the mount command. Frequently mount is used for SD card, USB storage, DVD and other removable storage devices. The command is also available in the EFI shell.

GVfs is GNOME's userspace virtual filesystem designed to work with the I/O abstraction of GIO, a library available in GLib since version 2.15.1. It installs several modules that are automatically used by applications using the APIs of libgio. There is also FUSE support that allows applications not using GIO to access the GVfs filesystems.

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 application program to interact with a device by using its device driver via standard input/output system calls. Using standard system calls simplifies many programming tasks, and leads to consistent user-space I/O mechanisms regardless of device features and functions.

Toybox is a free and open-source software implementation of over 200 Unix command line utilities such as ls, cp, and mv. The Toybox project was started in 2006, and became a 0BSD licensed BusyBox alternative. Toybox is used for most of Android's command-line tools in all currently supported Android versions, and is also used to build Android on Linux and macOS. All of the tools are tested on Linux, and many of them also work on BSD and macOS.

References

  1. "mdconfig". freebsd.org.
  2. "Man pages section 7: Device and Network Interfaces - Sun Microsystems". Archived from the original on 2010-12-30. Retrieved 2009-09-28.
  3. "Schily Tools - Browse /kernel/fbk at SourceForge.net". sourceforge.net.
  4. "Using marry to create filesystem images on files". uw714doc.sco.com.
  5. "GES on Windows 7". docs.microsoft.com.
  6. "Virtual Hard Drive VHD File - Create and Start with at Boot - Windows 7 Help Forums". sevenforums.com.
  7. "Windows XP/Vista: How to Attach a VHD File". Tech-Recipes: A Cookbook Full of Tech Tutorials. November 12, 2008.
  8. "UNIX Manual Page: man 8 losetup". man7.org.
  9. lofiadm, Sun System Administration Command manual Archived 2009-05-02 at the Wayback Machine

6363kk9k9k9