You were never here, you didn't see anything..

Netbook, NFS and postup

Since I am up late I will hammer this out while it is fresh in my mind. I am using my netbook more and more. As noted in the previous post “Gentoo Server Config -1” I use NFS on my home server. Well I would like access to the NFS shares from my netbook but I don’t want it taking forever booting or loading the WiFi when those shares are unreachable, like when I travel for example. A little digging online and through the docs turned up a very handy Gentoo solution, postup.

The networking scripts will check for a function named “postup” (among others) in the “/etc/conf.d/net” file. If this function is found it will be executed upon having successfully brought the interface up. This means it won’t hang on boot waiting for it, but once it does come up the function is run. This also avoids nasty hangs and errors from trying to start a service that depends on the interface being actively up, like NFS for example…

Enter my implementation of the function:

postup() { 
    if [ ${IFACE} != "lo" ]; then
        net_domain=$(grep domain /var/run/dhcpcd/resolv.conf/${IFACE} | cut -d " " -f 2) 
        if [ $net_domain = "Inferno-Valley" ]; then 
            /bin/mount /media/photon/home 
            /bin/mount /media/photon/anime 
    return 0 

To break it down;
The variable ${IFACE} translates to whichever interface is being brought up. This means this will be effective on the eth0 wired interface as well as the wlan0 WiFi interface.

First we check to make sure we are not working with the “lo” interface. Don’t want to waste time doing checks and so on with an interface that will not return anything we are loking for.

Next, if not “lo”, we set the “net_domain” variable to the domain provided via dhcpcd which can be found in the file “/var/run/dhcpcd/resolv.conf/${IFACE}”. This value is pushed via the DHCP server configuration.

Next an if checks the “net_domain” variable to see if it matches the desired domain. In this case I use the domain Inferno-Valley which started as a joke from my early LAN party days (we had a real small room to work with and it got really hot) that has simply stuck with me.

If the domain check passes we go ahead and mount the NFS shares. I specified the shares directly as who knows, I may want to add more NFS shares to my “/etc/fstab” at some point so a “mount -a -t nfs” would hit them all. Mounting them explicitly has another benefit too.

To keep additional delays and such out of the boot and other processes the shares are defined in the “/etc/fstab” file with the “noauto” and “_netdev” options set. The “noauto” prevents it from being automatically mounted. The “_netdev” specifies it as a network device so the startup and/or other scripts handle things accordingly.

The end result is things still boot up rather quickly with the added bonus of any time I am at home my NFS shares are automatically mounted. When I am not at home it will not even try to look for or mount the shares keeping things clean.

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *


This blog is kept spam free by WP-SpamFree.

Most who fail…

Most who fail have yet to really try!