#!/bin/sh . /lib/dracut-lib PATH=$PATH:/sbin:/usr/sbin # XXX needs error handling like ifup/dhclient-script getarg rdnetdebug && { exec > /tmp/nfsroot.$1.$$.out exec 2>> /tmp/nfsroot.$1.$$.out set -x } # root is in the form root=nfs[4]:server:path:[options] netif="$1" root="$2" nfsver=${root%%:*}; root=${root#*:} nfsserver=${root%%:*}; root=${root#*:} nfspath=${root%%:*} flags=${root#*:} # look through the flags and see if any are overridden by the command line # Append a , so we know we terminate flags=${flags}, while [ -n "$flags" ]; do f=${flags%%,*} flags=${flags#*,} if [ -z "$f" ]; then break fi if [ "$f" = "ro" -o "$f" = "rw" ]; then nfsrw=$f continue fi if [ "$f" = "lock" -o "$f" = "nolock" ]; then nfslock=$f continue fi nfsflags=${nfsflags+$nfsflags,}$f done getarg ro && nfsrw=ro getarg rw && nfsrw=rw nfsflags=${nfsflags+$nfsflags,}${nfsrw} # Load the modules so the filesystem type is there modprobe nfs || exit 1 # XXX don't forget to move /var/lib/nfs/rpc_pipefs to new / # Start rpcbind and rpc.statd as mount won't let us use locks on a NFSv4 # filesystem without talking to them, even though they are unneeded # XXX occasionally saw 'rpcbind: fork failed: No such device' -- why? [ -n "$(pidof rpcbind)" ] || rpcbind [ -n "$(pidof rpc.statd)" ] || rpc.statd # XXX should I do rpc.idmapd here, or wait and start in the new root # XXX waiting assumes root can read everything it needs right up until # XXX we start it... # XXX really, want to retry in a loop I think, but not here... if [ "$nfsver" = "nfs4" ]; then # XXX really needed? Do we need non-root users before we start it in # XXX the real root image? if [ -z "$(pidof rpc.idmapd)" ]; then rpc.idmapd fi # NFSv4 does locks internally exec mount -t nfs4 -o${nfsflags}${nfslock+,$nfslock} \ $nfsserver:$nfspath $NEWROOT fi # NFSv{2,3} doesn't support using locks as it requires a helper to transfer # the rpcbind state to the new root # [ -z "$nfslock" -o "$nfslock" = "lock" ] && echo "Locks unsupported on NFSv{2,3}, using nolock" 1>&2 exec mount -t nfs -onolock,$nfsflags $nfsserver:$nfspath $NEWROOT