VD与RAID分区对应关系

40 篇文章 0 订阅
17 篇文章 0 订阅

概述

环境中创建了VD,lsblk可以看到创建好后的分区信息,如何获取分区与RAID VD之间的对应关系呢,比如/dev/sdc分区,对应RAID组哪个VD?

实践

Step1. 获取RAID卡的Vendor Id和Device Id

shell

root@ec-node3:~# /opt/MegaRAID/MegaCli/MegaCli64 -adpallinfo -aall | grep -Ei 'Vendor Id|Device Id'
Vendor Id       : 1000
Device Id       : 005d

Step2. 获取VD的Target Id

shell

root@ec-node3:~# /opt/MegaRAID/MegaCli/MegaCli64 -ldpdinfo  aall | grep 'Target Id'
Virtual Drive: 0 (Target Id: 0)
Virtual Drive: 1 (Target Id: 1)
Virtual Drive: 2 (Target Id: 2)
Virtual Drive: 3 (Target Id: 3)
Virtual Drive: 4 (Target Id: 4)
Virtual Drive: 5 (Target Id: 5)
Virtual Drive: 6 (Target Id: 6)
Virtual Drive: 7 (Target Id: 7)
Virtual Drive: 8 (Target Id: 8)
root@ec-node3:~#

Step3. 获取设备前缀信息

shell

root@ec-node3:~# lspci -nd 1000:005d
af:00.0 0104: 1000:005d (rev 02)
root@ec-node3:~# 

这里的af:00.0,就是我们所需的设备前缀信息。

Step4. 根据设备前缀信息以及Target Id,获取对应分区信息

Linux 命令行操作如下:

shell

root@ec-node3:~# cd /dev/disk/by-path
root@ec-node3:/dev/disk/by-path# ls -l
total 0
lrwxrwxrwx 1 root root  9 Jun  8 14:39 pci-0000:00:11.5-ata-1 -> ../../sdj
lrwxrwxrwx 1 root root 10 Jun  8 14:39 pci-0000:00:11.5-ata-1-part1 -> ../../sdj1
lrwxrwxrwx 1 root root 10 Jun  8 14:39 pci-0000:00:11.5-ata-1-part2 -> ../../sdj2
lrwxrwxrwx 1 root root 10 Jun  8 14:39 pci-0000:00:11.5-ata-1-part3 -> ../../sdj3
lrwxrwxrwx 1 root root 10 Jun  8 14:39 pci-0000:00:11.5-ata-1-part4 -> ../../sdj4
lrwxrwxrwx 1 root root  9 Jun  8 14:39 pci-0000:00:11.5-ata-2 -> ../../sdk
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:1:0 -> ../../sdb
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:1:0-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:2:0 -> ../../sdc
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:2:0-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:3:0 -> ../../sdd
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:3:0-part1 -> ../../sdd1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:4:0 -> ../../sde
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:4:0-part1 -> ../../sde1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:5:0 -> ../../sdf
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:5:0-part1 -> ../../sdf1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:6:0 -> ../../sdg
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:6:0-part1 -> ../../sdg1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:7:0 -> ../../sdh
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:7:0-part1 -> ../../sdh1
lrwxrwxrwx 1 root root  9 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:8:0 -> ../../sdi
lrwxrwxrwx 1 root root 10 Jun  8 16:54 pci-0000:af:00.0-scsi-0:2:8:0-part1 -> ../../sdi1
root@ec-node3:/dev/disk/by-path#
root@ec-node3:/dev/disk/by-path# ls -l |grep 'pci-0000:af:00.0-scsi-0:2:2:0' | grep -v part | awk '{{print $NF}}' | awk -F'/' '{{print $NF}}' 
sdc

说明:

pci-0000:af:00.0-scsi-0:2:2:0 ,这里的 0:2:2:0 ,从左向右数,第三位,3,表示的就是Target Id,af:00.0 为设备前缀信息。

Python Code示例如下:

shell

root@ec-node3:~# python
Python 2.7.12 (default, Oct  8 2019, 14:14:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> slot_name = 'af:00.0'
>>> target_id = '2'
>>> import os, re
>>> pattern = re.compile(r':{}-scsi-\d+:\d+:{}:\d+$'.format(slot_name, target_id))
>>> disk_path = None
>>> dev_path = '/dev/disk/by-path'
>>> for disk in os.listdir(dev_path):
...     if pattern.search(disk):
...         path_to_disk = os.readlink(os.path.join(dev_path, disk))
...         disk_path = os.path.normpath(os.path.join(dev_path, path_to_disk))
...         print disk_path
...         break
... 
/dev/sdc
>>> 


来源: Transcendent
文章作者: Gavin Wang
文章链接: VD与RAID分区对应关系 | Transcendent
本文章著作权归作者所有,任何形式的转载都请注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值