initrd.scripts: refactor findnfsmount(), improve readability

master
Fabio Erculiani 12 years ago
parent 3790c6345a
commit 7a7e01c47e

@ -402,75 +402,80 @@ mount_sysfs() {
} }
findnfsmount() { findnfsmount() {
if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q if [ -z "${IP}" ]; then
then # IP is not set, return straight away
[ -e /rootpath ] && NFSROOT=$(cat /rootpath) return 0
fi
if [ "${NFSROOT}" = '' ] if ! busybox udhcpc -n -T 15 -q; then
then bad_msg "udhcpc returned error, skipping nfs setup..."
return 0
fi
local options=
[ -e /rootpath ] && NFSROOT=$(cat /rootpath)
if [ "${NFSROOT}" = "" ]; then
# Obtain NFSIP # Obtain NFSIP
OPTIONS=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g") # TODO: this is bogus, because dmesg is a circular buffer...
for OPTION in $OPTIONS # TODO: provide dmesg as symlink (see gen_initramfs.sh)
do options=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g")
if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootserver' ]
then local opt= optn=
NFSIP=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2)
for opt in ${options}; do
optn=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 1)
if [ "${optn}" = "rootserver" ]; then
NFSIP=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 2)
fi fi
done done
# Obtain NFSPATH # Obtain NFSPATH
OPTIONS=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g") # TODO: this is bogus, because dmesg is a circular buffer...
for OPTION in $OPTIONS # TODO: provide dmesg as symlink (see gen_initramfs.sh)
do options=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g")
if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootpath' ]
then for opt in ${options}; do
NFSPATH=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2) optn=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 1)
if [ "${optn}" = "rootpath" ]; then
NFSPATH=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 2)
fi fi
done done
# Setup NFSROOT # Setup NFSROOT
if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ] if [ "${NFSIP}" != "" ] && [ "$NFSPATH" != "" ]; then
then
NFSROOT="${NFSIP}:${NFSPATH}" NFSROOT="${NFSIP}:${NFSPATH}"
else else
bad_msg "The DHCP Server did not send a valid root-path." bad_msg "The DHCP Server did not send a valid root-path."
bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter." bad_msg "Please check your DHCP setup, or set nfsroot=<...>"
fi fi
fi fi
if [ "${NFSROOT}" != '' ] if [ "${NFSROOT}" != "" ]; then
then
NFSOPTIONS=${NFSROOT#*,} NFSOPTIONS=${NFSROOT#*,}
NFSROOT=${NFSROOT%%,*} NFSROOT=${NFSROOT%%,*}
if [ "${NFSOPTIONS}" = "${NFSROOT}" ] if [ "${NFSOPTIONS}" = "${NFSROOT}" ]; then
then NFSOPTIONS="${DEFAULT_NFSOPTIONS}"
NFSOPTIONS=$DEFAULT_NFSOPTIONS
else else
NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}"
fi fi
if is_livecd local path=
then # override path if on livecd
good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}" if is_livecd; then
mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH} path="${CDROOT_PATH}"
if [ "$?" = '0' ] good_msg "Attempting to mount NFS CD image on ${NFSROOT}."
then
REAL_ROOT="/dev/nfs"
else else
bad_msg "NFS Mounting failed. Is the path corrent ?" path="${NEW_ROOT}"
good_msg "Attempting to mount NFS root on ${NFSROOT}."
fi fi
else
good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}" good_msg "NFS options: ${NFSOPTIONS}"
mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT} mount -t nfs -o ${NFSOPTIONS} "${NFSROOT}" "${path}"
if [ "$?" = '0' ] if [ "${?}" = "0" ]; then
then
REAL_ROOT="/dev/nfs" REAL_ROOT="/dev/nfs"
else else
bad_msg "NFS Mounting failed. Is the path correct ?" bad_msg "NFS Mounting failed. Is the path corrent ?"
fi
# FIXME: Need to start portmap and the other rpc daemons in
# order to remount rw.
fi
fi fi
fi fi
} }

Loading…
Cancel
Save