Archive

Posts Tagged ‘nfs’

Slackware trying to mount NFS shares before the network is ready

June 14th, 2010 4 comments

I have a right pain of a problem in this network in that individual machines are slow to get network access at boot. I haven’t had the opportunity to properly find out why, but my instinct says the blame lies with the Allied Telesyn switches.

The big problem this causes is that any machines with a remote filesystem, such as an NFS share, in their fstab fail to mount the shares at boot; which means I have to manually ssh in and issue a mount command as root.

The solution is to ask rc.inet2 if it would kindly consider waiting just a little longer for the network to come up and not mount remote filesystems if it doesn’t.

The following patch attempts to ping an always-on host, preferably the host that serves the filesystem(s) you are going to mount.

  • If a response is received, the boot process continues as normal.
  • If there’s no response to the first ping:
    • A further 5 pings are attempted.
    • A countdown is displayed.
    • After 6 failed attempts boot continues, but with no attempt to mount remote filesystems.

rc.inet2.diff (download rc.inet2.diff.gz):

--- ./rc.inet2.orig     2007-09-17 23:07:32.000000000 +0100
+++ ./rc.inet2  2010-06-14 14:05:24.237107265 +0100
@@ -15,9 +15,16 @@
 
 # At this point, we are ready to talk to The World...
 
+lan_test_host="<known up host, or remote filesystem server>";
+avail=6;
+while ! ping -c1 $lan_test_host &>/dev/null && (( avail-- > 1 ));
+do
+       echo "Waiting for network before mounting remote filesystems... $avail";
+       sleep 1;
+done
 
 # Mount remote (NFS) filesystems:
-if cat /etc/fstab | grep -v '^#' | grep -w nfs 1> /dev/null 2> /dev/null ; then
+if cat /etc/fstab | grep -v '^#' | grep -w nfs 1> /dev/null 2> /dev/null && ((avail)); then
   # Start rpc.portmap, /sbin/rpc.lockd, and /sbin/rpc.statd if we find NFS
   # volumes defined in /etc/fstab since these will need to be running in order
   # to mount them.  If they are not running, attempting to mount an NFS
@@ -46,7 +53,7 @@
 
 # Mount remote CIFS filesystems.  Note that where possible, using CIFS is
 # preferred over SMBFS.  SMBFS is no longer actively maintained.
-if cat /etc/fstab | grep -v '^#' | grep -w cifs 1> /dev/null 2> /dev/null ; then
+if cat /etc/fstab | grep -v '^#' | grep -w cifs 1> /dev/null 2> /dev/null && ((avail)); then
   echo "Mounting remote CIFS file systems:  /sbin/mount -a -t cifs"
   /sbin/mount -a -t cifs
   # Show the mounted volumes:
@@ -54,7 +61,7 @@
 fi
 
 # Mount remote SMB filesystems:
-if cat /etc/fstab | grep -v '^#' | grep -w smbfs 1> /dev/null 2> /dev/null ; then
+if cat /etc/fstab | grep -v '^#' | grep -w smbfs 1> /dev/null 2> /dev/null && ((avail)); then
   echo "Mounting remote SMBFS file systems:  /sbin/mount -a -t smbfs"
   /sbin/mount -a -t smbfs
   # Show the mounted volumes:

In order to apply the above patch, do the following as root:

# cd /etc/rc.d
# wget http://blog.tpa.me.uk/wp-content/uploads/2010/06/rc.inet2.diff.gz
# zcat rc.inet2.diff.gz | patch -p1

Do not forget to manually edit your newly patched file to replace “<known up host, or remote filesystem server>” with a valid hostname or IP address.