11

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
  • 95,029
  • 29
  • 173
  • 228
Loic Dachary
  • 851
  • 1
  • 7
  • 11

4 Answers4

14

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
Alex Stragies
  • 369
  • 3
  • 12
6

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

Tilman Schmidt
  • 3,778
  • 10
  • 23
5

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
Loic Dachary
  • 851
  • 1
  • 7
  • 11
2

/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.

shodanshok
  • 44,038
  • 6
  • 98
  • 162
  • 1
    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. – womble Aug 16 '15 at 01:11
  • True, but I shot for the common case first... – shodanshok Aug 16 '15 at 06:53