Smartctl & megaraid: how to find the right device node for an adapter #

megaclimegaraidsmartsmartctl

I can list physical drives on all megaraid adapters using:

megacli -PDList -aALL 

This will display an adapter # for each adapter, and then list the physical drives attached to them.

The individual devices in the PDList output also have a Device Id which is used for the smartctl command e.g. for device id 3:

smartctl -a -d sat+megaraid,3 /dev/sda

Both commands use the same device id, so no problem there. But how can we properly map the adapter # to a device node?

Running smartmontools-5.43-1.el6 on CentOS 6. Looking at the source code it seems it needs a bus number / host_no obtained from ioctl SG_GET_SCSI_ID or SCSI_IOCTL_GET_BUS_NUMBER on the named device node. Is this the same number used as "Adapter #" in MegaCLI output?

Actually in my case I could probably get away with hardcoding it to /dev/sda, but I'd like to know if there's a better way.

Best Answer

This is how I've done it before. There might be better ways.

Get the PCI bus ID for the adapter from MegaCLI:

/opt/MegaRAID/MegaCli/MegaCli64 -adpgetpciinfo -a0 | grep Bus
Bus Number      : 2

In this case, BUS=2. Then look through the PCI table for devices on that BUS, and look for the 'hostX' entry:

ls /sys/bus/pci/devices/0000\:0${BUS}\:00.0/ | grep host
host0

So, HOST=host0.
Now look for the target in that host directory

ls /sys/bus/pci/devices/0000\:0${BUS}\:00.0/${HOST}/ | grep target
target0:2:0

Our SCSI target ID is 0:2:0 (host 0:channel 2:target 0).

Match SCSI target with the output of lsscsi

# lsscsi 
[0:2:0:0]    disk    LSI      MR9271-8i        3.24  /dev/sda 
[1:2:0:0]    disk    LSI      MR9271-8i        3.24  /dev/sdb 
[2:0:0:0]    disk    ATA      INTEL SSDSC2BA80 5DV1  /dev/sdc

MegaCLI adapter a0 corresponds to /dev/sda (0:2:0 is ~= 0:2:0:0 in this case. The final 0 is the LUN ID)

If I follow the same method for adapter a1 I get a bus number of 3, host1, and a target value of 1:2:0, which maps to /dev/sdb.