1、找到所有NVME设备的总线地址
1 2 3 4 5 6 7 |
# find /sys/devices |egrep 'nvme[0-9][0-9]?$' /sys/devices/pci0000:80/0000:80:03.3/0000:87:00.0/nvme/nvme3 /sys/devices/pci0000:80/0000:80:03.1/0000:85:00.0/nvme/nvme1 /sys/devices/pci0000:80/0000:80:03.2/0000:86:00.0/nvme/nvme2 /sys/devices/pci0000:80/0000:80:03.0/0000:84:00.0/nvme/nvme0 |
如上0000:87:00.0所示
2、根据总线地址获取PCI槽位号
1 2 3 4 |
# grep -r '0000:87:00' /sys/bus/pci/slots/* /sys/bus/pci/slots/26/address:0000:87:00 |
如上26就是slots号
3、关闭NVME设备电源
1 2 3 |
# echo 0 > /sys/bus/pci/slots/26/power |
综上,可以通过脚本来获取所有设备的PCI slot:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
bus_nvme_list=$(find /sys/devices |egrep 'nvme[0-9][0-9]?$' | awk -F'/' '{print $6" "$8";"}') pci_slot_list=$(find /sys/bus/pci/slots -name "address") total=$(echo $bus_nvme_list | awk -F';' '{print NF}') for index in `seq 1 $total` do bus_nvme=$(echo $bus_nvme_list | awk -F';' -v line=$index 'i=line{print $i}') bus=$(echo $bus_nvme | awk '{print $1}' | awk -F'.' '{print $1}') for pci_slot in $pci_slot_list do grep "$bus" "$pci_slot" > /dev/null if [ $? -eq 0 ];then echo "$pci_slot" "$bus_nvme" break fi done done |
正常卸载肯定是不会使用这种粗暴的方法,此处模拟设备故障,所以非暴力不可。常规的操作流程,可以参考oracle server的这篇文章:
https://docs.oracle.com/cd/E72435_01/html/E72445/grcmp.html
附录:
另外一种删除sata物理盘的手段:
echo 1 >/sys/block/sdX/device/delete