I recently ran into an issue where a mounted SSHFS filesystem refused to unmount.
I tried to unmount it from inside Nautilus by right-clicking the mount and selecting Unmount, but this failed with an error message. The error told me that it couldn’t unmount the device and gave a reason of “mount disagrees with the fstab”.
I then edited the fstab (sudo vi /etc/fstab
) and commented out the entry for the device. I tried to unmount in Nautilus again, but this time it told me that I couldn’t unmount the device because I wasn’t root and the device was not listed in fstab. I then uncommented the previously commented line and saved the file again.
Time to get dirty. I tried to manually run umount
, but it failed:
[chris@home ~]$ sudo umount /mnt/share umount: /mnt/share: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) [chris@home ~]$
This was getting personal now as the previous messages said nothing about the device being in use. I closed out every application and tried again. Same error message.
I followed the instructions and ran man lsof
followed by man fuser
to find out more about those recommended commands. fuser was the winner.
fuser allows you to find out detailed information about processes that are using specific files or sockets. In addition to getting information, it allows you to kill processes accessing the file or socket. This was exactly what I was looking for.
After reading up on the fuser syntax, I ran the following:
[chris@home ~]$ sudo fuser -km /mnt/share /mnt/share/: 9004c [chris@home ~]$
This command basically translates into “find every process that is accessing the /mnt/share mount point and kill it”. Since I was unsure of the ownership of the processes that would be killed, I ran it with sudo to make sure that any processes could be killed.
The /mnt/share/: 9004c
response means that a process with an ID of 9004 was terminated.
Again, I ran:
[chris@home ~]$ sudo umount /mnt/share [chris@home ~]$
This command cheerily replied with nothing, which is a good sign as it means that the umount command succeeded.
Finally, the mount is unmounted. Now if only I could remember what I was trying to do when this problem happened…
Did I help you?
ajajja you forgot what you wanted to do LOL!! thanks 🙂
Thank you so much this helped out a great deal.
I got the same error. It helps me very much. Thx 🙂
umount -l
It will help to do that.
This helped alot! Thanks
thanks for taking the time to document this…
man you’re great!!
It was really helpful. thanks
[…] https://chrisjean.com/forcing-a-device-to-unmount-in-ubuntu-linux/ […]
nice 😀
[…] [chrisjean.com] Forcing a Device to Unmount in Ubuntu Linux […]
thx m8 it worked like a charm
[…] [chrisjean.com] Forcing a Device to Unmount in Ubuntu Linux […]
when i had use the fuser -kmi /root/usb in server . i was logout the server and i could not login to server. i got port 22: Connection refused.
[root@host218 ~]# fuser -kmi /root/usb
/root/usb: 1rce 2rc 3rc 4rc 5rc 6rc 7rc 8rc 9rc 10rc 11rc 12rc 13rc 14rc 15rc 16rc 17rc 18rc 19rc 20rc 21rc 22rc 23rc 24rc 25rc 26rc 27rc 28rc 29rc 30rc 31rc 32rc 33rc 34rc 35rc 36rc 37rc 38rc 39rc 40rc 41rc 42rc 43rc 44rc 45rc 46rc 47rc 48rc 49rc 50rc 51rc 52rc 53rc 54rc 55rc 56rc 57rc 58rc 59rc 60rc 61rc 62rc 63rc 64rc 65rc 66rc 67rc 68rc 69rc 70rc 71rc 72rc 73rc 74rc 75rc 76rc 77rc 78rc 79rc 80rc 81rc 82rc 83rc 84rc 85rc 86rc 87rc 88rc 89rc 90rc 91rc 92rc 93rc 94rc 95rc 96rc 97rc 98rc 99rc 100rc 101rc 102rc 103rc 104rc 105rc 106rc 107rc 108rc 109rc 110rc 111rc 112rc 113rc 114rc 115rc 116rc 117rc 118rc 123rc 124rc 125rc 126rc 127rc 128rc 129rc 130rc 131rc 132rc 134rc 135rc 164rc 243rc 335rc 336rc 338rc 339rc 414rc 415rc 442rc 490rce 541rc 850rc 851rc 886rc 1226rce 1242rce 1323rce 1331rce 1365rce 1470rce 1525rce 1527rce 1529rce 1530rce 1531rce 1532rce 1547rce 1558rce 1567rce 1575rce 1597rce 1616rce 1625rce 1631rce 1644rce 1646rce 1648rce 1650rce 1654rce 1656rce 1657rce 1658rce 1659rce 1660rce 1661rce 3248rce 3303rce 3304rce 3308rce 3694rc 3695rc 3842rce 3843rce 3844rce 3845rce 3846rce 3847rce 3848rce 4666rce 4869rc 5129rce 5163rc 5164rc 5669rce 5670rce 5671rce 5673rce 6776rce 11730rce 12171rce 12738rce 14350rce 14535rce 14536rce 14540rce 17604rce 24130rce 24148rce 24149rce 24152rce 24155rce 24163rce 24164rce 24167rce 24169rce 25131rce 25330rce 25333rce 25336rce 25338rce 25343rce 25362rce 25371rce 25373rce 25374rce 25378rce 25382rce 27258rce 27260rce 27594rce 27596rce 28735rce 29567rce 29920rce 32490rce
Connection to 105.114.86.218 closed by remote host.
Connection to 105.114.86.218 closed.
I modified your comment just in case a curious reader tries running your command. I changed
-km
to-kmi
to make the process interactive rather than automatically terminating processes.I don’t know why you would have a mount point in the
/root
directory. Looking at the output, it looks like the file system used by/root/usb
is the same as the file system used by/
. Effectively, you told the command to terminate all processes accessing the/
file system. This resulted in terminating all the processes responsible for keeping the operating system running. The only way to recover from this will likely be to hard reboot the system.