2

I have a machine that mounts another machine's NFS share.

However the client machine boots up faster than the server, so it gets an error when trying to mount the NFS share from the server. I had a power outage over the weekend and this can be annoying when I am remote.

I would like to ensure that the NFS share is always mounted, so that if the client detects that the share isn't there it will attempt to remount it. I think this might involve autofs and/or upstart to ensure the share stays mounted, but I don't know how to do this.

I am mounting it via the following method in /etc/fstab:

jillybean.local:/share /share nfs rsize=32768,rw,soft,intr
0

3 Answers 3

2
+50

There are multiple things you could do:

  • add the retry=n (with n being an integer representing minutes) to your mount options in /etc/fstab for the cases NFS is not (yet) available at boot time
  • make use of autofs, as you suggested (lots of How-Tos returned by this Google search)
  • create some simple daemon process which exits when the NFS share is not available, and mounts it when invoked with the start parameter -- so you can set it up as upstart event with respawn (i.e. automatically restart when aborted other than by service xyz stop). Combine this with above retry=n)
  • setup a cron job checking for some (existing) directory on the NFS share -- and run the mount command when it is not found (again, combine it with retry=n)
0

Consider to create a bash script with the following:

#!/bin/bash
if ! grep -qs '/share' /proc/mounts; then
    mount jillybean.local:/share /share
fi

Give it exe permissions. Then put the script in crontab, croning it to your needs. For example, if you know your machines power on 7 o'clock, you could consider to execute the script every minute from 7 to 8:

0-15 7-8 * * * /path/tho/your/script.sh
0

Try using a background mount.

From the general nfs fstab manpage:

bg / fg

Determines how the mount(8) command behaves if an attempt to mount an export fails. The fg option causes mount(8) to exit with an error status if any part of the mount request times out or fails outright. This is called a "foreground" mount, and is the default behavior if neither the fg nor bg mount option is specified.

If the bg option is specified, a timeout or failure causes the mount(8) command to fork a child which continues to attempt to mount the export. The parent immediately returns with a zero exit code. This is known as a "background" mount.

If the local mount point directory is missing, the mount(8) command acts as if the mount request timed out. This permits nested NFS mounts specified in /etc/fstab to proceed in any order during system initialization, even if some NFS servers are not yet available. Alternatively these issues can be addressed using an automounter (refer to automount(8) for details).

When doing a background mount, default retry is 10000 minutes. From the same page:

retry=n

The number of minutes that the mount(8) command retries an NFS mount operation in the foreground or background before giving up. If this option is not specified, the default value for foreground mounts is 2 minutes, and the default value for background mounts is 10000 minutes (80 minutes shy of one week). If a value of zero is specified, the mount(8) command exits immediately after the first failure.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .