Linux – Find what is Preventing You from Unmounting a Drive

Disclaimer: I’ve had this problem for probably four months, ever since I started running Plex Media Server on my headless linux machine at home, whilst storing all my actual media on a nice external portable drive. Usually I just yank it, but then I watch the drive letters run themselves up obscenely high before I need to reboot.

So you’ve gone through the process of mounting your drive in Linux:

You run a bunch of stuff, get it all working, then find you need to take the drive to work the next day, so you try to unmount it.

Well, being a Windows guy at heart, and not really understanding why everything here needs to be so technical, this message never told me ANYTHING. I would try typing just plain “lsof” or “lsof(8)” or “fuser(1)” with no useful results.

Then I asked a friend.

lsof | grep <stuff> ,” he said.

“Like,  <stuff>  would be the /dev/sdb1 ?”


So I tried it:

“Oh,” he said. “Try the mount path.  /dev/sdb1  is the device which is mounted somewhere else.”

“Nothing,” I said. “Just a blank line.”

“Looks like no program has any file open on it?”

“Let me try again.”

“Ahh…It may have been because I was still cd’d into it.”


So lessons learned:

  • grep, no matter how weird and complicated it looks with all those pipes and stuff, is still VERY useful.
  • lsof is the command of choice for figuring this out.
  • Use the mount point rather than the drive itself when searcing the lsof output text.
  • Even just navigating into a drive will lock it from being unmounted – it’s not like in Windows where if you “Safely Remove Hardware” or yank the USB cable, the computer conveniently closes the explorer window for you.

Leave a Reply

Your email address will not be published. Required fields are marked *