Linux – NFS mounts depending on other NFS mount fail to mount at boot

fstablinuxmountnfs

I have setup 5 NFS mounts in /etc/fstab.

The first one "parent" mounts on local mount point /foo and the other 4 "child" in mounts points on the first one:

So let's say the second is /foo/test1.
The third is in /foo/media etc…

Example:

192.168.0.101:/adventure-time    /foo           some-nfs-options
192.168.0.101:/south-park        /foo/test1     some-nfs-options
192.168.0.101:/futurama          /foo/media     some-nfs-options
/etc./

But when i do df -h after logging in (after reboot) it shows only the share on /foo… the others (in the sub-directories) are not mounted… So i type mount -a and everything is fine…

I check /var/log/messages and i saw that during boot when it tries to mount the "child" nfs exports which depend on folders in the "parent" one it whines about "no local mounts points found". So i assume it takes some time (we are talking 1-2 seconds more) to mount /adventure-time in /foo so during that time the folders test1 and media are not available… and therefore it fails to mount the other shares.Like it tries to mount everything at once…

Then after login when already these folders are present (because /adventure-time is already mounted in /foo) it mounts the other shares without problem (local mount points already exist)…

The question is how to make the "child" shares to be depending on the "parent" and wait for him to mount before they try?

Typing mount -a in /etc/rc.d/rc.local is only a workaround…

Is there some nfs option that i should put in fstab?

There has to be a solution for this? nfs (or the boot process) should not be that dumb… :/

Best Answer

You want the bg mount option in /etc/fstab: this will cause the mounts which initially fail to background themselves and retry, when they will succeed.