Score:0

How to script finding which physical disk belongs to which virtual disk in a RAID confiuration

de flag

I need to write a script to find the firmware versions of physical disks in a RAID configuration, if a physical disk is a specific firmware version then I need to unmount the corresponding virtual disk before upgrading. The problem is I don't know how to easily find the mapping between physical and virtual disks. I need commands that output something I can parse, so JSON or XML preferably.

For example, if I had a system such as this how could I script finding which device (sda or sdb) corresponds to which PD (252:0, 252:1, 252:4, 252:5)?

# lsscsi 
[0:0:0:0]    disk    ATA      WDC WD5003ABYX-0 1S03  /dev/sda 
[6:2:0:0]    disk    AVAGO    MR9361-8i        4.68  /dev/sdb

# /usr/bin/lsblk -l -J
{
   "blockdevices": [
      {"name":"sda", "maj:min":"8:0", "rm":false, "size":"465.8G", "ro":false, "type":"disk", "mountpoint":null},
      {"name":"sda1", "maj:min":"8:1", "rm":false, "size":"15.6G", "ro":false, "type":"part", "mountpoint":"[SWAP]"},
      {"name":"sda2", "maj:min":"8:2", "rm":false, "size":"20G", "ro":false, "type":"part", "mountpoint":"/"},
      {"name":"sda3", "maj:min":"8:3", "rm":false, "size":"46.3G", "ro":false, "type":"part", "mountpoint":"/var"},
      {"name":"sdb", "maj:min":"8:16", "rm":false, "size":"32.8T", "ro":false, "type":"disk", "mountpoint":null},
      {"name":"sdb1", "maj:min":"8:17", "rm":false, "size":"93.1G", "ro":false, "type":"part", "mountpoint":"/var/opt/americandynamics/venvr/clipexport"},
      {"name":"sdb2", "maj:min":"8:18", "rm":false, "size":"32.7T", "ro":false, "type":"part", "mountpoint":"/mediadb"}
   ]
}

# /opt/MegaRAID/storcli/storcli64 show 
Status Code = 0
Status = Success
Description = None

Number of Controllers = 1
Host Name = Colorado
Operating System  = Linux5.3.18-lp152.69-default

System Overview :
===============

---------------------------------------------
Ctl Model                   Ports PDs DGs DNOpt VDs VNOpt BBU sPR DS  EHS ASOs Hlth 
---------------------------------------------
  0 AVAGOMegaRAIDSAS9361-8i     8   4   1     0   1     0 Opt On  1&2 Y      3 Opt  
---------------------------------------------

Ctl=Controller Index|DGs=Drive groups|VDs=Virtual drives|Fld=Failed
PDs=Physical drives|DNOpt=DG NotOptimal|VNOpt=VD NotOptimal|Opt=Optimal
Msng=Missing|Dgd=Degraded|NdAtn=Need Attention|Unkwn=Unknown
sPR=Scheduled Patrol Read|DS=DimmerSwitch|EHS=Emergency Hot Spare
Y=Yes|N=No|ASOs=Advanced Software Options|BBU=Battery backup unit
Hlth=Health|Safe=Safe-mode boot

# /opt/MegaRAID/storcli/storcli64 /c0 show
Generating detailed summary of the adapter, it may take a while to complete.

Controller = 0
Status = Success
Description = None

Product Name = AVAGO MegaRAID SAS 9361-8i
Serial Number = SV53943497
SAS Address =  500605b00acedf80
PCI Address = 00:01:00:00
System Time = 12/22/2021 15:02:48
Mfg. Date = 09/21/15
Controller Time = 12/22/2021 15:02:27
FW Package Build = 24.21.0-0025
BIOS Version = 6.36.00.2_4.19.08.00_0x06180202
FW Version = 4.680.00-8292
Driver Name = megaraid_sas
Driver Version = 07.713.01.00-rc1
Current Personality = RAID-Mode
Vendor Id = 0x1000
Device Id = 0x5D
SubVendor Id = 0x1000
SubDevice Id = 0x9361
Host Interface = PCI-E
Device Interface = SAS-12G
Bus Number = 1
Device Number = 0
Function Number = 0
Drive Groups = 1

TOPOLOGY :
========

---------------------------------------------
DG Arr Row EID:Slot DID Type  State BT      Size PDC  PI SED DS3  FSpace TR 
---------------------------------------------
 0 -   -   -        -   RAID5 Optl  N  32.740 TB dsbl N  N   dflt N      N  
 0 0   -   -        -   RAID5 Optl  N  32.740 TB dsbl N  N   dflt N      N  
 0 0   0   252:0    8   DRIVE Onln  N  10.913 TB dsbl N  N   dflt -      N  
 0 0   1   252:1    10  DRIVE Onln  N  10.913 TB dsbl N  N   dflt -      N  
 0 0   2   252:4    9   DRIVE Onln  N  10.913 TB dsbl N  N   dflt -      N  
 0 0   3   252:5    11  DRIVE Onln  N  10.913 TB dsbl N  N   dflt -      N  
---------------------------------------------

DG=Disk Group Index|Arr=Array Index|Row=Row Index|EID=Enclosure Device ID
DID=Device ID|Type=Drive Type|Onln=Online|Rbld=Rebuild|Dgrd=Degraded
Pdgd=Partially degraded|Offln=Offline|BT=Background Task Active
PDC=PD Cache|PI=Protection Info|SED=Self Encrypting Drive|Frgn=Foreign
DS3=Dimmer Switch 3|dflt=Default|Msng=Missing|FSpace=Free Space Present
TR=Transport Ready

Virtual Drives = 1

VD LIST :
=======

---------------------------------------------
DG/VD TYPE  State Access Consist Cache Cac sCC      Size Name 
---------------------------------------------
0/0   RAID5 Optl  RW     Yes     RWBD  -   ON  32.740 TB      
---------------------------------------------

Cac=CacheCade|Rec=Recovery|OfLn=OffLine|Pdgd=Partially Degraded|dgrd=Degraded
Optl=Optimal|RO=Read Only|RW=Read Write|HD=Hidden|TRANS=TransportReady|B=Blocked|
Consist=ConsistentR=Read Ahead Always|NR=No Read Ahead|WB=WriteBack|
AWB=Always WriteBack|WT=WriteThrough|C=Cached IO|D=Direct IO|sCC=Scheduled
Check Consistency

Physical Drives = 4

PD LIST :
=======

---------------------------------------------
EID:Slt DID State DG      Size Intf Med SED PI SeSz Model                Sp 
---------------------------------------------
252:0     8 Onln   0 10.913 TB SATA HDD N   N  512B HGST HUH721212ALE604 U  
252:1    10 Onln   0 10.913 TB SATA HDD N   N  512B HGST HUH721212ALE604 U  
252:4     9 Onln   0 10.913 TB SATA HDD N   N  512B HGST HUH721212ALE604 U  
252:5    11 Onln   0 10.913 TB SATA HDD N   N  512B HGST HUH721212ALE604 U  
---------------------------------------------

EID-Enclosure Device ID|Slt-Slot No.|DID-Device ID|DG-DriveGroup
DHS-Dedicated Hot Spare|UGood-Unconfigured Good|GHS-Global Hotspare
UBad-Unconfigured Bad|Onln-Online|Offln-Offline|Intf-Interface
Med-Media Type|SED-Self Encryptive Drive|PI-Protection Info
SeSz-Sector Size|Sp-Spun|U-Up|D-Down|T-Transition|F-Foreign
UGUnsp-Unsupported|UGShld-UnConfigured shielded|HSPShld-Hotspare shielded
CFShld-Configured shielded|Cpybck-CopyBack|CBShld-Copyback Shielded


Cachevault_Info :
===============

---------------------------------------------
Model  State   Temp Mode MfgDate    Next Learn           
---------------------------------------------
CVPM02 Optimal 25C  -    2015/12/04 2022/01/12  03:03:06 
---------------------------------------------

# wdckit show -z --output json

{
    "wdckit": {
        "application": {
            "name": "wdckit",
            "versions": [
                {
                    "name": "wdckit",
                    "version": "2.9.0.0",
                    "hash": "f2b9472e7a3ed7c5b374d1e855eb93351c8c0073"
                },
                {
                    "name": "workspace",
                    "version": "2.9.0.0",
                    "hash": "7c67fb1016c100744f1f500f56c050acfb4d2728"
                },
                {
                    "name": "yadl",
                    "version": "1.17.0",
                    "hash": "517e48d01b8edbc5b3ae43f4ca50d825985095ca"
                },
                {
                    "name": "cutils",
                    "version": "1.7.2",
                    "hash": "18a7bee7f8beb9fbad7e471ca197b05a68e1e2e6"
                },
                {
                    "name": "yextata",
                    "version": "2.3.1",
                    "hash": "570cce3a3ccaef19af99097bf9149292d294cc4e"
                },
                {
                    "name": "yextnvme",
                    "version": "9.1.1",
                    "hash": "528238cbec4be66d22faf1e8a67d55e2f67cece5"
                },
                {
                    "name": "yextnvmezns",
                    "version": "3.0.0",
                    "hash": "7abf1fd96e0a5d174ce427d0a842b2d3f8c1dfee"
                },
                {
                    "name": "yextscsi",
                    "version": "2.4.0",
                    "hash": "51d4b9a5fe07e30a4a719fa0070881f3903a50a5"
                },
                {
                    "name": "yextfirmware",
                    "version": "2.2.0",
                    "hash": "bf56f7f6b1517649e56f154f32d312921518351e"
                },
                {
                    "name": "yextraidadaptecwrapper",
                    "version": "1.0.4",
                    "hash": "f2363d24ad942973552d85570252799aca718dcb"
                },
                {
                    "name": "yextraidmegaraidwrapper",
                    "version": "1.2.0",
                    "hash": "78504afaaf02717c6bc86ac66a9b192aeb5c8ffd"
                },
                {
                    "name": "yexttcg",
                    "version": "1.6.0",
                    "hash": "6768b02a80e64302a8748a75bc8929371842fa16"
                },
                {
                    "name": "yextvuc",
                    "version": "6.0.0",
                    "hash": "247db046a4438558109e64aa867f0de823914457"
                },
                {
                    "name": "yextlinpci",
                    "version": "1.0.1",
                    "hash": "a60830cca68f0eef1bc27f98563e327f1cdd2215"
                },
                {
                    "name": "yextxml",
                    "version": "1.2.0",
                    "hash": "a6e94527b75ef1fc3c6b4cf154b6ca0c221dae92"
                },
                {
                    "name": "utilities",
                    "version": "",
                    "hash": "d13caaeac183093be53a18f7cb8f3dbfd63511c1"
                }
            ],
            "command": "show",
            "args": [
                "show",
                "-z",
                "--output",
                "json"
            ],
            "start time [local]": "2021-Dec-22 15:13:30",
            "start time [UTC]": "2021-Dec-22 15:13:30",
            "end time [local]": "2021-Dec-22 15:13:30",
            "end time [UTC]": "2021-Dec-22 15:13:30",
            "working directory": "\/var\/opt\/americandynamics\/users\/VideoEdge",
            "OS": "Linux",
            "OS Details": "5.3.18-lp152.69-default",
            "OS Version": "#1 SMP Tue Apr 6 11:41:13 UTC 2021 (d532e33)"
        },
        "results": [
            {
                "DUT": "0",
                "Device": "\/dev\/sda",
                "Alternate Devices": [
                    "NA"
                ],
                "Port": "SATA",
                "Capacity": "500 GB",
                "State": "Good",
                "BootDevice": "Yes",
                "Serial Number": "WD-WMAYP6676686",
                "Model Number": "WDC WD5003ABYX-01WERA2",
                "Firmware": "01.01S03",
                "Lnk Spd Cap\/Cur": "Gen2\/Gen2",
                "OUI": "0014ee",
                "Type": "Physical",
                "Block Size": "512 Bytes",
                "Max LBA": "976773167",
                "RAID state": "NA",
                "Device Type": "HDD",
                "RPM": "7200",
                "Recording Technology": "CMR"
            },
            {
                "DUT": "1",
                "Device": "\/dev\/sdb",
                "Alternate Devices": [
                    "NA"
                ],
                "Port": "SCSI",
                "Capacity": "35.9 TB",
                "State": "unretrievable",
                "BootDevice": "No",
                "Serial Number": "00b95467140b22cd2780dfce0ab00506",
                "Model Number": "MR9361-8i",
                "Firmware": "4.68",
                "Lnk Spd Cap\/Cur": "unretrievable\/unretrievable",
                "OUI": "00605b",
                "Type": "Logical",
                "Block Size": "512 Bytes",
                "Max LBA": "70310166526",
                "RAID state": "NA",
                "Device Type": "Unknown",
                "RPM": "Unknown",
                "Recording Technology": "CMR"
            },
            {
                "DUT": "2",
                "Device": "megaraid:0.0.8",
                "Alternate Devices": [
                    "NA"
                ],
                "Port": "SATA",
                "Capacity": "12.0 TB",
                "State": "unretrievable",
                "BootDevice": "No",
                "Serial Number": "5PK2NHGB",
                "Model Number": "HGST HUH721212ALE604",
                "Firmware": "LEGNW9G0",
                "Lnk Spd Cap\/Cur": "Gen3\/Gen3",
                "OUI": "000cca",
                "Type": "Physical",
                "Block Size": "512 Bytes",
                "Max LBA": "23437770751",
                "RAID state": "Configured - drive is online",
                "Device Type": "HDD",
                "RPM": "7200",
                "Recording Technology": "CMR"
            },
            {
                "DUT": "3",
                "Device": "megaraid:0.0.9",
                "Alternate Devices": [
                    "NA"
                ],
                "Port": "SATA",
                "Capacity": "12.0 TB",
                "State": "unretrievable",
                "BootDevice": "No",
                "Serial Number": "5PK2MYDB",
                "Model Number": "HGST HUH721212ALE604",
                "Firmware": "LEGNW9G0",
                "Lnk Spd Cap\/Cur": "Gen3\/Gen3",
                "OUI": "000cca",
                "Type": "Physical",
                "Block Size": "512 Bytes",
                "Max LBA": "23437770751",
                "RAID state": "Configured - drive is online",
                "Device Type": "HDD",
                "RPM": "7200",
                "Recording Technology": "CMR"
            },
            {
                "DUT": "4",
                "Device": "megaraid:0.0.10",
                "Alternate Devices": [
                    "NA"
                ],
                "Port": "SATA",
                "Capacity": "12.0 TB",
                "State": "unretrievable",
                "BootDevice": "No",
                "Serial Number": "5PK2MNGB",
                "Model Number": "HGST HUH721212ALE604",
                "Firmware": "LEGNW9G0",
                "Lnk Spd Cap\/Cur": "Gen3\/Gen3",
                "OUI": "000cca",
                "Type": "Physical",
                "Block Size": "512 Bytes",
                "Max LBA": "23437770751",
                "RAID state": "Configured - drive is online",
                "Device Type": "HDD",
                "RPM": "7200",
                "Recording Technology": "CMR"
            },
            {
                "DUT": "5",
                "Device": "megaraid:0.0.11",
                "Alternate Devices": [
                    "NA"
                ],
                "Port": "SATA",
                "Capacity": "12.0 TB",
                "State": "unretrievable",
                "BootDevice": "No",
                "Serial Number": "5PK23V6B",
                "Model Number": "HGST HUH721212ALE604",
                "Firmware": "LEGNW9G0",
                "Lnk Spd Cap\/Cur": "Gen3\/Gen3",
                "OUI": "000cca",
                "Type": "Physical",
                "Block Size": "512 Bytes",
                "Max LBA": "23437770751",
                "RAID state": "Configured - drive is online",
                "Device Type": "HDD",
                "RPM": "7200",
                "Recording Technology": "CMR"
            }
        ]
    }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.