How do I mount sshfs at boot?
Using a NAS box as 24/7 file server, I'd like to use sshfs to connect to it from an Ubuntu 9.04 desktop. Currently, I have this line in the desktop's fstab:
sshfs#
I can confirm it works with mount `/mnt/storage`. What I need is some method of mounting it at startup, but after the network connection is established. Suggestions?
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Last query:
- 2009-05-18
- Last reply:
- 2009-05-18
Steven Danna (ssd7) said : | #1 |
There are a number of ways to accomplish this. However, the easiest way may be to do the following:
On your desktop, add the following line to the entry in /etc/network/
post-up mount /mnt/storage
The only downside to this is that if the mount fails, the interface will not be marked as up.
Justin Dugger (jldugger) said : | #2 |
Does this work in the presence of NetworkManager?
Steven Danna (ssd7) said : | #3 |
No, that method will not work with NetworkManager since any device connected with NetworkManager doesn't use /etc/network/
You may want to respond to this so this email just so the question goes back to an open status.
Justin Dugger (jldugger) said : | #4 |
Indeed, this is a desktop with wireless. I just find wireless easier to deal with in home deployment, and sufficiently fast for normal use.
Steven Danna (ssd7) said : | #5 |
Ok. I wrote a small script that should do what you need to do; however, there might be a way to do this without a script that I don't know of. The script will keep pinging the server (sleeping 5 seconds between pings) until the server can be reached, once it can be reached, it attempts to mount the drive. The MAX_ATTEMPTS variable is the maximum number of time it will ping the server before giving up. I'm not really a programmer so I'm sure this could be improved. Here is the script:
#!/bin/bash
SERVER=
MAX_ATTEMPTS=30 #Max number of times to see if the server is reachable
if_up="no"
ATTEMPTS=0
ping -q -c 1 $SERVER > /dev/null &> /dev/null
if [ $? = 0 ]; then
if_up="yes"
fi
while [ $if_up = "no" ];
do
sleep 5
ATTEMPTS=$(( $ATTEMPTS + 1 ))
ping -c 1 $SERVER > /dev/null &> /dev/null
if [ "$?" = "0" ]; then
if_up="yes"
fi
if [ "$ATTEMPTS" = "$MAX_ATTEMPTS" ]; then
exit 1
fi
done
if [ $if_up = "yes" ]; then
mount /mnt/storage
fi
To use this, do the following:
1) Open a terminal (Applications-
2) cd ~
3) mkdir bin
4) cd bin
5) gedit conn_test.sh
6) Copy and paste above script into gedit and save the file.
7) Back in the terminal: chmod +x conn_test.sh
8) Go to: System-
9) Click the Add Button
10) Fill the Name field with something like: Mount Network Drive
11) Hit the Browse button next to the "command" field and then find and select the conn_test.sh file you made.
12) Hit the Add button
If you use this method, the script will run after you login to your GNOME session. That is usually the same time that NetworkManager is finding and connecting to your wireless network so it should work the way you desire. Good luck!
Can you help with this problem?
Provide an answer of your own, or ask Justin Dugger for more information if necessary.