We can use smartctl to get the disk serial ID in case of disk replacement or crashes, with the following:
smartctl -a /dev/sdX
Where X is the device identifier like, for the first disk, this would be sda, second sdb etc. But in case the devices are behind the RAID, this command returns an error:
[[email protected] ~]# smartctl -a /dev/sda smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-1127.el7.x86_64] (local build) Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org Smartctl open device: /dev/sda failed: DELL or MegaRaid controller, please try adding '-d megaraid,N'
How to make this work?
To get the serial numbers behind the LSI MegaRAID, you would first need to find out the device ID using LSI Megaraid tools. A quick way to install LSI Megaraid tool is available here:
One you have installed the LSI Megaraid command line tools, now you may use the following command to identify your device:
/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll | egrep 'Slot\ Number|Device\ Id|Inquiry\ Data|Raw|Firmware\ state' | sed 's/Slot/\nSlot/g'
This would output something like the following:
Slot Number: 1 Device Id: 11 Raw Size: 447.130 GB [0x37e436b0 Sectors] Firmware state: Online, Spun Up Inquiry Data: 50026B72822A7D3A KINGSTON SEDC500R480G SCEKJ2.3
In this server, it has one disk, but you may have multiple disk with different ‘Firemware state’ and ‘Device Id’. To use smartmontools, you need to pick the ‘Device Id’, mentioned here, which is 11. Now you can run the following command to get the device details using smartctl:
smartctl -d megaraid,N -a /dev/sdX
Here, N is the device ID, and X is the device name, you may get the device name using df -h command or fdisk -l. For our case, this command would be like the following:
smartctl -d megaraid,11 -a /dev/sda
This would print a lot of information about your device, but if you are looking to identify the Serial Number only, you may run the following:
~ smartctl -d megaraid,11 -a /dev/sda|grep Serial Serial Number: 50026B72822A7D3A
One thing to note, we can also get Serial number from the MegaCli tools Inquiry data, you may have already noticed:
[[email protected] ~]# /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll | grep 'Inquiry Data' Inquiry Data: 50026B72822A7D3A KINGSTON SEDC500R480G SCEKJ2.3
Here, the first parameter in the return is the same as smartctl returns as Serial number, it’s because it’s the serial number that megacli gets/identifies as well.