Can't access folders mounted by sshfs after sleep (or when connection lost)

12

8

Often, when I mount a filesystem via ssh:

sshfs user@remote: ~/Mounts/Remote

and the machine hibernates (closing the Laptop lid) if I wake up the machine I can't access the mounted folder. Furthermore, if I try to ls in the parent folder, the terminal freeze. The same also happens when the connection is somehow lost.

If try to unmount using

fusermount -u ~/Mounts/Remote

I can't do this because:

fusermount: failed to unmount /home/yotama9/Mounts/Remote: Device or resource busy

I tried to kill ssh but I can't mount the folder again. ls in the folder still freezes.

How can I avoid this and fix this (Arch Linux)?

Yotam

Posted 2011-12-07T14:31:39.860

Reputation: 559

killall -KILL sshfs, and next time, mount with mount options from this answer. – Totor – 2019-09-30T18:21:12.663

Answers

12

I suffer the same problem in Ubuntu Linux. What I do after resume:

$ killall -9 sshfs

Then, umount

$ fusermount -u ~/far_projects

and mount again the remote filesystem.

$ sshfs -o idmap=user youruser@server:/projects ~/far_projects

jap1968

Posted 2011-12-07T14:31:39.860

Reputation: 827

Works on macOS too. – Shiva – 2018-11-20T05:45:45.040

Thanks. I replaced killall with killall -9 – Yotam – 2011-12-21T12:40:09.530

1I suggest making a script for more than one or two shares. It makes life a lot easier. – Alex Hirzel – 2012-01-04T03:40:17.983

4

As noted here, this is your solution:

 -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

As an example usage: https://github.com/aktos-io/dcs-tools, take a look at make mount-root target.

ceremcem

Posted 2011-12-07T14:31:39.860

Reputation: 363

More details here https://serverfault.com/questions/6709/sshfs-mount-that-survives-disconnect/#639735

– Totor – 2019-09-30T18:19:55.803

2

I've had the same issue on my laptop.

All you need is to include the lazy unmount option (z) in your unmount command:

$ fusermount -uz ~/Mounts/Remote

Then just remount the same way you normally would.

Also, it's worth noting that I use the reconnect option (-o reconnect) which will maintain the connection through any hiccups (like closing your lid and coming back a few minutes later).

You can also look into a solution like afuse which is an auto-mounter for fuse filesystems (sshfs included) to save you the hassle of unmounting/remounting every time.

One final auto-mount option is using autofs with sshfs.

asyncopation

Posted 2011-12-07T14:31:39.860

Reputation: 461