删盘重新扫描设备
背景
业务场景需要,服务器硬盘通道采用jbod模式,经常插拔盘,插盘触发udev挂载脚本,自动挂载路径
问题
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk /opt/datadisk/10006-1B-B1T-1
sdb 8:16 0 1.8T 0 disk /opt/datadisk/10006-1A-B2T-1
sdc 8:32 0 3.7T 0 disk /opt/datadisk/10062-2A-B4T-1
sdg 8:96 0 1.8T 0 disk /opt/datadisk/10006-2A-B2T-2
sdh 8:112 0 931.5G 0 disk /opt/datadisk/10006-2B-B1T-2
sdi 8:128 0 894.3G 0 disk
sdk 8:160 0 464.7G 0 disk
sdl 8:176 0 931.5G 0 disk /opt/datadisk/10062-1B-B1T-1
sdm 8:192 0 931.5G 0 disk /opt/datadisk/10062-2B-B1T-2
sdn 8:208 0 1.8T 0 disk /opt/datadisk/10062-1A-B2T-1
sdo 8:224 0 931.5G 0 disk /opt/datadisk/10061-SL-B1T-1
sdi 没有挂载
步骤
- 确认盘的接口位置
# udevadm info --query=path -n /dev/sdi
/devices/pci0000:00/0000:00:01.0/0000:01:00.0/host0/target0:0:12/0:0:12:0/block/sdi
确认sdi的接口是host0的target12
H:C:T:L是0:0:12:0
- 从scsi层删除设备映射
# echo 1| sudo tee /sys/class/block/sdi/device/delete
- 重新扫描设备
# echo "- - -" |sudo tee /sys/class/scsi_host/host0/scan
"- - -"代表channel,target和LUN编号
或者
echo 1 | sudo tee /sys/class/scsi_device/0:0:12:0/device/rescan
- 查看新设备
# lsblk -f
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk /opt/datadisk/10006-1B-B1T-1
sdb 8:16 0 1.8T 0 disk /opt/datadisk/10006-1A-B2T-1
sdc 8:32 0 3.7T 0 disk /opt/datadisk/10062-2A-B4T-1
sdg 8:96 0 1.8T 0 disk /opt/datadisk/10006-2A-B2T-2
sdh 8:112 0 931.5G 0 disk /opt/datadisk/10006-2B-B1T-2
sdk 8:160 0 464.7G 0 disk
├─sdk1 8:161 0 10M 0 part
├─sdk2 8:162 0 1G 0 part /boot
├─sdk3 8:163 0 128G 0 part /
└─sdk4 8:164 0 335.7G 0 part
sdl 8:176 0 931.5G 0 disk /opt/datadisk/10062-1B-B1T-1
sdm 8:192 0 931.5G 0 disk /opt/datadisk/10062-2B-B1T-2
sdn 8:208 0 1.8T 0 disk /opt/datadisk/10062-1A-B2T-1
sdo 8:224 0 931.5G 0 disk /opt/datadisk/10061-SL-B1T-1
sdp 8:240 0 894.3G 0 disk /opt/datadisk/10009-X86-B1T-1
sdp就是新的设备