Device mapper#Features
{{Short description|Software framework of Linux kernel}}
The device mapper is a framework provided by the Linux kernel for mapping physical block devices onto higher-level virtual block devices. It forms the foundation of the logical volume manager (LVM), software RAIDs and dm-crypt disk encryption, and offers additional features such as file system snapshots.{{cite web
| url = https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/device_mapper.html
| title = Logical Volume Manager Administration, Appendix A. The Device Mapper
| access-date = 2013-09-29
| publisher = Red Hat
}}
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 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 and DragonFly BSD.{{cite web
| url = http://netbsd.gw.com/cgi-bin/man-cgi?dm+4+NetBSD-current
| title = NetBSD Kernel Interfaces Manual: dm(4)
| date = 2008-08-30
| access-date = 2015-01-25
| website = netbsd.gw.com
| archive-date = 2014-07-19
| archive-url = https://web.archive.org/web/20140719152701/http://netbsd.gw.com/cgi-bin/man-cgi?dm+4+NetBSD-current
| url-status = dead
| url = http://leaf.dragonflybsd.org/cgi/web-man?command=dm§ion=4
| title = DragonFly On-Line Manual Pages: dm(4)
| date = 2010-07-28 | access-date = 2014-06-06
| website = dragonflybsd.org
}}
Usage
Applications (like LVM2 and Enterprise Volume Management System (EVMS)) that need to create new mapped devices talk to the device mapper via the libdevmapper.so
shared library, which in turn issues ioctls to the /dev/mapper/control
device node.{{cite web
| url = http://www.sourceware.org/cgi-bin/cvsweb.cgi/~checkout~/LVM2/libdm/libdevmapper.h?content-type=text/plain&cvsroot=lvm2
| title = libdevmapper.h
| access-date = 2013-09-29
| publisher = sourceware.org
}}{{Dead link|date=March 2023 |bot=InternetArchiveBot |fix-attempted=yes }} Configuration of the device mapper can be also examined and configured interactively{{mdashb}}or from shell scripts{{mdashb}}by using the {{man|8|dmsetup|man.cx||inline}} utility.{{cite web
| url = http://man.cx/?page=dmsetup%288%29
| title = dmsetup(8) - Linux man page
| access-date = 2013-10-22
| publisher = man.cx
| url = https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/dmsetup.html
| title = Logical Volume Manager Administration
| work = Appendix A.2. The dmsetup Command
| access-date = 2013-09-29
| publisher = Red Hat
}}
Both of these two userspace components have their source code maintained alongside the LVM2 source.{{cite web
| url = http://www.sourceware.org/dm/
| title = Device-mapper Resource Page
| access-date = 2013-09-29
| publisher = sourceware.org
}}
Features
File:The Linux Storage Stack Diagram.svg's storage stack.{{Cite web
| url = https://www.thomas-krenn.com/en/wiki/Linux_Storage_Stack_Diagram
| title = Linux Storage Stack Diagram
| date = 2015-06-01 | access-date = 2015-06-08
| author1 = Werner Fischer | author2 = Georg Schönberger
| publisher = Thomas-Krenn.AG
}}]]
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.
{{As of|2014}}, the following mapping targets are available:
- cache{{snd}} allows creation of hybrid volumes, by using solid-state drives (SSDs) as caches for hard disk drives (HDDs)
- clone{{snd}} will permit usage before a transfer is complete.
- crypt{{snd}} provides data encryption, by using the Linux kernel's Crypto API
- delay{{snd}} delays reads and/or writes to different devices (used for testing)
- era{{snd}} 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{{cite web
| url = http://kernelnewbies.org/Linux_3.15#head-33ab227d4984f4be9fa92f9163e403744e2a8f66
| title = 6. Block layer | work = Linux kernel 3.15
| date = 2014-06-08 | access-date = 2014-06-15
| publisher = kernelnewbies.org
}}
- error{{snd}} simulates I/O errors for all mapped blocks (used for testing)
- flakey{{snd}} simulates periodic unreliable behaviour (used for testing)
- linear{{snd}} maps a continuous range of blocks onto another block device
- mirror{{snd}} maps a mirrored logical device, while providing data redundancy
- multipath{{snd}} supports the mapping of multipathed devices, through usage of their path groups
- raid{{snd}} offers an interface to the Linux kernel's software RAID driver (md)
- snapshot and snapshot-origin{{snd}} used for creation of LVM snapshots, as part of the underlying copy-on-write scheme
- striped{{snd}} stripes the data across physical devices, with the number of stripes and the striping chunk size as parameters
- thin {{snd}} allows creation of devices larger than the underlying physical device, physical space is allocated only when written to
- zero{{snd}} an equivalent of
/dev/zero
, all reads return blocks of zeros, and writes are discarded
{{Anchor|DM-LOG-WRITES|DM-VERITY}}Applications
Linux kernel features and projects built on top of the device mapper include the following:
- cryptsetup{{snd}} utility used to conveniently setup disk encryption based on dm-crypt
- dm-crypt/LUKS{{snd}} mapping target that provides volume encryption
- dm-cache{{snd}} mapping target that allows creation of hybrid volumes
- dm-integrity{{snd}} mapping target that provides data integrity, either using checksumming or cryptographic verification,{{cite web
| url = https://gitlab.com/cryptsetup/cryptsetup/wikis/DMIntegrity
| title = dm-integrity
| date = 2018-04-30 | access-date = 2018-05-08
| publisher = cryptosetup project
| url = https://www.kernel.org/doc/Documentation/device-mapper/dm-integrity.txt
| title = dm-integrity target
| date = 2017-05-13 | access-date = 2018-05-08
| publisher = kernel.org
}} also used with LUKS{{cite web
| url = https://man.cx/?page=cryptsetup(8)
| title = cryptsetup - manage plain dm-crypt and LUKS encrypted volumes
| date = 2018-01-01 | access-date = 2018-05-08
}}
- dm-log-writes{{snd}} mapping target that uses two devices, passing through the first device and logging the write operations performed to it on the second device{{cite web
| url = https://www.kernel.org/doc/Documentation/device-mapper/log-writes.txt
| title = Linux kernel documentation: Documentation/device-mapper/log-writes.txt
| date = 2015-05-29 | access-date = 2015-10-13
| publisher = kernel.org
}}
- dm-verity{{snd}} validates the data blocks contained in a file system against a list of cryptographic hash values, developed as part of the ChromiumOS project{{cite web
| url = https://lwn.net/Articles/459420/
| title = dm-verity
| date = 2011-09-19 | access-date = 2015-10-13
| author = Jonathan Corbet | publisher = LWN.net
}}
- {{man|8|dmraid|man.cx||inline}}{{snd}} provides access to "fake" RAID configurations via the device mapper
- DM Multipath{{snd}} provides I/O failover and load-balancing of block devices within the Linux kernel
- Docker{{snd}} uses device mapper to create copy-on-write storage for software containers
- DRBD (Distributed Replicated Block Device)
- EVMS (deprecated)
- {{man|8|kpartx|man.cx||inline}}{{snd}} utility called from hotplug upon device maps creation and deletion
- LVM2{{snd}} logical volume manager for the Linux kernel
- VeraCrypt - Linux version of TrueCrypt
- VDO - Virtual Data Optimizer
References
{{Reflist|30em}}
External links
- [http://sources.redhat.com/dm/ Device mapper home at Red Hat] {{Webarchive|url=https://web.archive.org/web/20060315124752/http://sources.redhat.com/dm/ |date=2006-03-15 }}
- {{cite web | url=http://linuxgazette.net/114/kapil.html | title=Right To Your Own Devices | work = Linux Gazette | date = May 2005
}}{{snd}} an article illustrating the use of various device mapper targets
- [http://people.redhat.com/~heinzm/sw/dmraid/readme userspace tool to set up software RAID using various RAID metadata formats]
- [https://lwn.net/Articles/124703/ Multipath support in the device mapper], LWN.net, February 23, 2005, by Jonathan Corbet
{{Clear}}
{{Linux kernel}}
{{Linux}}
{{Operating system}}