LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   nfs and bind-mount order in /etc/fstab (http://www.linuxquestions.org/questions/linux-server-73/nfs-and-bind-mount-order-in-etc-fstab-640807/)

mr.neil 05-08-2008 10:11 AM

nfs and bind-mount order in /etc/fstab
 
How can I bind-mount local directories into part of the tree delivered via nfs at boot time? For example, if /var/chroot/etch-ia32 is on another machine and mounted via nfs how can I bind-mount the local /tmp directory at var/chroot/etch-ia32/tmp at boot time?

/etc/fstab:
137.xxx.xxx.xxx:/var/chroot/etch-ia32 /var/chroot/etch-ia32 nfs defaults,ro 0 0
/tmp /var/chroot/etch-ia32/tmp none bind 0 0

The problem is that at boot time the second entry for /tmp is mounted before the first entry for /var/chroot/etch-ia32, so that the contents of /var/chroot/etch-ia32/tmp end up being masked. Mounting these manually in the right order works, so how can I force the order in /etc/fstab to be honored at boot time? All comments extremely welcome.

rayfordj 05-09-2008 01:03 PM

add _netdev to your bind mount to postpone it being mounted.

Code:

/tmp/  /var/chroot/etc-ia32/tmp  none  _netdev,bind 0 0
since the fs-type is nfs for the nfs mount it waits for networking to be available before attempting to mount.

Hope this helps.

mr.neil 05-09-2008 06:03 PM

Thank you very much for this suggestion---hugely appreciated. Adding _netdev does indeed prevent /var/chroot/etch-ia32/tmp from mounting. So this is almost a complete solution. The remaining problem is that /var/chroot/etch-ia32/tmp does not get mounted at all during boot. (I can't find any errors or reports in the log files either.) While this is obviously better than having it mounted in the wrong order and thus masked by the nfs mount of /var/chroot/etch-ia32, is there any way to have /var/chroot/etch-ia32/tmp mounted _after_ the nfs mounts during boot? I could, for example, add mount commands to rc.local, but maybe there is a better way?

rayfordj 05-09-2008 06:08 PM

hmmm, not sure off-hand. rc.local (like you note) could do the trick. just toss a 'mount -a' or call the bind mount from within rc.local. If you wanted to get "fancier" you could write a script around it that would check to see if it is mounted and, if not, mount it for you.

mr.neil 05-12-2008 08:00 AM

Your suggestion in fact worked perfectly. I'd accidentally included a noauto in the options for /var/chroot/etch-ia32/tmp which messed things up by preventing it from being automatically mounted at boot. But with these entries in /etc/fstab

/etc/fstab:
137.xxx.xxx.xxx:/var/chroot/etch-ia32 /var/chroot/etch-ia32 nfs defaults,ro 0 0
/tmp /var/chroot/etch-ia32/tmp none _netdev,bind 0 0

everything gets mounted at boot, with the nfs partition mounted first and then the bind-mount of /tmp.

Thanks again for your help.

rayfordj 05-12-2008 09:55 AM

Thanks for the followup response. I thought it odd to not have worked but I didnt have access to the system where I'd configured something similar to check my exact configuration(s) for comparison.

Good to hear it is working for you. :)

jononeuk 06-16-2008 03:41 AM

Quote:

Originally Posted by rayfordj (Post 3148631)
rc.local (like you note) could do the trick. just toss a 'mount -a' or call the bind mount from within rc.local. If you wanted to get "fancier" you could write a script around it that would check to see if it is mounted and, if not, mount it for you.

Perhaps because my NFS server is an old SunBlade, the _netdev trick + 'mount -a' in rc.local didn't work for me - it seems like there's a delay of about 5-10 seconds before the NFS mount is ready. Here's a "fancier" script that does the job

Code:

#!/bin/bash

(( "$#" == 0 )) && exit

declare -i count

for mountpoint in "$@" ; do
    count=0
    while ! mount | grep "$mountpoint" > /dev/null ; do
        if mount "$mountpoint" 2>&1 | grep '/etc/fstab' > /dev/null ; then # not in fstab
            break
        fi
        if mount | grep "$mountpoint" > /dev/null ; then # successful mount
            echo "Mounting of $mountpoint SUCCESSFUL after $count tries"
            break
        fi
        count=count+1
        if (( "$count" >= 5 )) ; then # too many retries
            echo "Mounting of $mountpoint UNSUCCESSFUL after $count tries"
            break
        fi
        sleep 5
    done
done

call this script, followed by a list of mount points, from /etc/rc.local


All times are GMT -5. The time now is 09:18 PM.