1. Overview

Linux systems consist of various components and devices that work together to provide efficient functionality. One such device is the dm-0 device, which is part of the device mapper in the Linux kernel.

In this tutorial, we’ll explore what the dm-0 device is, its purpose, and how it’s related to LVM (Logical Volume Manager).

2. Device Mapper and LVM

The device mapper is a kernel-level framework in Linux that allows for the creation of virtual block devices by mapping physical or logical block devices.

The dm-0 device is one of the virtual block devices created and managed by the device mapper. It’s specifically associated with LVM and represents a logical volume within an LVM volume group.

LVM allows users to manage disk space in a more flexible manner. In addition, these device mappers are typically named “dm-X,” where X is a number assigned to the device.

2.1. dmsetup

dmsetup allows us to manage devices associated with the device mapper framework. We can view, configure, and obtain information about the mappings between logical and physical block devices.

We can view the devices associated with the device mapper with dmsetup:

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

The ls subcommand would display a list of devices along with their respective mappings. Moreover, we can get detailed information about the dm-0 device as well:

$ sudo dmsetup info /dev/dm-0
Name:              dm-0
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        1
Event number:      0
Major, minor:      253, 0

Notably, the dm-0 device here is mapped to a device with major and minor numbers 253, 0.

2.2. lvdisplay

lvdisplay retrieves essential information about the logical volumes configured in the system.

We can use lvdisplay to determine the mappings between logical volumes and the dm-X device:

$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/vol_grp/lvol0
  LV Name                lvol0
  VG Name                vol_grp
  LV UUID                NmNUn0-QKnq-SUnf-5kKl-sm3l-Cq0L-k9QR0d
  LV Write Access        read/write
  LV Creation host, time ubuntu-PC, 2022-02-18 21:43:27 +0545
  LV snapshot status     source of
                         snap [active]
  LV Status              available
  # open                 0
  LV Size                40.00 MiB
  Current LE             10
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

However, the output only subtly reveals the device mapping between a logical volume and a dm device. Therefore, we can use awk to print a proper mapping:

$ sudo lvdisplay | awk  '/LV Name/{n=$3} /Block device/{d=$3; sub(".*:","dm-",d); print d,n;}'
dm-0 /dev/vol_grp/lvol0

Here, we grabbed the LV Name field and put the name of the logical volume in the n variable. Then, we extracted the major and minor numbers of the device and put them in the variable d. Then, we prepend “dm-” to the minor number of the device.

Finally, we print both variables, which shows us the mapping of dm-0 to its respective logical volume.

3. Conclusion

In this article, we explored the device mapper framework and its role in creating virtual block devices. We used tools like dmsetup and lvdisplay to view information about device mappings.

Comments are closed on this article!