Why can’t I unmount my mount?

This basic (re-worded) question came in from Jeff: “Why won’t my remote filesystem mount unmount when I try the umount command?

It’s very true:  If you try to umount (unmount) a filesystem that is currently being accessed, it will not let you do it.  And it will tell you something like, “umount: /media/ncp: device is busy“.  What causes this?  Well, it’s likely to be one of two things:

  1. You have (or someone else has) cd‘d onto the remote filesystem and are currently at or below the mount point root
  2. You are running an application that has a file open on that mount point

To mitigate item #1 above (if you are the guilty party, not someone else), just cd to the filesystem root (like cd /), or some other place you know is not on the mount point (like cd /tmp).  Then you can run your umount command.

Solving item #2 above is perhaps a tad more tricky.  Of course, if you have a suspicion or direct knowledge of the guilty app, then you can just stop it.  Sometimes doing this:

ps -ef | grep
…or…
ps aux |grep

…will show the process and any files it accessed by the startup command.

Either way, my favorite way to check for both item #1 and #2 above is to use lsof.  This utility will list *every* file that the system has a hold on.  And this is essential because after all, we know that Linux is nothing but a bunch of files, right?

So here’s what I like to do, for example:

lsof| grep "/media"

… this will show you if anyone or anything is currently sitting on the mountpoint (of course, change your mountpoint to suit, be it /media, /mnt, /export, whatever).  If it shows anything, you can see who or what is at fault, and tell them to get off it, or kill them (I mean the app, jeez…).  If you really need to see the headers of the columns, you can do a double-run for cosmetic purposes that will run once for just the header, then again to grab your detail, like this:

lsof |head -1;lsof| grep "/media"

Another way is to use the fuser command, referencing your mount point. Here’s my favorite set of flags in an example:

fuser -uv /media/ncp

I hope that helps!

8)

2 Comments

  1. Topper

    And why not just umount -f ?
    On second hand, if ther is no care – umount -l?
    Much simplier

  2. Jeremy Pavlov

    @ Topper

    Sure you could try to force things; however I think you should always be cautious enough to try and see what has accessed the resource that you are trying to disconnect.

    Otherwise, you could corrupt a process, or cause a user to lose data changes, or cause your system to become unstable, etc…

    Thanks!
    – Jeremy

Leave a Comment

Your email address will not be published.