背景:当设备支持2个及两个以上硬盘插槽时(这里举例有两个硬盘插槽C0和C1),用户无法判断哪个硬盘插槽是hda,哪个是hdb,因为内核检测机制是哪个硬盘先被扫描到,哪个就认为是hda。通过修改hotplug脚本,可以实现固定硬盘插槽,比如C0对应hda,C1对应hdb。
脚本实例:
#一个是disk,表示设备本身,对应的$DEVPATH $MAJOR $MINOR分别是/block/hda0: 8 0
#一个是partition,表示设备上的分区,对应的$DEVPATH $MAJOR $MINOR分别是 /block/sda/hda0: 8 1
#硬盘插入:
if [ $ACTION == "add" ];then
if ( echo $DEVPATH | grep "/block/sd" > /dev/null 2>&1 ) && [ $DEVTYPE == "partition" ]; then
for i in a b c d e f
do
if ( echo $DEVPATH | grep "/block/sd""$i""" > /dev/null 2>&1 ) then
if ( readlink -f /sys/block/sd"$i"/device/ | grep "host0" > /dev/null 2>&1) then
DEVPATH="/block/sda/hda0:"
/sbin/hotplug_inner
echo "notice!!!! $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.log
break
elif ( readlink -f /sys/block/sd"$i"/device/ | grep "host1" > /dev/null 2>&1 ) then
DEVPATH="/block/sdb/hdb0:"
/sbin/hotplug_inner
echo "notice!!!! action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.log
break
fi
fi
done
elif ( echo $DEVPATH | grep "/block/hd" > /dev/null 2>&1 ) && [ $DEVTYPE == "disk" ]; then
for i in a b c d e f
do
if ( echo $DEVPATH | grep "/block/hd""$i""" > /dev/null 2>&1 ) then
if ( readlink -f /sys/block/sd"$i"/device/ | grep "host0" > /dev/null 2>&1) then
DEVPATH="/block/hda0:"
/sbin/hotplug_inner
echo "notice!!!! action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.log
break
elif ( readlink -f /sys/block/sd"$i"/device/ | grep "host1" > /dev/null 2>&1) then
DEVPATH="/block/hdb0:"
/sbin/hotplug_inner
echo "notice!!!! action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.log
break
fi
fi
done
fi
fi
#硬盘拔出
if [ $ACTION == "remove" ];then
if ( echo $DEVPATH | grep "/block/sd" > /dev/null 2>&1 ) && [ $DEVTYPE == "partition" ]; then
for i in a b
do
p=$(ls -l /dev/hd"$i"0: | awk '{print $5}' | sed 's/,//g')
q=$(ls -l /dev/hd"$i"0: | awk '{print $6}')
if [[ $MAJOR == $p && $MINOR == $q ]]; then
DEVPATH="/block/sd"$i"/hd"$i"0:"
#/sbin/hotplug_inner
echo "notice!!!! p=$p q=$q action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.log
break
fi
done
elif ( echo $DEVPATH | grep "/block/hd" > /dev/null 2>&1 ) && [ $DEVTYPE == "disk" ]; then
for i in a b
do
#输出结果的第5列内容,并将逗号去掉(注意print $x ,x从1开始数)
p=$(ls -l /dev/hd"$i": | awk '{print $5}' | sed 's/,//g')
#输出结果的第6列内容
q=$(ls -l /dev/hd"$i": | awk '{print $6}')
if [[ $MAJOR == $p && $MINOR == $q ]]; then
DEVPATH="/block/hd"$i"0:"
#/sbin/hotplug_inner
echo "notice!!!! p=$p q=$q action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.log
break
fi
done
fi
fi