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:
In this case, BUS=2. Then look through the PCI table for devices on that BUS, and look for the 'hostX' entry:
So, HOST=host0.
Now look for the target in that host directory
Our SCSI target ID is 0:2:0 (host 0:channel 2:target 0).
Match SCSI target with the output of lsscsi
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.