Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I cannot figure out the mapping between different logical and physical block device names. The output of "cat /proc/diskstats" is :

 104    0 cciss/c0d0 ...
 104    1 cciss/c0d0p1 ...
 104    2 cciss/c0d0p2 ...
 104    16 cciss/c0d1 ...
 253    0 dm-0 ...
 253    1 dm-1 ...
 253    2 dm-2 ...
 253    3 dm-3 ...

The output of "df -h" is :

/dev/cciss/c0d0p1                 99M   39M   56M  42% /boot
/dev/mapper/VolGroup01-LogVol02   908G  760G  103G  89% /home
/dev/mapper/VolGroup01-LogVol03   193G  181G  2.6G  99% /opt
/dev/mapper/VolGroup00-LogVol00   54G   11G   41G  21%  /

Where do I find the mapping between "cciss" , "dm-#", and "VolGroup##" ?

Thanks

share|improve this question
3  
Everything in the /dev/mapper directory is typically a symlink to the actual device. – jw013 Jun 19 '12 at 1:29

There're handy dmsetup ls --tree and lsblk utils.

share|improve this answer
2  
Although that doesn't give you the mapping between VGs and their PVs. For that, you'd need to run pvdisplay and vgdisplay and correlate their output to that of dmsetup ls. – Alexios Jun 19 '12 at 9:54
1  
@Alexios, ? Didn't try lsblk? – poige Jun 20 '12 at 13:17

Ok, finally figured that out.

pvscan command provides the mapping I'm looking for.

share|improve this answer
    
pvs, rather, or did I misunderstand the question? – Gilles Jun 19 '12 at 23:37

I was just running into this, so I'll document what helped me here.

poise's answer is correct, You can get all of the information you need from dmsetup ls --tree, if you know how to interpret the output.

cciss is the device name, that's your actual disk. The man page spells it out well, but I'll copy the relevant section here:

   Device nodes
   The device naming scheme is as follows:

   Major numbers:

       104     cciss0
       105     cciss1
       106     cciss2
       105     cciss3
       108     cciss4
       109     cciss5
       110     cciss6
       111     cciss7

   Minor numbers:

       b7 b6 b5 b4 b3 b2 b1 b0
       |----+----| |----+----|
            |           |
            |           +-------- Partition ID (0=wholedev, 1-15 partition)
            |
            +-------------------- Logical Volume number

   The device naming scheme is:

       /dev/cciss/c0d0         Controller 0, disk 0, whole device
       /dev/cciss/c0d0p1       Controller 0, disk 0, partition 1
       /dev/cciss/c0d0p2       Controller 0, disk 0, partition 2
       /dev/cciss/c0d0p3       Controller 0, disk 0, partition 3

       /dev/cciss/c1d1         Controller 1, disk 1, whole device
       /dev/cciss/c1d1p1       Controller 1, disk 1, partition 1
       /dev/cciss/c1d1p2       Controller 1, disk 1, partition 2
       /dev/cciss/c1d1p3       Controller 1, disk 1, partition 3

The "dm-#" is the device mapper number. The easiest way to map DM numbers is to run lvdisplay, which shows the logical volume name, the volume group it belongs to, and the block device. In the "Block device" row, the value listed after the colon is the DM number.

root@centos:/dev > lvdisplay /dev/vg0/opt 
  --- Logical volume ---
  LV Name                /dev/vg0/opt
  VG Name                vg0
  LV UUID                ObffAT-txIn-5Rwy-bW5s-gekn-VLZv-71mDZi
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             32
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

Which maps back nicely to the output of dmsetup ls --tree

vg0-opt (253:5)
 └─ (104:3)

You can also see the DM number mappings by running ls -lrt /dev/mapper.

root@centos:/dev > ls -lrt /dev/mapper
total 0
crw------- 1 root root  10, 60 Aug 29  2013 control
brw-rw---- 1 root disk 253,  0 Aug 29  2013 vg0-root
brw-rw---- 1 root disk 253,  1 Aug 29  2013 vg0-usr
brw-rw---- 1 root disk 253,  2 Aug 29  2013 vg0-tmp
brw-rw---- 1 root disk 253,  3 Aug 29  2013 vg0-var
brw-rw---- 1 root disk 253,  4 Aug 29  2013 vg0-home
brw-rw---- 1 root disk 253,  5 Aug 29  2013 vg0-opt

The sixth column lists the DM number. So, for my server, vg0-opt is mounted on /opt, and maps back to DM-5.

share|improve this answer

I've had the same issue, maybe little "deeper": up to the mount point level. In case anyone is interested, here are two functions I'm using, for querying both ways.

######## FIND THE LVPATH of an existing FS. Query the lvm using FS' mount point
fileSystem_to_lvPath(){
    FS_TO_QUERY=$1
    #Call like this:  $0 /tmp
    #Relevant commands for debug: blkid, lsblk, dmsetup, lvdisplay, lvs
    #OLD Solution: DEV_MAPPER=$(df -l --output=source $1 | awk '{print $1}' | cut -d"/" -f 4 | tail -1)

    #Find DeviceMapper_MajorMinorNumber for specific fs
    DeviceMapper_MajorMinorNumber=$(lsblk --noheadings --output TYPE,MAJ:MIN,MOUNTPOINT | grep -w lvm | grep -w $FS_TO_QUERY | awk '{print $2}')

    #VG=$(lvs --noheadings --separator : --options lv_kernel_major,lv_kernel_minor,vg_name,lv_name,lv_path | grep $DeviceMapper_MajorMinorNumber | awk -F : '{print $3}')
    #LV=$(lvs --noheadings --separator : --options lv_kernel_major,lv_kernel_minor,vg_name,lv_name,lv_path | grep $DeviceMapper_MajorMinorNumber | awk -F : '{print $4}')
    LV_PATH=$(lvs --noheadings --separator : --options lv_kernel_major,lv_kernel_minor,vg_name,lv_name,lv_path | grep $DeviceMapper_MajorMinorNumber | awk -F : '{print $5}')
    echo $LV_PATH
    #echo "$VG/$LV"
}

and the reverse query:

######## FIND THE FS (and FS' mountpoint) of an existing LVPATH:
 lvPath_to_fileSystem(){
    LV_PATH=$1
    #Call like this:  $0 /dev/vg00/opt
    #Relevant commands for debug: blkid, lsblk, dmsetup, lvdisplay, lvs
    #OLD Solution: DEV_MAPPER=$(df -l --output=source $1 | awk '{print $1}' | cut -d"/" -f 4 | tail -1)

    #Find DeviceMapper_MajorMinorNumber for specific lv_path
    DeviceMapper_MajorMinorNumber=$(lvs --noheadings --separator : --options lv_kernel_major,lv_kernel_minor,vg_name,lv_name,lv_path | grep $LV_PATH | awk -F : '{print $1":"$2}')

    FS=$(lsblk --noheadings --output TYPE,MAJ:MIN,MOUNTPOINT | grep -w lvm | grep -w $DeviceMapper_MajorMinorNumber | awk '{print $3}')

    echo $FS
}
share|improve this answer

All binding are mapped in file /etc/multipath/bindings. You can rename here any device like from /dev/mapper/mpathf to /dev/mapper/mpathe.

share|improve this answer
1  
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. - From Review – cuonglm Dec 4 '15 at 6:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.