-   Linux - Desktop (
-   -   How to keep alive (or reconnect) fuse SSHFS mount between sleep/hibernate? (

lefty.crupps 09-27-2010 10:33 AM

How to keep alive (or reconnect) fuse SSHFS mount between sleep/hibernate?
Running Debian GNU/Linux (testing/Squeeze, 2.6.32) with KDE 4.4.5 and Wicd networking, trying to sleep (hibernate to RAM).

I have a laptop that connects to another computer in my house with SSHFS at laptop's login to KDE, to allow Amarok to play music and to allow non-KDE apps to easily open and save files across the network (most KDE apps can natively use sftp:// KIO slave).

When the laptop goes to sleep and then resumes, the three mount points:
sometimes are able to reconnect and sometimes SSHFS (fuse) will hang, preventing any file open/save dialogs from functioning (the wife loves this). When SSHFS hangs, sometimes I am able to manually (CLI) unmount the drives as user, sometimes I must be root to do so.

My current attempts to make this function cleanly are failing. This is what I've tried:
1. Using Wicd's 'scripts' functionality to unmount the drives before disconnection, but I don't know if Wicd knows that Sleep is happening
2. KDE's PowerDevil allows for actions before sleep; I put a script there to unmount the drives before sleep
3. I have Wicd (via 'scripts') try to reconnect the drives after a 5sec delay upon reconnecting to the network, but if the mount points aren't cleanly unmounted this usually causes the hang
4. Sometimes things just seem to hang for no reason.
5. Sometimes everything works just fine.

My mount scripts call for SSHFS to use:
-s disable multi-threaded operation
-o reconnect
My unmount (fusermount) scripts use:
-u unmount
-z lazy unmount
and seem to generally work well when I am testing the scripts. It's the Sleep action that seems to be causing most of the issues, as I have a hard time recreating the issue when I am just testing by running the various commands.

Can anyone help me to figure out the best way to make this function? I am not against using /etc/fstab to make these mounts if the ssh mount point can survive the Sleep mode, but I thought that userspace may be better for this (perhaps not).

Earlier today I thought maybe the unmount script could be given UID perms to allow the user account to run root permissions to better unmount these network connections before sleep, but I am not sure yet if that is a good solution or not.

Suggestions anyone?

acid_kewpie 09-27-2010 10:44 AM

Well it's possible to run sshfs over autofs so that would disconnect the mount when it was idle. I'm not sure if that would be wholly suitable if she likes to slam the lid done immediately after using those files, but aside from the time taken to re-establish the sshfs connection on first use of the mount point, it's a really nice model that makes this sort of thing a non-issue.

lefty.crupps 09-27-2010 01:51 PM

autofs to the rescue? I'll get back to you...
> Well it's possible to run sshfs over autofs so that would
> disconnect the mount when it was idle
> the sshfs connection on first use of the
> mount point

That sounds wonderful, I will look into autofs tonight. Thank you so much for the heads up on that, acid_kewpie, and I will post back with results within a few days of testing.

lefty.crupps 09-28-2010 08:52 AM

I cannot seem to get autofs to function with sshfs and mDNS (avahi/zeroconf), although the mDNS may have nothing to do with this.

SSH keys (passwordless) are working fine for normal sshfs and ssh operations.

Here is my entry for /etc/auto.master:

/mnt/network_files/Music /etc/auto.sshfs.Music uid=1000,gid=1000,--timeout=30,--ghost
/mnt/network_files/Photos /etc/auto.sshfs.Photos uid=1000,gid=1000,--timeout=30,--ghost
/mnt/network_files/lefty_computer /etc/auto.sshfs.lefty_computer uid=1000,gid=1000,--timeout=30,--ghost

Here are my other /etc/autofs.sshfs.* files (all very similar so I'll post just one) which I've made executable (apparently needed); note that I've taken a lot of these options from what I've read on the web, but many of the articles seem rather old:

Music -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#lefty@bigboi.local\:/home/lefty/Music

Apparently I also needed to add a line to nsswitch.conf:

# /etc/nsswitch.conf
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:        compat
group:          compat
shadow:        compat

hosts:          files mdns4_minimal dns mdns4
networks:      files mdns4_minimal dns mdns4
automount:      nis files # mdns4_minimal dns mdns4 # these cause 'ignored' warnings

protocols:      db files
services:      db files
ethers:        db files
rpc:            db files

netgroup:      nis

I restarted /etc/init.d/autofs and no matter what I try, nothing shows up in my directory listings; directories are created if I put the mount point elsewhere (in auto.master such as /mnt/Music ). Am I missing something or have I mis-configured the configs? Are my options outdated? Does mDNS not work to resolve my hostname? Are my sshfs syntaxes wrong (because that is a mess)?

humba 11-16-2010 10:17 PM

I'm no expert, but maybe try afuse, an automounter for fuse file systems?

This is my first post on, so I cannot post links but just google:

"afuse" howto

All times are GMT -5. The time now is 01:41 AM.