服务器下的硬盘主有机械硬盘、固态硬盘以及raid阵列,通常内核分配盘符的顺序是/dev/sda、/dev/sdb… …。在系统启动过程中,内核会按照扫描到硬盘的顺序分配盘符(先分配直通的,再分配阵列)。在同一个硬盘槽位,热插拔硬盘,系统会顺着已存在的盘符分配下去,如之前分配的是/dev/sdb,系统最后一块硬盘是/dev/sdf,那么/dev/sdb/热拔插后,系统会重新分配这块硬盘的盘符为/dev/sdg,出现盘符错乱的情况。
假设机器上有14个硬盘槽位,槽位号分别为0~13,在Centos7.3环境下,R730XD服务器分配槽位如下:
0 | 3 | 6 |
1 | 4 | 7 |
2 | 5 | 8 |
/dev/sda | /dev/sdd | /dev/sdg |
/dev/sdb | /dev/sde | /dev/sdh |
/dev/sdc | /dev/sdf | /dev/sdi |
在此种情况下,我们应该可以用以下方法解决盘符错位的问题:
[root@localhost ~]# udevadm info -q path -n /dev/sda
/devices/pci0000:00/0000:00:1f.2/ata5/host5/target5:0:0/5:0:0:0/block/sda
按此方法分别获取sdb sdc sdd, 然后自定义规则:
[root@localhost rules.d]# pwd /usr/lib/udev/rules.d
[root@localhost rules.d]# vi 100-define.rules
# define by self ACTION=="remove", GOTO="drivers_end" ENV{MODALIAS}=="?*", RUN{builtin}+="kmod load $env{MODALIAS}" SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="SD", RUN{builtin}+="kmod load tifm_sd" SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="MS", RUN{builtin}+="kmod load tifm_ms" SUBSYSTEM=="memstick", RUN{builtin}+="kmod load ms_block mspro_block" SUBSYSTEM=="i2o", RUN{builtin}+="kmod load i2o_block" SUBSYSTEM=="module", KERNEL=="parport_pc", RUN{builtin}+="kmod load ppdev" KERNEL=="mtd*ro", ENV{MTD_FTL}=="smartmedia", RUN{builtin}+="kmod load sm_ftl" DEVPATH=="/devices/pci0000:00/0000:00:1f.2/ata5/host5/target5:0:0/5:0:0:0/block/sda", NAME="sda", MODE="0660" DEVPATH=="/devices/pci0000:00/0000:00:01.0/0000:01:00.0/host0/target0:2:0/0:2:0:0/block/sdb", NAME="sdb", MODE="0660" DEVPATH=="/devices/pci0000:00/0000:00:01.0/0000:01:00.0/host0/target0:2:1/0:2:1:0/block/sdc", NAME="sdc", MODE="0660" DEVPATH=="/devices/pci0000:00/0000:00:01.0/0000:01:00.0/host0/target0:2:2/0:2:2:0/block/sdd", NAME="sdd", MODE="0660" LABEL="drivers_end" [root@localhost rules.d]#
这样对应的插槽的第二个就会一直对应盘符sdc 而不会出现跳盘符的问题了。
我们可以用个小脚本实现绑定所有的盘符和槽位
#!/bin/bash disk="a b c d e f g h i j k l i j k m n" for i in ${disk}; do a=`/usr/sbin/udevadm info -q path -n /dev/sd${i}`; if [ ! -n "$a" ]; then break 1 ; else echo DEVPATH=="\"${a}"\", NAME="\"sd${i}"\", MODE="\"0660"\">>/etc/udev/rules.d/80-mydisk.rules; fi done