Safekipedia

Device mapper

Adventurer · ages 7–10Adapted from Wikipedia
The position of the device mapper targets within various layers of the Linux kernel's storage stack.

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 useful 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. Along 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 with a shared library called libdevmapper.so, which sends ioctls to the /dev/mapper/control device node. People can also look at and change the device mapper's settings by hand, or from shell scripts, using the dmsetup tool.

The source code for both of these parts is kept together with the LVM2 source code.

Features

The position of the device mapper targets within various layers of the Linux kernel's storage stack.

The device mapper can do several jobs. These include linear, striped and error mappings, and crypt and multipath targets. For example, two disks may be joined into one logical volume using two linear mappings, one for each disk. The crypt target encrypts the data that passes through a device. It uses 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). This creates hybrid volumes. The mirrored target keeps extra copies of data. The multipath target works with devices that have several paths. 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. It passes data through the first and records 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. It was 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.