標題: how to force umount a partition on Linux platform [打印本頁] 作者: passion 時間: 2005-09-19 11:27 標題: how to force umount a partition on Linux platform 在linux下面, 如果在某個NFS目錄下有打開的文件, 使用umount的時候
就會得到device busy的錯誤, 而linux下的umount -f又不起作用,
這個腳本就是用來force umount一個分區(qū)的:
使用方法很簡單:
./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作者: twf_cc 時間: 2005-09-19 13:20 標題: how to force umount a partition on Linux platform 不錯! 作者: twf_cc 時間: 2005-09-19 22:06 標題: how to force umount a partition on Linux platform 但為什麼寫個無盡 loop 來 test $LOSF 呢?
可否這樣?
LSOF="/usr/sbin/lsof"
[ ! -x "$LSOF" ] || {
echo -n "$LSOF not executable, enter the path to it:"
read LSOF ;
}作者: r2007 時間: 2005-09-19 22:12 標題: how to force umount a partition on Linux platform 要是又輸錯了呢?
loop有它的作用。作者: twf_cc 時間: 2005-09-19 22:15 標題: how to force umount a partition on Linux platform 也說的是,這個沒想到 , 哈哈。作者: 大螞蟻 時間: 2005-09-19 22:16 標題: how to force umount a partition on Linux platform 先用 fuser -k yourdir
然后 umount yourdir