Server Fault is a question and answer site for system and network administrators. 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

Let's say I know the drive I want is on Adapter 8, Virtual Drive 0, is there a way to get the Linux device name (e.g. /dev/sdt)? I am on RHEL 6.2.

-pdlist displays a WWN value for each physical drive, but that doesn't help much. -ldinfo doesn't print a WWN or any other identifying value.

# ./MegaCli64 -pdlist -a8 | grep WWN
WWN: 500051610003776C
WWN: 5000516100037BFC
WWN: 5000516100038090
WWN: 50005161000284F4
WWN: 5000516100037C0C
WWN: 5000516100037C5C
WWN: 50005161000310C8
WWN: 5000516100037F4C

# ls -1dt /dev/disk/by-id/wwn*
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd142c12c84d
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd142c0973e6
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd132c002573
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd122bf6e2f6
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd122beda52a
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd112be46f10
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd112bdb3ffb
/dev/disk/by-id/wwn-0x600605b0043e52d01721fd102bd20f14

# ./MegaCli64 -v                       
 MegaCLI SAS RAID Management Tool  Ver 8.03.08 Mar 15, 2012
share|improve this question
up vote 7 down vote accepted

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
share|improve this answer
    
I just tried this, but I have IBM drives and for me it looks like there's no correlation between the serial number that shows up in -pdlist and the serial number that shows up lshw. Thanks for the tip though. – twblamer Apr 19 '12 at 16:05
    
It may be that your controller card is not exposing the real serial number and makes a volume serial number for each disk. – Jeff Strunk Apr 19 '12 at 16:09
    
I should add this is a JBOD setup with each drive configured in a RAID0 array of one drive. So I would expect the physical drive's serial number to be hidden, but I'm wondering if I can get some info out of the logical drive config. – twblamer Apr 19 '12 at 16:25
1  
Looks like JBOD is disabled on the adapter by default, but I can enable it: ./MegaCli64 -AdpSetProp -EnableJBOD 1 -a0 – twblamer May 2 '12 at 20:23
1  
To only show disks, use: lshw -class disk – danmaz74 Jun 7 at 10:56

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
share|improve this answer
    
Short and sweet. – Michael R. Hines Jan 5 at 23:34

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

share|improve this answer
    
This works great, even at Centos 6, thanks! – Svenn Dhert Jan 15 at 11:00
1  
Please note that the tool was accepted and merged upstream so a more recent version is at: raw.githubusercontent.com/eLvErDe/hwraid/master/wrapper-scripts/… – Vincent S. Cojot Jan 16 at 15:30

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 ]

share|improve this answer
    
I have added a utility called megablink to the same github repo that will blink the bad drive for the field technician to easily find it. – chicks Jul 27 '14 at 4:13
    
Based on a bug report and subsequent fixes I have released a new version of megamap on github. – chicks Dec 2 '14 at 15:54

Harry's command was very helpful, but I needed to go a step further and determine the pci device because I have multiple SAS adapters in my configuration. Figured I should share:

  vdisk=1

  MegaCommand=/opt/MegaRAID/CmdTool2/CmdTool2

  vendor_id=$($MegaCommand -AdpAllInfo -aALL \
    | grep -E "^Vendor Id" \
    | sed 's/.*: //g' )

  device_id=$($MegaCommand -AdpAllInfo -aALL \
    | grep -E "^Device Id" \
    | sed 's/.*: //g' )

  pci_address=$(lspci -n \
    | grep "$vendor_id" \
    | grep "$device_id" \
    | awk '{print $1}' )

  dev_sdx=$($MegaCommand -LDInfo -LALL -aALL \
    | grep "^Virtual Drive: $vdisk (" \
    | tr -d ")" \
    | sed 's/.*Target Id: //g')

  dev_sdx=$(ls -l /dev/disk/by-path/ \
    | grep -E "$pci_address-scsi-[0-9]:[0-9]:$dev_sdx:[0-9] " \
    | grep sd  \
    | sed 's/.*\///g')

  echo "Found /dev/ as /dev/$dev_sdx"
share|improve this answer

There is an alternate tool called lsiutil that has been discontinued. If it works for your card, it may be easier to use: http://www.lsi.com/downloads/Public/Obsolete/Obsolete%20Common%20Files/LSIUtil_1.62.zip

Once you select your controller card, option 42 is supposed to display the OS names. I use this on Solaris, and the disks are in real JBOD mode instead of a bunch of single disk RAID 0 logical drives.

share|improve this answer
    
I downloaded that zip and it doesn't look like it works for my card+OS, unfortunately. Seems like I might be stuck. – twblamer Apr 19 '12 at 17:07

I was researching for the same thing and found this post - http://sysadm.pp.ua/linux/monitoring-systems/python-lsi-megaraid-monitoring.html . You can use python and bash script which give you all needed info:

root@s11:~# bash megaraid.sh log

-- Array information --
-- ID | Type   |    Size |  Strpsz | Flags | DskCache |   Status |  OS Path | InProgress
c0u0  | RAID-5 |   2725G |   64 KB | RA,WT |  Default | Degraded | /dev/sda | None
-- Disk information --
-- ID   | Type | Drive Model                               | Size     | Status          | Speed    | Temp | Slot ID  | Device ID
c0u0p2  | HDD  | SEAGATE ST1000NM0001 0002Z1N4K2PY         | 930.3 Gb | Failed          | 6.0Gb/s  | 29C  | [4:2]    | 15
share|improve this answer

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.