- 论坛徽章:
- 0
|
在linux下面, 如果在某个NFS目录下有打开的文件, 使用umount的时候
就会得到device busy的错误, 而linux下的umount -f又不起作用,
这个脚本就是用来force umount一个分区的:
使用方法很简单:
./force_umount.sh mount_point
例如:
#force_umount.sh /nfs/file
#!/bin/sh
#force_umount.sh
#force umount a mount poing, if umount -f takes no effect.
usage () {
echo "$0 umount_path"
exit 1
}
#Only root can execute this scripts.
[ `whoami` != "root" ] && echo "Only root can execute this script" && exit 1
#Check parameters
[ $# != 1 ] && usage
#Check if $1 exsits
[ ! -r $1 ] && echo "Don't have read permission!" && exit 1
#if SunOS, we can simply use the -f switch
#But in Linux system, -f switch seems no use, you have to kill all the process
#related to the mount point
#trouble.
if [ `uname` = "SunOS" ]; then
echo "Under SunOS platform, we can simply use the -f switch"
umount -f $1
exit 0
fi
#Check if lsof executable, under Linux platform
echo "Under Linux platform, we have to do a lot of things"
echo "Check if lsof executeable"
LSOF="/usr/sbin/lsof"
while true; do
if [ ! -x $LSOF ]; then
echo -n "$LSOF not executable, enter the path to it:"
read LSOF
else
break
fi
done
echo "Good"
#Check all opened file handlers
echo "Kill all opened file handlers"
$LSOF | grep $1 | while read LINE
do
echo $LINE
PID=`echo $LINE | awk '{ print $2 }'`
kill -9 $PID
done
#umount
echo "umount $1"
umount $1 |
|