Examples of using dmsetup command in Linux

It is a command using which we can do low level logical volume management. So basically dmsetup is used to manage logical devices that use the device-mapper driver. The first argument to dmsetup is a command. The second argument is the logical device name or uuid.

The package which provides dmsetup command can be found out using:

# yum whatprovices /sbin/dmsetup
...

7:device-mapper-1.02.158-2.el7_7.2.x86_64 : Device mapper utility
Repo        : @updates
Matched from:
Filename    : /sbin/dmsetup

Examples of using dmsetup command

1. To list the device mapper devices:

# dmsetup ls 
# dmsetup ls
VG00-LV02       (253, 2)
VG00-LV01       (253, 1)
VG00-LV00       (253, 0)

2. To get information about any DM device:

# dmsetup info /dev/VG00/LV00 
# dmsetup info /dev/VG00/LV00
Name:              VG00-LV00
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        1
Event number:      0
Major, minor:      253, 0
Number of targets: 2
UUID: LVM-jUqeLC.....

3. To get DM device info in column wise:

# dmsetup info -c /dev/VG00/LV00
# dmsetup info -C /dev/VG00/LV00 
# dmsetup info -c /dev/VG00/LV00
Name             Maj Min Stat Open Targ Event  UUID
VG00-LV00        253   0 L--w    1    2      0 LVM-jUqeLvGB9........

4. To list the DM device dependencies:

# dmsetup deps /dev/VG00/LV00 
# dmsetup deps /dev/VG00/LV00
 2 dependencies  : (8, 48) (8, 32)

5. To get the status of a DM device:

# dmsetup status /dev/VG00/LV00 
# dmsetup status /dev/VG00/LV00
0 20963328 linear
20963328 8192 linear

6. To destroy the inactive table for a device:

# dmsetup clear /dev/VG00/LV00 

7. To send message to target:

# dmsetup device_name sector message
# dmsetup /dev/VG00/LV00 0 "My Logical device" 

8. To remove a device (this will cause data loss):

# dmsetup remove /dev/VG00/LV00 

9. To remove all the devices:

# dmsetup remove_all 

10. To rename the device:

# dmsetup /dev/VG00/LV00 /dev/VG00/LV04 

11. To suspend a device:

# dmsetup suspend --nolockfs /dev/VG00/LV00
# dmsetup suspend --noflush /dev/VG00/LV00

12. To un-suspend a device:

# dmsetup resume /dev/VG00/LV00 

13. To output the table for a device:

# dmsetup table /dev/VG00/LV00 
# dmsetup table /dev/VG00/LV00
0 20963328 linear 8:32 2048
20963328 8192 linear 8:48 2048

14. To get the dmsetup version info:

# dmsetup version 
# dmsetup version
Library version:   1.02.53 (2010-07-28)
Driver version:    4.17.0 

15. To display the help information:

# dmsetup -h
Related Post