#!/bin/sh
if [ $# -ne 1 ];then
echo "USAGE: esata_removal hdd"
exit;
else
if [ `echo $1 | awk '{ if($1~/^sd/) {print length($0)} else {print "0"}}'` -ne 3 ];then
echo "USAGE: esata_removal sdX"
else
if [ `cat /proc/partitions |grep $1|wc -l` -eq 0 ];then
echo -e "Invalid Drive: Unable to find target drive on system."
fi
if [ `mount|awk '($1~"^/dev/'""$1""'" && $3=="/boot"){print $0}'|wc -l` -eq 1 ];then
echo "System Drive is not allowed to be removed."
exit;
fi
fi
fi
function check_mount(){
IFS=$'\n'
mount_map=`mount|awk '($1~"^/dev/'""$1""'"){print $0}'`
OUT=0
for i in $mount_map; do
echo $i|awk '{print $3" need to be unmounted from system before performing esata hot swap"}'
OUT=1
done
if [ $OUT -eq 1 ];then
exit
fi
}
function bus_id_lookup(){
bus_id=`dmesg |grep $1|grep scsi|tail -n 1|awk '{print $6 $8 $10 $12}'|sed 's/,/ /g'|sed 's/scsi//g'`
}
check_mount $1
bus_id_lookup $1
echo 1 > /sys/block/$1/device/delete
echo "scsi remove-single-device $bus_id" > /proc/scsi/scsi
echo Disk $1 can be removed from bus $bus_id
沒有留言:
張貼留言