
dmsetup Command in Linux
The Linux dmsetup is a low-level command that manages the device mapper devices. The device-mapper is a kernel framework that maps the physical block devices to virtual block devices. Virtual block devices, or logical devices, are more flexible to manipulate than physical block devices.
Table of Contents
Here is a comprehensive guide to the options available with the dmsetup command −
- Syntax of dmsetup Command
- Subcommands for the dmsetup Command
- dmsetup Command Options
- Examples of dmsetup Command in Linux
Syntax of dmsetup Command
The general syntax for the dmsetup command is as follows −
dmsetup [subcommand] [options]
The [subcommand] field is used to specify the command to perform an operation on a device mapper device. While the [options] field modifies the behavior of the command.
Subcommands for dmsetup Command
To perform an action, the Linux dmsetup command combines with a subcommand. Important subcommands include −
Subcommand | Description |
---|---|
clear device_name | It clears the device mapping associated with device_name (It does not delete the device) |
create device_name | It creates a new device mapping named device_name |
deps device_name | It displays the device dependencies of the specified device |
info device_name | It provides information about the specified device such as state ACTIVE, INACTIVE, SUSPENDED, or READONLY |
load device_name | It loads the new table for the specified device name |
ls | It lists the device mapper devices |
reload device_name | It reloads the mapping table |
remove device_name | It removes the specified device mapping |
rename device_name, new_name | It renames the specified device |
resume device_name | It resumes the I/O operations on the specified device |
suspend device_name | It suspends the I/O operations on the specified device |
status device_name | It displays the status of the specified device by target |
table device_name | It displays the mapping table of the specified device |
targets | It displays the list of available device mapper target types |
wipe-table device_name | It removes the mapping table associated with the specified device |
dmsetup Command Options
The commonly used options for dmsetup and its subcommands are listed in the following table −
Options | Description |
---|---|
-c | -C | --columns | It displays the output in columns |
-h | --help | It displays the help related to command or subcommand |
--notable | It is used to create devices without a table |
-o | --options | It displays the specified field |
-r | --readonly | It loads the table in read-only form |
--table table | To specify the table |
-u | --uuid | To specify the uuid |
-y | --yes | It answers yes to all prompts |
-v | --verbose | It displays the detailed output |
Examples of dmsetup Command in Linux
This section describes the usage of the dmsetup command on Linux using various examples.
- Listing all the Devices
- Listing the Supported Target Types
- Creating a Device Mapper Device
- Displaying Information about a Device
- Renaming a Device
- Suspending and Resuming a Device
- Removing a Device
Note − The dmsetup command requires sudo privileges.
Listing all the Devices
To list the device mapper devices, use the dmsetup command with the ls subcommand.
sudo dmsetup ls

The output shows two active devices.
Listing the Supported Target Types
To create a virtual block, you need to know its various types. The dmsetup command can list the supported target types −
sudo dmsetup targets

It lists the target types.
Type | Description |
---|---|
zero | Any data written to this device will be discarded |
multipath | It manages multipath I/O by grouping multiple physical paths to storage into a single logical device |
mirror | It mirrors data across two or more devices, ensuring redundancy by maintaining similar copies |
striped | It stripes data across multiple devices, distributing data blocks evenly for improved performance |
linear | It combines data from multiple disks into a single logical device without striping or redundancy |
error | It acts as a sink for I/O errors generated, useful for testing or error-handling |
snapshot | It creates a snapshot of a device mapper device |
Apart from these, other targets are crypt, delay, flakey, and raid.
Creating a Device Mapper Device
To create the device mapper device, use the create subcommand. The general syntax to create a device is as follows −
sudo dmsetup create [name] --table '[start sector] [end sector] [target] [target paramaters]'
For example, to create a type zero device-mapper device, run −
sudo dmsetup create mydevice_zero --table '0 800 zero'

In the above command, 0 is the starting sector while 800 is the ending sector. The zero indicates the target type.
To create a linear virtual block, execute −
sudo dmsetup create mydevice_linear --table '0 1000 linear /dev/loop0 0'
In the above command, a linear virtual block is created. The 0 is the starting sector and 1000 indicates the total sectors. The type is linear while /dev/loop0 is a loopback device that can create the virtual block. The 0 at the end of the command is the starting sector of the physical device /dev/loop0.
To create a snapshot of the device mapper device, use the snapshot type. It is a two-step process; first mark a device as a snapshot origin.
sudo dmsetup create mysnapshot_origin --table '0 1000 snapshot-origin /dev/mapper/mytest_snapshot'
After marking a device as an origin, create its snapshot −
sudo dmsetup create mysnapshot --table '0 1000 snapshot /dev/mapper/mytest_snapshot /dev/mapper/snapshot P 6'
The snapshots are of two types: persistent or non-persistent. The persistent snapshots survive the reboot and stay valid. At the same time, non-persistent snapshots get invalid after system reboot. Persistent and non-persistent snapshots are denoted by P and N, respectively. The 6 indicates the chunk size in sectors; which signifies the number of sectors snapshots at an interval. Another important thing to note is that the origin device is not mentioned by its device name; the underlying device path is used.
Displaying Information about A Device
To display the information of all the devices, use the info subcommand −
sudo dmsetup info
To retrieve the details about a specific device, mention the device name −
sudo dmsetup info mydevice_zero
To display the info in column form, use the -c option −
sudo dmsetup info -c
To display the information of specific options, use the -o flag with the column name −
sudo dmsetup info -c -o 'major,minor'

Renaming a Device
To rename the device, use the rename subcommand.
sudo dmsetup rename [device_name] [new_device_name]
For instance, to rename the mydevice_zero, run −
sudo dmsetup rename mydevice_zero new_mydevice_zero

Suspending and Resuming a Device
Any device can be suspended or resumed easily using the dmsetup with the suspend and resume subcommands.
sudo dmsetup suspend [device_name] sudo dmsetup resume [device_name]
For example, to suspend mydevice_zero device, use the following command −
sudo dmsetup suspend mydevice_zero
To resume the device, replace suspend with resume subcommand −
sudo dmsetup resume mydevice_zero

Removing a Device
To delete the device, use the remove subcommand.
sudo dmsetup remove [device_name]
For example, to remove mydevice_linear, run −
sudo dmsetup remove mydevice_linear
To verify, list the devices.

Conclusion
The dmsetup command in Linux is used to manage the device mapper devices. The device mapper is a kernel framework used to create and manage virtual block devices. The virtual block devices are easier to manage in partitions and resize the partition.
In this tutorial, we explained the Linux dmsetup command, its syntax, subcommand, options, and usage through various examples.