16

I have an external disk connected via USB that was accidentally disconnected uncleanly. Now lsing the directory in which it was mounted gives Input/output error. umounting the directory simply hangs. dmesg just contains:

[3360010.363235] usb 2-1.1: USB disconnect, device number 3

How do I resolve this (short of rebooting), i.e. how do I clean up kernel state upon unclean disconnect of an external storage device?

Yang
  • 886
  • 3
  • 12
  • 21

4 Answers4

27

Lazy unmount usually does the trick.

sudo umount -l /path/where/its/mounted

For more info try man umount.

-l, --lazy Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore.

A system reboot would be expected in near future if you’re going to use this option for network filesystem or local filesystem with submounts. The recommended use-case for umount -l is to prevent hangs on shutdown due to an unreachable network share where a normal umount will hang due to a downed server or a network partition. Remounts of the share will not be possible.

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
mbiber
  • 830
  • 5
  • 11
  • 4
    This also hangs for ever in my case (an unreachable NFS system). Now I have 6 terminals open with all combinations of umount `-f` and `-l` hanging infinitely. – Hubro Sep 28 '16 at 08:39
  • @Hubro just had the same problem. In my case the clue was that if I run `strace umount -l /mnt/foo/bar`, I get no output, i.e. `umount` wasn't even ran. It turned out, by mistake I wrote name of a directory that is inside the problematic mount point. Like, mount point was `/mnt/foo`, and I wrote `umount -l /mnt/foo/bar`. As result shell was trying to enter the directory *(to check if I typed the path correctly)* and of course was getting frozen. – Hi-Angel Jul 07 '20 at 12:45
5

You should also be able to do

sudo umount -f /path/to/mount

From man umount:

   -f     Force unmount (in case of an unreachable NFS system).  (Requires
          kernel 2.1.116 or later.)
terdon
  • 98,183
  • 15
  • 197
  • 293
  • 2
    I tried this since it sounded perfect for my use case (an unreachable NFS system) but it also hangs for ever, just like it does without the `-f`. – Hubro Sep 28 '16 at 08:35
  • @Hubro try restarting the networking service, that might force it to unmount. – terdon Sep 28 '16 at 09:07
  • Will give it a shot next time. This time I ended up having to reboot. – Hubro Sep 29 '16 at 06:38
0

Just posting this here in hopes that it might help someone reading this in the future. I had a share mapped to /tmp/delete-me and anytime I'd type out the share path, /tmp/delete-m_ it would stop before I could complete typing the full name. This is why the suggestions on force unmounting won't work.

My workaround was to first set a variable using the read built-in command, and then unmount using the variable name.

# If zsh
read "sharePath?Enter the path to the share to be removed: "

# If bash
read -p "Enter the path to the share to be removed: " sharePath

sudo umount $sharePath
0xBEN
  • 1
0

just had the same issue - tried to exec:

sudo umount /path/mymount

but it always already hang when i typed sudo umount /path/mymoun - so couldn't type the last t and press return as it seems the system tries to read the directory. also -l or -f did not help

what worked for me - instead of entering the whole path, i used wildcard:

sudo umount -f /path/mymo*
armin
  • 1
  • If `mymount` is the only file that matches the wildcard, there is no way that the fact that you used the wildcard could have helped. There must have been some other factor that changed without you having noticed it. – dwymark Nov 15 '22 at 23:55