Search:  
Gentoo Wiki

TIP_NFS_premount_check

Situation

You have a notebook setup which mounts some directories from a local net-only server, e.g. mp3s, portage dir, etc. When you're travelling, mounting those nfs directories will fail as the nfs host is not reachable. This will result in several minutes of hang time during the boot process. This tip tries to avoid that long wait.

The idea

I wrote a mount helper script that checks if the host is up and running before mounting it. See man mount for further information on mount helper.

File: /sbin/mount.nfs
#!/bin/bash

REMOTE_HOST=`echo "$@"|gawk -F ":" '{print $1}'`
ping -c1 -W1 ${REMOTE_HOST} > /dev/null
PING_RESULT=$?
if [ $PING_RESULT -eq 0 ]
then
        mount -t nfs -i "$@"
else
        echo "Error: ${REMOTE_HOST} is not reachable"
fi
exit ${PING_RESULT}

Why it (should) work

I'm using only programs from the root filesystem (those in /bin an /sbin) so this works even if you mount /usr via nfs. What is does is simply that it pings the remote host. If it's not reachable (PING_RESULT != 0 (==1)) it prints an error message. If it succceeds it will start the mount process. The parameter "-i" for the mount command tells mount not to start /sbin/mount.nfs again. This script gave me a HUGE speed up when I'm not running my notebook at home but on travel. I hope you'll enjoy it. Feel free to extend it further.

Retrieved from "http://www.gentoo-wiki.info/TIP_NFS_premount_check"

Last modified: Fri, 05 Sep 2008 23:33:00 +0000 Hits: 6,507