From 51a54c3388c152dcab76e49dbd3086c463bc38f1 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 31 Aug 2013 12:17:01 +0200 Subject: [PATCH] initrd.scripts: move find_nfs to 00-nfs.sh --- defaults/initrd.d/00-nfs.sh | 84 +++++++++++++++++++++++++++++++++++++ defaults/initrd.scripts | 82 +----------------------------------- 2 files changed, 85 insertions(+), 81 deletions(-) create mode 100755 defaults/initrd.d/00-nfs.sh diff --git a/defaults/initrd.d/00-nfs.sh b/defaults/initrd.d/00-nfs.sh new file mode 100755 index 0000000..9e8aed3 --- /dev/null +++ b/defaults/initrd.d/00-nfs.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +. /etc/initrd.d/00-common.sh + +find_nfs() { + if [ -z "${IP}" ]; then + # IP is not set, return straight away + return 1 + fi + + if ! busybox udhcpc -n -T 15 -q; then + bad_msg "udhcpc returned error, skipping nfs setup..." + return 1 + fi + + local options= + + [ -e /rootpath ] && NFSROOT=$(cat /rootpath) + if [ -z "${NFSROOT}" ]; then + # Obtain NFSIP + # TODO: this is bogus, because dmesg is a circular buffer... + # TODO: provide dmesg as symlink (see gen_initramfs.sh) + options=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g") + + local opt= optn= + + 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 + done + + # Obtain NFSPATH + # TODO: this is bogus, because dmesg is a circular buffer... + # TODO: provide dmesg as symlink (see gen_initramfs.sh) + options=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g") + + for opt in ${options}; do + 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 + done + + # Setup NFSROOT + if [ -n "${NFSIP}" ] && [ -n "$NFSPATH" ]; then + NFSROOT="${NFSIP}:${NFSPATH}" + else + bad_msg "The DHCP Server did not send a valid root-path." + bad_msg "Please check your DHCP setup, or set nfsroot=<...>" + return 1 + fi + fi + + # expecting a valid NFSROOT here, or the code should have returned + NFSOPTIONS=${NFSROOT#*,} + NFSROOT=${NFSROOT%%,*} + if [ "${NFSOPTIONS}" = "${NFSROOT}" ]; then + NFSOPTIONS="${DEFAULT_NFSOPTIONS}" + else + NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" + fi + + local path= + # override path if on livecd + if is_livecd; then + path="${CDROOT_PATH}" + good_msg "Attempting to mount NFS CD image on ${NFSROOT}." + else + path="${NEW_ROOT}" + good_msg "Attempting to mount NFS root on ${NFSROOT}." + fi + + good_msg "NFS options: ${NFSOPTIONS}" + mount -t nfs -o ${NFSOPTIONS} "${NFSROOT}" "${path}" + if [ "${?}" = "0" ]; then + REAL_ROOT="/dev/nfs" + return 0 + else + bad_msg "NFS Mounting failed. Is the path corrent ?" + return 1 + fi +} diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 7fd7c90..960987c 100755 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -8,6 +8,7 @@ . /etc/initrd.d/00-zfs.sh . /etc/initrd.d/00-modules.sh . /etc/initrd.d/00-livecd.sh +. /etc/initrd.d/00-nfs.sh . /etc/initrd.d/00-keymaps.sh @@ -34,87 +35,6 @@ bootstrap_key() { media_find "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS} } -find_nfs() { - if [ -z "${IP}" ]; then - # IP is not set, return straight away - return 1 - fi - - if ! busybox udhcpc -n -T 15 -q; then - bad_msg "udhcpc returned error, skipping nfs setup..." - return 1 - fi - - local options= - - [ -e /rootpath ] && NFSROOT=$(cat /rootpath) - if [ -z "${NFSROOT}" ]; then - # Obtain NFSIP - # TODO: this is bogus, because dmesg is a circular buffer... - # TODO: provide dmesg as symlink (see gen_initramfs.sh) - options=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g") - - local opt= optn= - - 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 - done - - # Obtain NFSPATH - # TODO: this is bogus, because dmesg is a circular buffer... - # TODO: provide dmesg as symlink (see gen_initramfs.sh) - options=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g") - - for opt in ${options}; do - 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 - done - - # Setup NFSROOT - if [ -n "${NFSIP}" ] && [ -n "$NFSPATH" ]; then - NFSROOT="${NFSIP}:${NFSPATH}" - else - bad_msg "The DHCP Server did not send a valid root-path." - bad_msg "Please check your DHCP setup, or set nfsroot=<...>" - return 1 - fi - fi - - # expecting a valid NFSROOT here, or the code should have returned - NFSOPTIONS=${NFSROOT#*,} - NFSROOT=${NFSROOT%%,*} - if [ "${NFSOPTIONS}" = "${NFSROOT}" ]; then - NFSOPTIONS="${DEFAULT_NFSOPTIONS}" - else - NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" - fi - - local path= - # override path if on livecd - if is_livecd; then - path="${CDROOT_PATH}" - good_msg "Attempting to mount NFS CD image on ${NFSROOT}." - else - path="${NEW_ROOT}" - good_msg "Attempting to mount NFS root on ${NFSROOT}." - fi - - good_msg "NFS options: ${NFSOPTIONS}" - mount -t nfs -o ${NFSOPTIONS} "${NFSROOT}" "${path}" - if [ "${?}" = "0" ]; then - REAL_ROOT="/dev/nfs" - return 0 - else - bad_msg "NFS Mounting failed. Is the path corrent ?" - return 1 - fi -} - crypt_exec() { if [ "${CRYPT_SILENT}" = '1' ] then