本文轉載至(http://tonnyxs.blog.163.com/blog/static/27937985201102202028695/),存檔備忘。
當Umount一個目錄時,提示device is busy,umount加參數f,是強制執行umount,但是許多時候均不會成功。
原理上要想umount,首先要kill正在使用這個目錄的進程。*假設無法卸載的設備爲/dev/sdb1
1)運行下面命令看一下哪個用戶哪個進程佔用着此設備
fuser -m -v /dev/sdb1
2)運行下面命令殺掉佔用此設備的進程
fuser -m -v -k /dev/sdb1
或者fuser -m -v -k -i /dev/sdb1(每殺掉一下進程會讓你確認)
3)再umount
*殺掉所有以任何形式訪問文件系統 /dev/sdb1的進程:
$fuser -km /dev/sdb1
這個辦法是一個比較粗魯的辦法,通常適用於在測試等非正式環境。比較正規的要配合ps等命令,查出使用的用戶、進程、命令等,然後做出綜合判斷,必要時先通知(signal或口頭等)用戶,確認安全時纔可以強制kill此進程。
但有時fuser執行時,仍然會有報錯,其實umount強制退出,可以考慮用參數l(Lazy),這個參數是比f(Force)更強大的終極命令。
Man Umount 查看f和l的參數說明如下:
-f Force unmount. This allows an NFS-mounted filesystem to be unmounted if the NFS server is unreachable. Note: when using umount -f on an NFS filesystem, the filesystem must be mounted using either the soft, or intr options (see nfs(5). This option will not force unmount a <A1><AE>busy<A1><AF> filesystem (use -l
instead).
(Requires kernel 2.1.116 or later.)
-l Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. This option
allows a <A1><AE>busy<A1><AF> filesystem to be unmounted. (Requires kernel 2.4.11 or later.)
本次操作過程如下:
[root@FUHOST /]# umount /home/swebapp/apache-tomcat-5.5.17/webapps/upload/
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy
[root@FJ-WEB-02 sbin]# umount -f /home/swebapp/apache-tomcat-5.5.17/webapps/upload/
umount2: 設備或資源忙
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy
umount2: 設備或資源忙
umount: /home/swebapp/apache-tomcat-5.5.17/webapps/upload: device is busy
[root@FJ-WEB-02 sbin]# fuser -km /home/swebapp/apache-tomcat-5.5.17/webapps/upload/
/home/swebapp/apache-tomcat-5.5.17/webapps/upload/: 輸入/輸出錯誤
[root@FJ-WEB-02 sbin]# fuser -um /home/swebapp/apache-tomcat-5.5.17/webapps/upload/
/home/swebapp/apache-tomcat-5.5.17/webapps/upload/: 輸入/輸出錯誤
[root@FJ-WEB-02 upload]# umount -l /home/swebapp/apache-tomcat-5.5.17/webapps/upload/