How to fix NFS (v4) not mounting /etc/fstab entries on boot

Last Modified: Wed, 02 Mar 2011 19:18:38 +0000 ; Created: Tue, 01 Mar 2011 22:22:14 +0000

You want to auto-mount on boot an NFS (I was using nfs4), but for some reason when you place it in /etc/fstab it just won't.

I modified some network settings on a machine, and it stopped working. Ubuntu Server 10.10 64-bit with nfs-common 1.2.2 installed. It worked fine for a while.

My /etc/fstab:

# non-nfs stuff removed   /home   nfs4       _netdev,auto    0       0

The fix:

  1. Use the _netdev option in the /etc/fstab even though during boot the system doesn't really wait for the network to be configured with an IP, it just skips that mount and goes on hence the problem. See Ubuntu's Fstab documentation for details on why _netdev doesn't work with nfs4
  2. Create a file called /etc/init.d/ with the following
    • #!/bin/bash
      # Have to ping the NFS server to know when the network is actually configured
      # This is the only way to use /etc/fstab although you may be better off using Autofs Automounter instead
      # It's just a limitation of NFS and Linux booting.  If your network was Wifi you'd have this problem even worse
      # It may take a few seconds after boot (you get a login prompt on your local console) before this gets to mount too
      while [ ping -c 2 2>/dev/null >/dev/null ]
              sleep 1
      mount -a -O _netdev
  3. chmod 755 /etc/init.d/mount_netdev.bash
  4. ln -s /etc/init.d/mount_netdev.bash /etc/rcS.d/

See also: