前言
首先还是做好标记最靠谱!我这次要处理的是一个6年前的设置的服务器存储集群,当时没有给硬盘盒加标签导致现在处理起来很麻烦。
解决方案
首先在系统中确定要更换硬盘的序列号:
ls -lh /dev/disk/by-id/ ...... lrwxrwxrwx 1 root root 9 Aug 2 16:17 ata-WUH721816ALE6L4_2CKNWULJ -> ../../sdd ......
这里我要更换的是ata-WUH721816ALE6L4_2CKNWULJ
,对应的设备为sdd
。
然后找到对应的sg设备位置为/dev/sg3
:
lsscsi -g | grep sdd [0:0:3:0] disk ATA WUH721816ALE6L4 W232 /dev/sdd /dev/sg3
之后使用下面给出的脚本./blink_disk.sh /dev/sdX 5 1.5
来让硬盘指示灯闪烁:
#!/bin/bash # Function to display usage information usage() { echo "Usage: $0 /dev/sdX BLINK_COUNT INTERVAL" echo " /dev/sdX : The disk device to blink (e.g., /dev/sda)" echo " BLINK_COUNT : Number of times to blink the disk" echo " INTERVAL : Time in seconds between each blink" exit 1 } # Check if the correct number of arguments is provided if [ "$#" -ne 3 ]; then usage fi DEVICE=$1 BLINK_COUNT=$2 INTERVAL=$3 # Validate BLINK_COUNT is a positive integer if ! [[ "$BLINK_COUNT" =~ ^[0-9]+$ ]] || [ "$BLINK_COUNT" -le 0 ]; then echo "Error: BLINK_COUNT must be a positive integer." usage fi # Validate INTERVAL is a positive number if ! [[ "$INTERVAL" =~ ^[0-9]+(\.[0-9]+)?$ ]] || (( $(echo "$INTERVAL <= 0" | bc -l) )); then echo "Error: INTERVAL must be a positive number." usage fi # Check if sg_start is installed if ! command -v sg_start &> /dev/null; then echo "sg_start could not be found, please install sg3_utils." exit 1 fi # Blink the drive for ((i=1; i<=BLINK_COUNT; i++)); do echo "Blinking drive $DEVICE ($i/$BLINK_COUNT)..." sg_start --stop --imm $DEVICE sleep $INTERVAL sg_start --start --imm $DEVICE sleep $INTERVAL done echo "Completed blinking the drive $DEVICE."