You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.7 KiB

#!/bin/sh
. /lib/dracut-lib
PATH=$PATH:/sbin:/usr/sbin
# XXX needs error handling like ifup/dhclient-script
if getarg rdnetdebug ; then
exec > /tmp/nfsroot.$1.$$.out
exec 2>> /tmp/nfsroot.$1.$$.out
set -x
fi
# Huh? Empty $1?
[ -z "$1" ] && exit 1
# Huh? Empty $2?
[ -z "$2" ] && exit 1
# Huh? Empty $3?
[ -z "$3" ] && exit 1
# root is in the form root=nfs[4]:server:path:[options]
netif="$1"
root="$2"
NEWROOT="$3"
nfsver=${root%%:*}; root=${root#*:}
nfsserver=${root%%:*}; root=${root#*:}
nfspath=${root%%:*}
flags=${root#*:}
[ -z "$nfspath" ] && nfspath=/tftpboot/%s
# Kernel replaces first %s with host name, and falls back to the ip address
# if it isn't set. Only the first %s is substituted.
#
if [ "${nfspath#*%s}" != "$nfspath" ]; then
ip=$(ip -o -f inet addr show $netif)
ip=${ip%%/*}
ip=${ip##* }
read node < /proc/sys/kernel/hostname
[ "$node" = "(none)" ] && node=$ip
nfspath=${nfspath%%%s*}$node${nfspath#*%s}
fi
# 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
# Override rw/ro if set on cmdline
getarg ro && nfsrw=ro
getarg rw && nfsrw=rw
nfsflags=${nfsflags+$nfsflags,}${nfsrw}
# Load the modules so the filesystem type is there
incol2 /proc/filesystems nfs || modprobe nfs || exit 1
incol2 /proc/filesystems nfs4 || modprobe nfs || exit 1
# Start rpcbind or rpcbind
# FIXME occasionally saw 'rpcbind: fork failed: No such device' -- why?
[ -x /sbin/portmap ] && [ -z "$(pidof portmap)" ] && portmap
[ -x /sbin/rpcbind ] && [ -z "$(pidof rpcbind)" ] && rpcbind
if [ "$nfsver" = "nfs4" ]; then
# Start rpc.statd as mount won't let us use locks on a NFSv4
# filesystem without talking to it. NFSv4 does locks internally,
# rpc.lockd isn't needed
[ -z "$(pidof rpc.statd)" ] && rpc.statd
# 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
# XXX Should we loop here?
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 "Warning: Locks unsupported on NFSv{2,3}, using nolock" 1>&2
# XXX Should we loop here?
exec mount -t nfs -onolock,$nfsflags $nfsserver:$nfspath $NEWROOT