逻辑和物理块设备名称之间的映射


19

我无法弄清楚不同逻辑和物理块设备名称之间的映射。“ cat / proc / diskstats”的输出是:

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

“ df -h”的输出为:

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

在哪里找到“ cciss”,“ dm-#”和“ VolGroup ##”之间的映射?

谢谢


3
在一切/dev/mapper目录通常是一个符号链接到实际的设备。
2012年

Answers:


25

有方便dmsetup ls --tree和实用程序lsblk


2
尽管这不能为您提供VG及其PV之间的映射。为此,您需要运行pvdisplay并将vgdisplay其输出与的输出关联起来dmsetup ls
Alexios 2012年

3
@Alexios ,?没有尝试lsblk吗?
poige 2012年

没有lsblk在CentOS 5
karatedog

6

我刚遇到这个问题,因此我将在此处记录对我有帮助的内容。

poise的答案是正确的,dmsetup ls --tree如果您知道如何解释输出,则可以从中获取所需的所有信息。

cciss是设备名称,即您的实际磁盘。该手册页拼出来好,但我会在这里复制的相关章节:

   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

“ dm-#”是设备映射器编号。映射DM编号最简单的方法是run lvdisplay,它显示逻辑卷名称,它所属的卷组以及块设备。在“块设备”行中,冒号后列出的值是DM编号。

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

哪个很好地映射回了 dmsetup ls --tree

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

您还可以通过运行来查看DM编号映射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

第六列列出了DM编号。因此,对于我的服务器,vg0-opt安装在/ opt上,并映射回DM-5。



2

@Jon Buys和@poige的答案是正确的,但至少在内核相对较新的系统上,它甚至更简单。

中的条目/dev/mapper只是指向其中的dm-x设备的软链接/dev,因此您需要做的只是:

ls -l /dev/mapper

例如,在我的系统上,这显示:

# ls -l /dev/mapper/  
total 0
crw-------. 1 root root 10, 236 Dec 12 10:11 control
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_cache_pool_home_cdata -> ../dm-3
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_cache_pool_home_cmeta -> ../dm-4
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_cache_pool_var_cdata -> ../dm-7
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_cache_pool_var_cmeta -> ../dm-8
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_home -> ../dm-6
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_home_corig -> ../dm-5
lrwxrwxrwx. 1 root root       8 Dec 12 10:11 vg_raid10-lv_var -> ../dm-10
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_raid10-lv_var_corig -> ../dm-9
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_ssd-lv_root -> ../dm-0
lrwxrwxrwx. 1 root root       7 Dec 12 10:11 vg_ssd-lv_swap -> ../dm-1
lrwxrwxrwx. 1 root root       8 Dec 27 20:00 vg_ssd_sata-docker--pool -> ../dm-13
lrwxrwxrwx. 1 root root       8 Dec 27 20:00 vg_ssd_sata-docker--pool_tdata -> ../dm-12
lrwxrwxrwx. 1 root root       8 Dec 27 20:00 vg_ssd_sata-docker--pool_tmeta -> ../dm-11
lrwxrwxrwx. 1 root root       7 Dec 27 20:00 vg_ssd_sata-lv_scratch -> ../dm-2
lrwxrwxrwx. 1 root root       8 Dec 27 20:00 vg_ssd_sata-lv_vms -> ../dm-14

如果您ls没有帮助并且没有显示软链接,请尝试以下操作:

for x in /dev/mapper/*; do echo "$(realpath $x) -> $x"; done;

应该输出如下内容:

/dev/mapper/control -> /dev/mapper/control
/dev/dm-3 -> /dev/mapper/vg_raid10-lv_cache_pool_home_cdata
/dev/dm-4 -> /dev/mapper/vg_raid10-lv_cache_pool_home_cmeta
...

以及是否要查找特定的映射,例如dm-6

# (for x in /dev/mapper/*; do echo "$(realpath $x) -> $x"; done;) | grep dm-6
/dev/dm-6 -> /dev/mapper/vg_raid10-lv_home

1

我遇到过同样的问题,也许有点“深入”:直到安装点级别。如果有人感兴趣,这是我正在使用的两个函数,用于查询两种方式。

######## 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"
}

和反向查询:

######## 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
}

1

使用dmsetup ls --tree -o blkdevname

[root@redhat7 Packages]# dmsetup ls --tree -o blkdevname
rhel-swap <dm-1> (253:1)
 └─ <sda2> (8:2)
rhel-root <dm-0> (253:0)
 └─ <sda2> (8:2)
oraclevg-oraclelv <dm-2> (253:2)
 └─ <sdb> (8:16)

需要root访问
iruvar

-2

所有绑定都映射在file中 /etc/multipath/bindings。你可以在这里重新命名任何设备,如从/dev/mapper/mpathf/dev/mapper/mpathe

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.