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?

xyzzyrz
  • 896

4 Answers4

28

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
  • 17,371
mbiber
  • 850
6

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
  • 104,119
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