免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2642 | 回复: 5
打印 上一主题 下一主题

how to force umount a partition on Linux platform [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-19 11:27 |只看该作者 |倒序浏览
在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

论坛徽章:
0
2 [报告]
发表于 2005-09-19 13:20 |只看该作者

how to force umount a partition on Linux platform

不錯!

论坛徽章:
0
3 [报告]
发表于 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 ;
}

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
4 [报告]
发表于 2005-09-19 22:12 |只看该作者

how to force umount a partition on Linux platform

要是又输错了呢?
loop有它的作用。

论坛徽章:
0
5 [报告]
发表于 2005-09-19 22:15 |只看该作者

how to force umount a partition on Linux platform

也說的是,這個沒想到 , 哈哈。

论坛徽章:
0
6 [报告]
发表于 2005-09-19 22:16 |只看该作者

how to force umount a partition on Linux platform

先用 fuser -k yourdir
然后 umount yourdir

如果不行 那么 man fuser
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP