3

The standard way to setup a central "/home" directory on a Linux workstation is using NFS. The problem is that I don't like the lack of real security in NFS. So instead I want to try to use SSHFS. SSHFS in-and-of itself works fine, the problem is with mounting it at boot. If I add a line to "/etc/fstab" for the SSHFS share, the workstation complains that it can't contact the SSH server. This is true because the "/etc/fstab" lines are executed before networking is actually up!

Right now I am using the following init script to mount "/home":

#!/bin/sh

# Mounts "/home"  over SSHFS at boot

start () {
    while true; do
        ping -c 1 "10.0.0.200" 1> /dev/null

        if [ "$?" = 0 ]; then
            break
        fi

        sleep 1
    done

    sshfs root@10.0.0.200:/home/ /home/ -o transform_symlinks,allow_other,nonempty,hard_remove
}

case "$1" in
    start)
        start
        ;;

    *)
        echo "Usage: $0 {start}"
        exit 1

esac

Basically it pings the SSH server once per second until it can connect, then it mounts the SSHFS share.

My question is: Is there a more direct and less "hack-ish" way to make "/etc/fstab" wait until there is an active network connection before attempting to mount "/home"?

An alternative idea I had, was adding the "sshfs root@10.0.0.200:/home/ /home/ -o transform_symlinks,allow_other,nonempty,hard_remove" line as an "post-up" script in "/etc/network/interfaces", but that still feels wrong.

Environment:

Server OS: Ubuntu Server Edition 10.04

Client OS: Ubuntu Desktop 10.04

Soviero
  • 4,306
  • 7
  • 34
  • 59

1 Answers1

3

You probably want to add the _netdev option to delay mounting until the network has been enabled:

sshfs#root@10.0.0.200:/home/ /home/ fuse transform_symlinks,allow_other,_netdev,nonempty,hard_remove 0 0

You can also put your script in /etc/network/if-up.d/ or the mount command in /etc/rc.local.

quanta
  • 50,327
  • 19
  • 152
  • 213
  • Adding "_netdev" absolutely fixed it! Thank you for both the answer and the quick response time. – Soviero Nov 02 '11 at 04:31