欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

支持固定硬盘插槽脚本实例

时间:2023-05-18

背景:当设备支持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" ];thenif ( echo $DEVPATH | grep "/block/sd" > /dev/null 2>&1 ) && [ $DEVTYPE == "partition" ]; thenfor i in a b c d e fdoif ( echo $DEVPATH | grep "/block/sd""$i""" > /dev/null 2>&1 ) thenif ( readlink -f /sys/block/sd"$i"/device/ | grep "host0" > /dev/null 2>&1) thenDEVPATH="/block/sda/hda0:"/sbin/hotplug_innerecho "notice!!!! $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.logbreakelif ( readlink -f /sys/block/sd"$i"/device/ | grep "host1" > /dev/null 2>&1 ) thenDEVPATH="/block/sda/hdb0:"/sbin/hotplug_innerecho "notice!!!! action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.logbreakfifidoneelif ( echo $DEVPATH | grep "/block/hd" > /dev/null 2>&1 ) && [ $DEVTYPE == "disk" ]; thenfor i in a b c d e fdoif ( echo $DEVPATH | grep "/block/hd""$i""" > /dev/null 2>&1 ) thenif ( readlink -f /sys/block/sd"$i"/device/ | grep "host0" > /dev/null 2>&1) thenDEVPATH="/block/hda0:"/sbin/hotplug_innerecho "notice!!!! action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.logbreakelif ( readlink -f /sys/block/sd"$i"/device/ | grep "host1" > /dev/null 2>&1) thenDEVPATH="/block/hdb0:"/sbin/hotplug_innerecho "notice!!!! action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.logbreakfifidonefifi#硬盘拔出if [ $ACTION == "remove" ];thenif ( echo $DEVPATH | grep "/block/sd" > /dev/null 2>&1 ) && [ $DEVTYPE == "partition" ]; thenfor i in a b dop=$(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 ]]; thenDEVPATH="/block/sd"$i"/hd"$i"0:"#/sbin/hotplug_innerecho "notice!!!! p=$p q=$q action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.logbreakfidoneelif ( echo $DEVPATH | grep "/block/hd" > /dev/null 2>&1 ) && [ $DEVTYPE == "disk" ]; thenfor 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 ]]; thenDEVPATH="/block/hd"$i"0:"#/sbin/hotplug_innerecho "notice!!!! p=$p q=$q action=$ACTION $DEVTYPE $DEVPATH $MAJOR $MINOR not process" >> /var/log/hotplug.logbreakfidonefifi

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。