Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes, I would like to umount a usb device, but I get a drive is busy error.

How do I find out which processes or programs are accessing the device?

share|improve this question
add comment

4 Answers

up vote 16 down vote accepted

Use lsof | grep /media/whatever to find out what is using the mount.

Also, consider umount -l (lazy umount) to prevent new processes from using the drive while you clean up.

share|improve this answer
5  
fuser -mv /path/to/mountpoint might be a more readable alternative for finding out processes using a mointpoint. –  Riccardo Murri Oct 14 '10 at 17:59
add comment

Most of the time, the best command to use is lsof (“list open files”).

lsof +f -- /media/usb0

where /media/usb0 is the mount point of the USB drive or other filesystem to unmount. +f -- tells lsof to treat the subsequent argument as a mount point; it usually, but not always, manages on its own, so that lsof /media/usb0 also works. This finds open files (even unlinked ones), memory mapped files, current directories, and some more obscure uses. You'll need to run the command as root to get information on other users' processes (and I think there are unices where lsof has to be run as root).

There are uses that lsof will not find; these are uncommon on removable media. They include:

  • mount points: you can't unmount /foo if /foo/bar is a mount point.
  • mount devices: you can't unmount /foo if /foo/bar is a mounted block device or loop-mounted regular file, or if it is the source of a Linux bind mount.
  • NFS export: lsof won't detect that a tree is exported by a kernel NFS server.

Another command that can serve in a pinch is fuser, which only lists PIDs of processes with open files on the device:

fuser -m /media/usb0
share|improve this answer
add comment

You can use lsof like Peter said, or if you're sure you just wanna kill all those things and unmount it, you can probably do something like:

fuser -k /mnt/path
umount /mnt/path
share|improve this answer
add comment

If you use GNOME, unmounting via Nautilus will display a message stating which process is still using the drive, and the file it's using.

alt text

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.