Device mapper
The device mapper is a framework built into the Linux kernel. It connects real storage devices, called block devices, to new virtual block devices that sit on top of them.
The device mapper is the foundation for several important tools. It supports the logical volume manager (LVM), software RAIDs, and dm-crypt disk encryption. It also offers extra features, such as file system snapshots.
It works by passing data from a virtual block device to another block device. On the way, the data can be changed. For example, this is how the device mapper provides disk encryption or imitates unreliable hardware.
Usage
Programs such as LVM2 and Enterprise Volume Management System (EVMS) use the device mapper when they need to create new mapped devices. They do this through a shared library called libdevmapper.so, which sends ioctls to the /dev/mapper/control device node. The device mapper's settings can also be viewed and changed by hand, or from shell scripts, using the dmsetup utility.
Both of these parts have their source code kept together with the LVM2 source code.
Features
The device mapper can do several jobs, such as linear, striped and error mappings, and crypt and multipath targets. For example, two disks may be joined into one logical volume using a pair of linear mappings, one for each disk. The crypt target encrypts the data that passes through a device, using the Linux kernel's Crypto API.
As of 2014, the device mapper had many mapping targets. The cache target lets solid-state drives (SSDs) act as caches for hard disk drives (HDDs), which creates hybrid volumes. The mirrored target keeps extra copies of data, the multipath target works with devices that have several paths, and the raid target connects to the Linux kernel's software RAID driver (md). Some targets, like delay, error and flakey, are used for testing. The zero target acts like /dev/zero, so reads return zeros.
Applications
Many Linux computer features and projects are built on top of the device mapper. Here are some of them:
- cryptsetup: a tool that makes it easy to set up disk encryption based on dm-crypt
- dm-crypt/LUKS: a part that scrambles, or encrypts, all the data on a storage volume
- dm-cache: a part that allows creating hybrid volumes
- dm-integrity: a part that helps keep data correct, using checksums or cryptographic checks, and is also used with LUKS
- dm-log-writes: a part that uses two devices, passing data through the first and recording the write actions on the second
- dm-verity: a part that checks the data blocks in a file system against a list of cryptographic hash values, developed as part of the ChromiumOS project
- dmraid(8): gives access to "fake" RAID setups through the device mapper
- DM Multipath: provides backup paths if one fails and shares work across block devices inside the Linux kernel
- Docker: uses the device mapper to create copy-on-write storage for software containers
- DRBD (Distributed Replicated Block Device)
- EVMS (deprecated, meaning it is no longer recommended)
- kpartx(8): a tool that is run by hotplug when device maps are created or deleted
- LVM2: a logical volume manager for the Linux kernel
- VeraCrypt: the Linux version of TrueCrypt
- VDO: Virtual Data Optimizer
This article is a child-friendly adaptation of the Wikipedia article on Device mapper, available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.
