Thursday, February 5, 2009

Unmounting busy device

You have an external drive attached to your linux machine. Then after finishing all your job, you try to unmount it, a message come out saying the device is busy.

# umount /media/disk
umount: /media/disk: device is busy
umount: /media/disk: device is busy

So what could possibly the cause?

1. You are inside the disk. Check your working directory using pwd

# pwd
/media/disk

2. Some files are accessing the disk. Check list of open files using lsof

# lsof | grep /media/disk

3. Some processes areaccessing the disk. Use fuser to check

# fuser -m /media/disk

What to do?

1. For case 1, just go to another directory

# cd
# umount /media/disk

2. For case 2, check the files that are accessing the disk and kill it

# lsof | grep "/media/disk"
vim 2693 pingu cwd DIR 8,4 4096 73729 /media/disk
# kill -9 2693
# umount /media/disk

3. For case 3, find the process that accessing the disk and kill it

# fuser -m /media/disk
/media/disk: 2693

# ps -e | grep 2693
2693 pts/0 00:00:00 vim
# kill -9 2693
# umount /media/disk

4. For case no 3 also, you can use fuser -k to kill the process that bugging the disk directly (Thanx to mr. linuxmalaysia for the comment)

# fuser -k /media/disk
#umount /media/disk


Hope this will be useful

3 comments:

  1. fuser -k /mountpoint

    can be used to directly kill any process that stuck.

    ReplyDelete
  2. Nice post as for me. It would be great to read something more about that topic. The only thing that blog needs is a few photos of some gadgets.
    David Karver
    Cell jammer

    ReplyDelete
  3. If lsof and other commands don't find the process check to see if the mount is exported via nfs and if it is kill the nfs daemon

    ReplyDelete