1. 程式人生 > >用fuser或者lsof解決無法umount問題(device is busy

用fuser或者lsof解決無法umount問題(device is busy

一、命令介紹
1.  fuser
        用法 :fuser  [-umv] [-k [i] [-signal] ]    file/dir
                        -u:除了程序的PID外 ,同時列出該程序的所有者。
                        -m:後接的檔名會主動上調到檔案系統的所頂層,對umount不成功很有效。
                        -v:列出每個檔案與程式還有命令的完整相關性。
                        -k:找出使用檔案/目錄的pid,並試圖一sigkill這個訊號給予該pid.
                        -i:與,-k合用,kill前詢問使用者意願。
                        -signal:1,15,9

            可用於在無法umount檔案時,檢視pid,並殺死程序見下面的例子
2.lsof
        用法:lsof  [-aUu] [+d]
        一個奇怪的命令,
        -u:後接username;
        +d:後接目錄,找出某個目錄下面已經被開啟的檔案。

二。解決無法umount問題
本來在把伺服器本地yum源掛載到了html目錄下的centos目錄,用來方便區域網內使用者可以不連外網就能進行yum安裝或這升級,有一天centos目錄卻出錯了導致無法安裝軟體,就重新掛載了centos,但是直接umount不動,就用fuser檢視並殺死程序成功umount
[
[email protected]
~]# umount -f /var/www/html/centos/ umount2: 裝置或資源忙 umount: /var/www/html/centos: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) umount2: 裝置或資源忙 [[email protected] ~]# fuser -l /var/www/html/centos/ HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS UNUSED [
[email protected]
~]# fuser /var/www/html/centos/ /var/www/html/centos/: 9807c [[email protected] ~]# ps -aux|grep 9807c Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 10000 0.0 0.0 103240 896 pts/3 S+ 15:04 0:00 grep 9807c [[email protected] ~]# ps -aux|grep 9807 Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 9807 0.0 0.0 108428 2000 pts/2 Ss+ 14:52 0:00 -bash root 10003 0.0 0.0 103240 896 pts/3 S+ 15:05 0:00 grep 9807 [
[email protected]
~]# kill -9 9807 [[email protected] ~]# umount /var/www/html/centos/