Linux: umount 時 出現 "Device is busy" 的解法

當任何目錄有 mount, 然後有程式 使用/掛 在那個目錄上的話, 就沒有辦法 umount 掉, 於 umount 時會出現 Device is busy 的訊息.

要怎麼找出是哪個程式掛在那個目錄上? 然後去把那個程式砍掉呢?

使用 fuser 的指令

那要怎麼找出是哪個程式掛在那個目錄上, 可以使用 fuser - identify processes using files or sockets

假設現在 mount 起來的目錄是 /media/share

  • 查詢: fuser -m /media/share
  • 顯示: /media/share: 25023c

就代表是 process 25023(pid) 有使用到此目錄, 後面 c 代表的意思可參考下述:

  • c: current directory.
  • e: executable being run.
  • f: open file. f is omitted in default display mode.
  • F: open file for writing. F is omitted in default display mode.
  • r: root directory.
  • m: mmap'ed file or shared library.

要把這個資源釋放的話, 可以有下述做法:

  • kill -9 25023 # ps aux | grep 25023 應該就會看到它
  • fuser -m -v -i -k /media/share # 會問你是不是要把 25023 這個 kill 掉, 選 y 就會 kill 掉

    訊息如下:
                  USER      PID   ACCESS COMMAND
    /meida/share: root      25023 ..c..  bash
    Kill process 25023 ? (y/N) y

相關網頁

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

在〈Linux: umount 時 出現 "Device is busy" 的解法〉中有 10 則留言

  1. 我用fuser 的command沒有顯示東西
    vi /etc/mtab之後砍掉我mount的device
    但是找不到/etc/init.d/autofs restart
    最後是登出登入,然後unmount桌面顯示的icon

medophin 發表迴響取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料