歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux維護 >> linux如何使用umount命令強制卸載文件系統

linux如何使用umount命令強制卸載文件系統

日期:2017/3/2 10:27:25   编辑:Linux維護

對於Linux系統下掛載的文件系統,通常情況下是無法卸載的,可通過命令進行強行卸載,下面小編就給大家介紹下Linux使用umount命令強制卸載文件系統的方法。

umount命令

解掛文件系統。umount [-ahnrvV][-t 《文件系統類型》][文件系統]

umount可卸除目前掛在Linux目錄中的文件系統。

線上在用的nfs訪問時出了問題,導致/data1目錄ls都無法進行輸出,需要進行卸載掉 。而直接卸載時由於目錄正被其他進程占用 ,無法直接umount,這裡就結合fuser進行umount卸載。

1、直接卸載

[root@localhost /]# umount /data1/img

umount: /data1/img: device is busy

umount: /data1/img: device is busy

2、提示被占用,使用強制卸載

[root@localhost /]# umount -f /data1/img

umount2: Device or resource busy

umount: /data1/img: device is busy

umount2: Device or resource busy

umount: /data1/img: device is busy

注:使用-f 參數進行強制卸載時一般建議等一會兒再進行下面的操作,一些情況下處理需要1-2分鐘的時間。

3、使用umount -f,問題依舊。使用fuser命令,先確認有那些進程在占用該目錄

[root@localhost /]# fuser -cu /data1/img

/data1/img: 1757c(mysql)

上面查看發現是pid為1757的mysql用戶起的進程在占用該目錄。

4、確認mysql所起的進程可以kill 後,可以直接使用fuser 的k參數進行kill (也可以手動停掉1757進程再卸載)

[root@localhost /]# fuser -ck /data1/img

/data1/img: 1757c

注:這裡k 就是kill的意思,注意沒進行確認前要謹慎使用該參數。

另外,umount異常時,也經常會用到 lsof 指定確認文件被什麼進程占用

上面就是Linux使用umount命令強制卸載文件系統的方法,即使提示被占用也照樣能夠通過命令來卸載。

Copyright © Linux教程網 All Rights Reserved