MegaCli: Get the /dev/sd* device name for a logical drive

Solution 1:

You should be able to compare the disk serial number from -pdlist with the output from lshw.

# MegaCLI -pdlist -a0 | grep "Inquiry Data:"
Inquiry Data:       XXXXXXXXXXXXHitachi YYYYYYYY                 ZZZZZZ
...

Then search the output of lshw for the serial number. The device name will be in the logical name field.

I can't verify this because all of my disks are in a volume.

Identifying Logical Drives

Compare the Target Id from MegaCLI with the scsi bus target for the device. In lshw it is bus info.

# MegaCli -ldinfo -Lall -aall 


Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name                :
RAID Level          : Primary-6, Secondary-0, RAID Level Qualifier-3
Size                : 7.275 TB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives    : 6
Span Depth          : 1
Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disabled
Ongoing Progresses:
  Check Consistency        : Completed 17%, Taken 89 min.
Encryption Type     : None


Virtual Drive: 1 (Target Id: 1)
Name                :
RAID Level          : Primary-6, Secondary-0, RAID Level Qualifier-3
Size                : 7.275 TB
State               : Optimal
Strip Size          : 64 KB
Number Of Drives    : 6
Span Depth          : 1
Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Access Policy       : Read/Write
Disk Cache Policy   : Disabled
Ongoing Progresses:
  Check Consistency        : Completed 17%, Taken 89 min.
Encryption Type     : None

From lshw:

# lshw -class disk
...
              *-enclosure UNCLAIMED
               description: SCSI Enclosure
               product: Bobcat
               vendor: LSI CORP
               physical id: 1.75.0
               bus info: scsi@0:1.117.0
               version: 0504
               configuration: ansiversion=5
          *-disk:0
               description: SCSI Disk
               product: MR9260-16i
               vendor: LSI
               physical id: 2.0.0
               bus info: scsi@0:2.0.0
               logical name: /dev/sda
               version: 2.12
               serial: svDASJ-f8kM-4qp5-BswW-3IKC-DDyA-djz8N7
               size: 7450GiB
               capacity: 7450GiB
               capabilities: lvm2
               configuration: ansiversion=5
          *-disk:1
               description: SCSI Disk
               product: MR9260-16i
               vendor: LSI
               physical id: 2.1.0
               bus info: scsi@0:2.1.0
               logical name: /dev/sdb
               version: 2.12
               serial: NHUvUy-1tm4-aGYW-g6DZ-t1Z9-gxW8-JhvFfL
               size: 7450GiB
               capacity: 7450GiB
               capabilities: lvm2
               configuration: ansiversion=5

Solution 2:

I just added some support to my fork of megaclisas-status for matching the logical drive to an OS Native device. Here's an example output:

$ sudo ./megaclisas-status
-- Controller information --
-- ID | H/W Model                  | RAM    | Temp | Firmware     
c0    | LSI MegaRAID SAS 9271-8i   | 1024MB | 88C  | FW: 23.32.0-0009 
c1    | LSI MegaRAID SAS 9280-4i4e | 512MB  | N/A  | FW: 12.15.0-0205 

-- Array information --
-- ID | Type   |    Size |  Strpsz |   Flags | DskCache |  Status |  OS Path | InProgress   
c0u0  | RAID-1 |   1817G |  256 KB | ADRA,WT |  Enabled | Optimal | /dev/sda | None         
c0u1  | RAID-5 |  16370G |  512 KB | ADRA,WB |  Enabled | Optimal | /dev/sdb | None         
c1u0  | RAID-0 |    476G |  256 KB | ADRA,WT |  Enabled | Optimal | /dev/sdc | None         

-- Disk information --
-- ID   | Type | Drive Model                                  | Size     | Status          | Speed    | Temp | Slot ID  | LSI Device ID
c0u0p0  | HDD  | WD-WMC300422505WDC WD20EFRX-68AX9N0 80.00A80 | 1.817 TB | Online, Spun Up | 6.0Gb/s  | 31C  | [252:4]  | 17      
c0u0p1  | HDD  | WD-WMC300421817WDC WD20EFRX-68AX9N0 80.00A80 | 1.817 TB | Online, Spun Up | 6.0Gb/s  | 31C  | [252:5]  | 18      
c0u1p0  | HDD  | WD-WX41DA40LCE5WDC WD60EFRX-68MYMN1 82.00A82 | 5.456 TB | Online, Spun Up | 6.0Gb/s  | 32C  | [252:0]  | 15      
c0u1p1  | HDD  | WD-WX41DA40L42RWDC WD60EFRX-68MYMN1 82.00A82 | 5.456 TB | Online, Spun Up | 6.0Gb/s  | 31C  | [252:1]  | 12      
c0u1p2  | HDD  | WD-WX61DA4HAKFZWDC WD60EFRX-68MYMN1 82.00A82 | 5.456 TB | Online, Spun Up | 6.0Gb/s  | 32C  | [252:6]  | 14      
c0u1p3  | HDD  | WD-WX41DA40LEF1WDC WD60EFRX-68MYMN1 82.00A82 | 5.456 TB | Online, Spun Up | 6.0Gb/s  | 31C  | [252:7]  | 16      
c1u0p0  | SSD  | 0000000011310344CFE3M4-CT512M4SSD2 070H      | 476.4 Gb | Online, Spun Up | 6.0Gb/s  | N/A  | [252:1]  | 11      

-- Unconfigured Disk information --

The tool itself is available at: http://step.polymtl.ca/~coyote/dist/megaclisas-status/megaclisas-status

I hope this helps,

Vincent


Solution 3:

For anyone stumbling on this question and using storcli (successor of MegaCLI), you can map a virtual drive to the disk seen by the operating system with the following:

$ /opt/MegaRAID/storcli/storcli64 /c0/v0 show all | grep NAA
SCSI NAA Id = 6001676001750006201086de0bd7f605
$ ls -al /dev/disk/by-id/ | grep wwn-0x6001676001750006201086de0bd7f605
lrwxrwxrwx 1 root root   9 Jan 23 10:55 wwn-0x6001676001750006201086de0bd7f605 -> ../../sdk

Tested with storcli-1.21.06 download at: https://docs.broadcom.com/docs/1.21.06_StorCLI


Solution 4:

Instead of using lshw, I think you can just use /dev/disk/by-path to get the relationship between the scsi target id and the logical device name(sdX).

targetId=0;dev=`ls -l /dev/disk/by-path/ | grep -E "scsi-[0-9]:[0-9]:${targetId}:[0-9] " | awk '{print($11)}'`; echo ${dev##*\/}

  deviceId=$1
  ldPdInfo=`$MegaCommand -LdPdInfo -aALL | grep -E 'Virtual Drive|Device Id'`
  if [ $ldPdInfo ]; then
    targetId=`echo $ldPdInfo | awk '{a[NR]=$0} END {while (NR) print a[NR--]}' | awk "/Device Id: ${deviceId}$/,/Virtual Drive/" | grep -Eo 'Target Id: [0-9]' | grep -Eo '[0-9]'`
    dev=`ls -l /dev/disk/by-path/ | grep -E "scsi-[0-9]:[0-9]:${targetId}:[0-9] " | awk '{print($11)}'`
  else
    wwn=`$MegaCommand -PdList -aALL | awk "/Device Id: ${deviceId}$/,/WWN/" | grep "WWN" | awk '{print($2)}'`
    # wwn=`echo "obase=16;ibase=16; $wwn-1" | bc`
    dev=`ls -l /dev/disk/by-id/ | grep -i -E "wwn-0x${wwn:0:-1}[0-9a-z] " | awk '{print($11)}'`
  fi
  devName=${dev##*\/}
  echo $devName

Solution 5:

I have been dealing with this across a number of new servers recently and I've come up with a solution! We are not using RAID on the "RAID" card, just using the SAS drives as JBOD. The /dev/disk/by-id mappings are off by one (or a few) from the SAS Address. This seems bizarre, but it works across dozens of servers I've tested it on. I have also received independent confirmation that this works for others.

megamap is a short Perl script that implements the discovery above. It produces a map of Linux drive sd* to MegaRaid drive ID and also displays the WWN from Linux. After using this in production for a while I also added megablink and megaunblink for controlling the "come fix me" blinking LED. That feature has saved me from pulling the wrong drive out of the server. Please submit bug reports on github.

logo [ image thanks to Scott Vrable ]

Tags:

Linux

Megaraid