The device mapper is a
framework
A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of.
Framework may refer to:
Computing
* Application framework, used to implement the structure of an application for an op ...
provided by the
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
for mapping physical
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 ...
s onto higher-level ''virtual block devices''. It forms the foundation of the
logical volume manager
In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes to store volumes. In particular, a volume manager can concatenate ...
(LVM), software
RAID
Raid, RAID or Raids may refer to:
Attack
* Raid (military), a sudden attack behind the enemy's lines without the intention of holding ground
* Corporate raid, a type of hostile takeover in business
* Panty raid, a prankish raid by male college ...
s and
dm-crypt
dm-crypt is a transparent block device encryption subsystem in Linux kernel versions 2.6 and later and in DragonFly BSD. It is part of the device mapper (dm) infrastructure, and uses cryptographic routines from the kernel's Crypto API. Unlike its ...
disk encryption, and offers additional features such as file system
snapshots
Snapshot, snapshots or snap shot may refer to:
* Snapshot (photography), a photograph taken without preparation
Computing
* Snapshot (computer storage), the state of a system at a particular point in time
* Snapshot (file format) or SNP, a file ...
.
Device mapper works by passing data from a virtual block device, which is provided by the device mapper itself, to another block device. Data can be also modified in transition, which is performed, for example, in the case of device mapper providing
disk encryption
Disk encryption is a technology which protects information by converting it into unreadable code that cannot be deciphered easily by unauthorized people. Disk encryption uses disk encryption software or hardware to encrypt every bit of data that g ...
or simulation of unreliable hardware behavior.
This article focuses on the device mapper implementation in the Linux kernel, but the device mapper functionality is also available in both
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
DragonFly BSD
DragonFly BSD is a free and open-source Unix-like operating system forked from FreeBSD 4.8. Matthew Dillon, an Amiga developer in the late 1980s and early 1990s and FreeBSD developer between 1994 and 2003, began working on DragonFly BSD in Ju ...
.
Usage
Applications (like
LVM2 and
Enterprise Volume Management System
Enterprise Volume Management System (EVMS) was a flexible, integrated volume management software used to manage storage systems under Linux.
Its features include:
* Handle EVMS, Linux LVM and LVM2 volumes
* Handle many kinds of disk partitionin ...
(EVMS)) that need to create new mapped devices talk to the device mapper via the
libdevmapper.so
shared library
In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and subr ...
, which in turn issues
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 ...
s to the
/dev/mapper/control
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 ...
. Configuration of the device mapper can be also examined and configured interactivelyor from
shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manip ...
sby using the utility.
Both of these two userspace components have their source code maintained alongside the LVM2 source.
Features
![The Linux Storage Stack Diagram](https://upload.wikimedia.org/wikipedia/commons/f/fb/The_Linux_Storage_Stack_Diagram.svg)
Functions provided by the device mapper include linear, striped and error ''mappings,'' as well as crypt and multipath ''targets.'' For example, two disks may be concatenated into one logical volume with a pair of ''linear'' mappings, one for each disk. As another example, ''crypt'' target encrypts the data passing through the specified device, by using the Linux kernel's
Crypto API.
, the following mapping targets are available:
* ''
cache
Cache, caching, or caché may refer to:
Places United States
* Cache, Idaho, an unincorporated community
* Cache, Illinois, an unincorporated community
* Cache, Oklahoma, a city in Comanche County
* Cache, Utah, Cache County, Utah
* Cache County ...
'' allows creation of
hybrid volume
In computing, a hybrid drive (solid state hybrid drive – SSHD) is a logical or physical storage device that combines a faster storage medium such as solid-state drive (SSD) with a higher-capacity hard disk drive (HDD). The intent is adding s ...
s, by using
solid-state drive
A solid-state drive (SSD) is a solid-state storage device that uses integrated circuit assemblies to store data persistently, typically using flash memory, and functioning as secondary storage in the hierarchy of computer storage. It is ...
s (SSDs) as caches for
hard disk drive
A hard disk drive (HDD), hard disk, hard drive, or fixed disk is an electro-mechanical data storage device that stores and retrieves digital data using magnetic storage with one or more rigid rapidly rotating platters coated with magnet ...
s (HDDs)
* ''clone'' will permit usage before a transfer is complete.
* ''
crypt
A crypt (from Latin ''crypta'' "vault") is a stone chamber beneath the floor of a church or other building. It typically contains coffins, sarcophagi, or religious relics.
Originally, crypts were typically found below the main apse of a chur ...
'' provides data encryption, by using the Linux kernel's
Crypto API
* ''delay'' delays reads and/or writes to different devices (used for testing)
* ''era'' behaves in a way similar to the linear target, while it keeps track of blocks that were written to within a user-defined period of time
* ''error'' simulates I/O errors for all mapped blocks (used for testing)
* ''flakey'' simulates periodic unreliable behaviour (used for testing)
* ''linear'' maps a continuous range of blocks onto another block device
* ''mirror'' maps a
mirrored
''Mirrored'' is the debut studio album by American experimental rock band Battles. It was released on May 14, 2007 in the United Kingdom, and on May 22, 2007 in the United States. ''Mirrored'' marked the first album in which the band incorporated ...
logical device, while providing data redundancy
* ''
multipath'' supports the mapping of
multipathed devices, through usage of their path groups
* ''raid'' offers an interface to the Linux kernel's
software RAID
Raid, RAID or Raids may refer to:
Attack
* Raid (military), a sudden attack behind the enemy's lines without the intention of holding ground
* Corporate raid, a type of hostile takeover in business
* Panty raid, a prankish raid by male college ...
driver (
md)
* ''snapshot'' and ''snapshot-origin'' used for creation of LVM snapshots, as part of the underlying copy-on-write scheme
* ''striped'' stripes the data across physical devices, with the number of stripes and the striping chunk size as parameters
* ''thin'' allows creation of devices larger than the underlying physical device, physical space is allocated only when written to
* ''zero'' an equivalent of
/dev/zero
, all reads return blocks of zeros, and writes are discarded
Applications
Linux kernel features and projects built on top of the device mapper include the following:
*
cryptsetup
dm-crypt is a transparent block device encryption subsystem in Linux kernel versions 2.6 and later and in DragonFly BSD. It is part of the device mapper (dm) infrastructure, and uses cryptographic routines from the kernel's Crypto API. Unlike it ...
utility used to conveniently setup disk encryption based on dm-crypt
*
dm-crypt
dm-crypt is a transparent block device encryption subsystem in Linux kernel versions 2.6 and later and in DragonFly BSD. It is part of the device mapper (dm) infrastructure, and uses cryptographic routines from the kernel's Crypto API. Unlike its ...
/
LUKS mapping target that provides volume encryption
*
dm-cache
dm-cache is a component (more specifically, a target) of the Linux kernel's device mapper, which is a framework for mapping block devices onto higher-level virtual block devices. It allows one or more fast storage devices, such as flash-base ...
mapping target that allows creation of
hybrid volumes
* dm-integrity mapping target that provides
data integrity
Data integrity is the maintenance of, and the assurance of, data accuracy and consistency over its entire Information Lifecycle Management, life-cycle and is a critical aspect to the design, implementation, and usage of any system that stores, proc ...
, either using checksumming or cryptographic verification, also used with LUKS
* dm-log-writes mapping target that uses two devices, passing through the first device and logging the write operations performed to it on the second device
* dm-verity validates the data blocks contained in a file system against a list of cryptographic hash values, developed as part of the
Chromium OS
ChromiumOS is a free and open-source operating system designed for running web applications and browsing the World Wide Web. It is the open-source version of ChromeOS, a Linux-based operating system made by Google.
Like ChromeOS, ChromiumOS is ...
project
* provides access to
"fake" RAID configurations via the device mapper
*
DM Multipath provides I/O failover and load-balancing of block devices within the Linux kernel
*
Docker uses device mapper to create copy-on-write storage for software containers
*
DRBD
DRBD is a distributed replicated storage system for the Linux platform. It is implemented as a kernel driver, several userspace management applications, and some shell scripts. DRBD is traditionally used in high availability (HA) computer clust ...
(Distributed Replicated Block Device)
*
EVMS (deprecated)
* utility called from hotplug upon device maps creation and deletion
*
LVM2 logical volume manager
In computer storage, logical volume management or LVM provides a method of allocating space on mass-storage devices that is more flexible than conventional partitioning schemes to store volumes. In particular, a volume manager can concatenate ...
for the Linux kernel
*
VeraCrypt - Linux version of
TrueCrypt
TrueCrypt is a discontinued source-available freeware utility used for on-the-fly encryption (OTFE). It can create a virtual encrypted disk within a file, or encrypt a partition or the whole storage device (pre-boot authentication).
On 28 May ...
*VDO - Virtual Data Optimizer
References
External links
Device mapper home at Red Hat* an article illustrating the use of various device mapper targets
userspace tool to set up software RAID using various RAID metadata formatsMultipath support in the device mapper LWN.net
LWN.net is a computing webzine with an emphasis on free software and software for Linux and other Unix-like operating systems. It consists of a weekly issue, separate stories which are published most days, and threaded discussion attached to ...
, February 23, 2005, by Jonathan Corbet
{{Operating system
Red Hat software