Linux打开LED定位物理盘

说明:

raid主要有LSI、Adaptec、Highpoint、Promise四家提供,其中前两家提供的最多。LSI现在属于博通公司。不同厂家使用命令工具不同。使用厂家适配的raid卡驱动管理工具,对需要替换的故障硬盘进行亮灯处理。方便现场人员替换硬盘,可以降低误操作的概率。

华为5288V5服务器硬盘指示灯,Linux系统中打开LED灯,下面图片中的Fault黄灯将持续闪烁。

也可以使用Raid管理工具,查看操作系统中磁盘对应物理服务器的实际插槽位。

华为5288V5点亮效果[黄灯闪烁]

1、storcli64硬盘LED亮灯方法

1、storcli64安装
wget https://download.lenovo.com/pccbbs/thinkservers/ul_avago_storcli_1.18.11_anyos.zip
unzip  ul_avago_storcli_1.18.11_anyos.zip
dpkg -i storcli-1.18.11-1.noarch.dep
ln -s /opt/MegaRAID/storcli/storcli64 /usr/bin/storcli64

2、信息获取

storcli64 /c0/e64/sall show all |grep WWN -B6

Drive /c0/e64/s18 Device attributes : #磁盘标示路径
===================================
SN =             ZL2EWLE6  #序列号
Manufacturer Id = ATA     
Model Number = ST16000NM001G-2KK103 #磁盘序列号
NAND Vendor = NA
WWN = 5000c500c92170db  #磁盘wwn号
--
3、磁盘LED亮灯
storcli64 /c0/e64/s9  start locate #亮灯
Controller = 0
Status = Success
Description = Start Drive Locate Succeeded.

storcli64 /c0/e64/s9  stop locate  #关灯
Controller = 0
Status = Success
Description = Stop Drive Locate Succeeded.

4、操作系统盘符对应信息获取
  #上面说明亮怎么获取点灯路径,和点灯方法。当我们需要关闭指定系统盘符,可以使用下面命令获取硬盘序列号或wwn。
  #注意,不同磁盘和不同系统可能获取的信息格式会不一样。
   lsscsi -wg
   												WWN号																盘符
   [0:0:2:0]    disk    0x55cd2e414fd7fdd7                  /dev/sdb   /dev/sg3 
	 
   smartctl -i /dev/sdb
   Serial Number:    BTYF832002EK480BGN #磁盘序列号


5、参考脚本
参考脚本(自动点灯磁盘利用率低于50%的)
#!/bin/bash
#获取硬盘使用率小于50%的盘
echo `hostname -I`
for i in `df -hT |grep "/mnt/disk"|awk '{print $1}'`;do
usage=`df -hT $i |grep "/mnt/disk" |awk '{print $6}'|awk -F "%" '{print $1}'`
if [ $usage -lt '50' ]; then
#获取硬盘序列号
DISK_SN=`smartctl -i $i |grep "Serial Number" |awk '{print $3}'`
#获取盘符号
DISK_PATH=`storcli64 /c0/e64/sall show all |grep $DISK_SN -B2 |grep "Drive"|awk '{print $2}'`
#开灯
storcli64 $DISK_PATH  start locate > /dev/null
echo disk_usage=$usage% disk_path=$i  disk_bus=$DISK_PATH  lamp on
fi
done

2、megacli硬盘LED亮灯方法

1、安装方法
  apt-get install lsscsi -y
  apt-get install alien -y
  wget --user=hetzner --password=download http://download.hetzner.de/tools/LSI/tools/MegaCLI/8.07.14_MegaCLI.zip
  unzip 8.07.14_MegaCLI.zip -d megacli
  cd megacli/Linux
  sudo alien MegaCli-8.07.14-1.noarch.rpm
  sudo dpkg -i megacli_8.07.14-2_all.deb
  ln -s /opt/MegaRAID/MegaCli/MegaCli64 /usr/bin/megacli
2、磁盘信息获取
megacli -PDList -aALL  #查看所有物理盘信息

Enclosure Device ID: 64
Slot Number: 34
Enclosure position: 1
Device Id: 14
WWN: 5000c500c91e907b

Sequence Number: 2
Enclosure Device ID: 64
Slot Number: 35
Enclosure position: 1
Device Id: 21
WWN: 5000c500c90e0818

3、点灯
megacli PdLocate start physdrv[64:34] -a0 

megacli PdLocate stop physdrv[64:34] -a0 
说明:
  [64:34]  
  64 = Enclosure Device ID
  34 = Slot Number

4、操作系统盘符对应信息获取
  #上面说明亮怎么获取点灯路径,和点灯方法。当我们需要关闭指定系统盘符,可以使用下面命令获取硬盘序列号或wwn。
  #注意,不同磁盘和不同系统可能获取的信息格式会不一样。
   lsscsi -wg
   												WWN号																盘符
   [0:0:2:0]    disk    0x55cd2e414fd7fdd7                  /dev/sdb   /dev/sg3 
	 
   smartctl -i /dev/sdb
   Serial Number:    BTYF832002EK480BGN #磁盘序列号

其他方法(未测试):

  • sg_ses硬盘点灯方法(测试失败)
lsscsi -wg 获取磁盘对应关系,根据wwn号确定硬盘位置
																											WWn号
[5:0:22:0]   disk    ATA      ST16000NM001G-2K SN03  0x5000c500c8f3ffca                  /dev/sdn   /dev/sg13
[5:0:11:0]   disk    ATA      ST16000NM001G-2K SN03  0x5000c500c908e0f5                  /dev/sdc   /dev/sg2


megacli -PDList -aALL  #查看所有物理盘信息,获取磁盘sas地址
Enclosure Device ID: 64
Slot Number: 1
Enclosure position: 1
Device Id: 22
WWN: 5000c500c8f3ffca
Sequence Number: 2
Media Error Count: 0
Other Error Count: 0
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0
PD Type: SATA

Raw Size: 14.552 TB [0x746c00000 Sectors]
Non Coerced Size: 14.551 TB [0x746b00000 Sectors]
Coerced Size: 14.551 TB [0x746a52800 Sectors]
Sector Size:  512
Logical Sector Size:  512
Physical Sector Size:  4096
Firmware state: JBOD
Device Firmware Level: SN03
Shield Counter: 0
Successful diagnostics completion on :  N/A
SAS Address(0): 0x500605b000027381 #硬盘插槽1的sas地址

Enclosure Device ID: 64
Slot Number: 2
Enclosure position: 1
Device Id: 11
WWN: 5000c500c908e0f5
Sequence Number: 2
Media Error Count: 0
Other Error Count: 0
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0
PD Type: SATA

Raw Size: 14.552 TB [0x746c00000 Sectors]
Non Coerced Size: 14.551 TB [0x746b00000 Sectors]
Coerced Size: 14.551 TB [0x746a52800 Sectors]
Sector Size:  512
Logical Sector Size:  512
Physical Sector Size:  4096
Firmware state: JBOD
Device Firmware Level: SN03
Shield Counter: 0
Successful diagnostics completion on :  N/A
SAS Address(0): 0x500605b000027382 #硬盘插槽2的sas地址




#获取亮灯状态
--dev-slot-num=1 #插槽号也能识别硬盘位置
root@Worker-10-12-212-68:~/disk_bus_test# sg_ses --sas-addr=0x500605b000027381  --get=ident /dev/sg37
0
root@Worker-10-12-212-68:~/disk_bus_test# sg_ses --sas-addr=0x500605b000027382  --get=ident /dev/sg37
0
#硬盘亮灯
root@Worker-10-12-212-68:~/disk_bus_test# sg_ses --sas-addr=0x500605b000027381 --set=ident /dev/sg37
root@Worker-10-12-212-68:~/disk_bus_test# sg_ses --sas-addr=0x500605b000027382 --set=locate /dev/sg37

[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --get=ident /dev/sg12
1
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --clear=ident /dev/sg12
[root@idc-pxe009 ~]# sg_ses --dev-slot-num=1 --get=ident /dev/sg12
0
  • 确定磁盘插槽号
lsscsi -wg 获取磁盘对应关系,根据wwn号确定硬盘位置
																											WWn号
[5:0:22:0]   disk    ATA      ST16000NM001G-2K SN03  0x5000c500c8f3ffca                  /dev/sdn   /dev/sg13
[5:0:11:0]   disk    ATA      ST16000NM001G-2K SN03  0x5000c500c908e0f5                  /dev/sdc   /dev/sg2


megacli -PDList -aALL  #查看所有物理盘信息,获取磁盘sas地址
Enclosure Device ID: 64
Slot Number: 1 #插槽号
Enclosure position: 1
Device Id: 22
WWN: 5000c500c8f3ffca
Sequence Number: 2
Media Error Count: 0
Other Error Count: 0
Predictive Failure Count: 0
Last Predictive Failure Event Seq Number: 0
PD Type: SATA
  • sas3ircu点灯方法
https://www.broadcom.com/products/storage/host-bus-adapters/sas-9300-8i#downloads #下载地址
wget https://docs.broadcom.com/docs-and-downloads/host-bus-adapters/host-bus-adapters-common-files/sas_sata_12g_p16/Linux_Driver-RHEL5-6_SLES10-11_GEN35_PHASE_7.0.zip
wget https://docs.broadcom.com/docs-and-downloads/host-bus-adapters/host-bus-adapters-common-files/sas_sata_12g_p7/SAS3IRCU_P7.zip