UPDATE: Previous post below, and slightly different from this approach.
Now that I have had a couple of minutes to work with the scripts, here is a simplified approach. In /etc/fstab make your nfs mounts have the 'noauto' option. Like this
Code:
# <file system> <mount point> <type> <options> <dump> <pass>
yournfsserver:/some/directory /media/directory2 nfs noauto,users,rw,hard,intr,noacl,nolock 0 0
* "yournfsserver," "some," "directory," "media," "directory2," and options should be changed to fit your application.
Next, create /etc/network/if-up.d/mountnetfs and copy this script to it
Code:
#!/bin/sh
## Revised from http://ubuntuforums.org/showthread.php?t=430312
## Script will attempt to mount any fstab entry with type "nfs"
# Not for loopback
[ "$IFACE" != "lo" ] || exit 0
# unmount all shares first
sh "/etc/network/if-down.d/umountnetfs"
while read fs mp type opts dump pass extra
do
# check validity of line
if [ -z "$pass" -o -n "$extra" -o "`expr substr ${fs}x 1 1`" = "#" ];
then
# line is invalid or a comment, so skip it
continue
# check if the line is a selected line
elif echo $type | grep -q "nfs"; then
{ sh -c "mount $mp" &&
echo "$mp mounted as current user (`id -un`)" ||
echo "$mp failed to mount as current user (`id -un`)";
} &
fi
# if not a nfs line, do nothing
done </etc/fstab
wait
One more file, /etc/network/if-down.d/umountnetfs and copy this script to it
Code:
#!/bin/bash
# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0
# comment this for testing
exec 1>/dev/null # squelch output for non-interactive
# umount all nfs mounts
mounted=`grep 'nfs' /etc/mtab | awk '{ print $2 }'`
[ -n "$mounted" ] && { for mount in $mounted; do umount -l $mount; done; }
Finally, change the user and permissions
Code:
sudo chmod 755 /etc/network/if-up.d/mountnetfs /etc/network/if-down.d/umountnetfs
sudo chown root:root /etc/network/if-up.d/mountnetfs /etc/network/if-down.d/umountnetfs
Should now be able to reboot and the mounts wait for connectivity. Hopefully this is helpful. Let me know if you find a better way. Again, this is just revised from http://ubuntuforums.org/showthread.php?t=430312, so most credit goes to http://ubuntuforums.org/member.php?u=233493 .
----Previous post----
Hello, depending on your handiness with script tweaking, you can adapt this to your situation.
http://ubuntuforums.org/showthread.php?t=430312
Change the in the /etc/fstab entry to (see *)
Create the /etc/network/if-up.d/mountsshfs script as /etc/network/if-up.d/netfs (see *)
Change
Code:
SELECTED_STRING="sshfs"
in the if-up.d script to
Code:
SELECTED_STRING="netfs"
(see *)
Will have to re-work much of the if-down.d script to work properly. I currently don't have time to work through it.
*('netfs' could be any non-space word, e.g. "comment=goober" -- be certain "SELECTED_STRING" and "comment" are the same, if-up.d and if-down.d file names do not have to match any other name, just done to look nice).
At any rate, hopefully this can get you on the right track. The scripts basically only need to execute the lines which are not comments and contains "nfs", if you want to whittle down to bare essentials. This was a very quick post, so sorry for lacking detail and not having time to test it out myself.
Bookmarks