is /dev/dm-1 a partition or a whole block device?

38,482

Solution 1

For a given dm-x with major M, minor m, there is a corresponding /sys/dev/block/M:m/dm/uuid file. If the content of the uuid file starts with part, it is safe to assume it is a partition. The corresponding whole device is found in /sys/dev/block/M:n/slaves/. For instance:

[centos@try ~]$ cat /sys/dev/block/253:0/dm/uuid
mpath-353333330000007d0
[centos@try ~]$ cat /sys/dev/block/253:1/dm/uuid
part1-mpath-353333330000007d0
[centos@try ~]$ ls -l /sys/dev/block/253:1/slaves
total 0
lrwxrwxrwx. 1 root root 0 15 août  22:06 dm-0 -> ../../dm-0

Solution 2

Every partition is a "whole" block-device. You could sub-partition any partition, and then sub-partition it again, and again ...

In your example dm-1 could be mapped to anything, a raw device, a dmcrypt device abstraction, a logical volume on a MD-RAID-backed, multi-pathed, dm-crypted volume group.

The number dm-X basically was just an arbitrary free number when the device was initialized. On hosts without many changes in the block device layer during runtime these numbers are just allocated in natural order at bootup.

But most device mapper mechanisms also allow you to specify an alias for your mapping. Check out ls -l /dev/mapper/.

To then visualize the hierarchical relationships between block devices you can use the lsblk (List block-devices). Shortened example output below:

$ lsblk /dev/sdb
NAME                   MAJ:MIN  TYPE
sdb                      8:128  disk
├─sdb1                   8:129  part
└─sdb5                   8:133  part
  └─crypto (dm-0)        252:0  crypt
    ├─ubuntu-root (dm-1) 252:1  lvm
    └─ubuntu-swap (dm-2) 252:2  lvm

Solution 3

The lsblk command is a convenient way of displaying information about block devices including which device mapper device goes where.

Solution 4

/dev/dm-1 is for "device mapper n.1".

Basically, it is a logical unit carved out using the kernel embedded device mapper layer. From a userspace application point of view, it is a RAW block device.

Using pvs and lvdisplay we should be able to tell you the specific physical disk/partition backing it.

Share:
38,482

Related videos on Youtube

Loic Dachary
Author by

Loic Dachary

Updated on September 18, 2022

Comments

  • Loic Dachary
    Loic Dachary almost 2 years

    Is there a way to figure out if /dev/dm-1 is a block device partition or a whole block device? If /dev/dm-1 is a partition, is there a way to find out the path to the corresponding whole block device?

  • womble
    womble almost 9 years
    device-mapper is used for a lot more than just LVM. Assuming pvs and lvdisplay will show you the details of any given dm-X device is not a good assumption.
  • shodanshok
    shodanshok almost 9 years
    True, but I shot for the common case first...