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.
/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…