Flip awk return values.
[genkernel.git] / defaults / initrd.scripts
index 30d1a98f6def2eb3c09671e13bdf669a9e21bab9..ac32c8a3eeb90ef80030f0285e822c608527844f 100755 (executable)
@@ -6,14 +6,6 @@ backup() {
        echo -ne "\033[0G\033[0K"
 }
 
-parse_opt() {
-       case "$1" in
-               *\=*)
-                       echo "$1" | cut -d= -f2-
-               ;;
-       esac
-}
-
 modules_load() {
        for module in $*
        do
@@ -61,11 +53,10 @@ findmediamount() {
        # $1 = mount dir name / media name
        # $2 = recognition file
        # $3 = variable to have the device path
-       # $4 = directory before /mnt, like NEW_ROOT
+       # $4 = actual mount dir path (full path)
        # args remaining are possible devices 
 
-       local media=$1 recon=$2 vrbl=$3
-       local mntdir="${4}/mnt/${media}"
+       local media=$1 recon=$2 vrbl=$3 mntdir=$4
        shift 4
 
        good_msg "Looking for the ${media}" ${CRYPT_SILENT}
@@ -97,7 +88,7 @@ findmediamount() {
                                # don't skip device mapper devices. Even the craziest scenario
                                # deserves a fair chance.
                                #
-                               for part in `ls /sys/block/${bsn}/${bsn}[0-9]* 2>/dev/null`
+                               for part in `ls /sys/block/${bsn}/${bsn}*[0-9]* 2>/dev/null`
                                do
                                        skip=1
                                        break;
@@ -106,13 +97,8 @@ findmediamount() {
                                then
                                        continue
                                fi
-                               good_msg "Attempting to mount media:- ${x}" ${CRYPT_SILENT}
+                               good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT}
 
-#                              if [ "${media}" = "cdrom" ]; then
-#                                      mount -r -t iso9660 ${x} ${mntdir} &>/dev/null
-#                              else
-#                                      mount -r -t auto ${x} ${mntdir} &>/dev/null
-#                              fi
                                mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1
                                if [ "$?" = '0' ]
                                then
@@ -153,10 +139,17 @@ devicelist(){
        DEVICES="$DEVICES /dev/sd*"
        # IDE devices
        DEVICES="$DEVICES /dev/hd*"
+       # virtio devices
+       DEVICES="$DEVICES /dev/vd*"
        # USB using the USB Block Driver
        DEVICES="$DEVICES /dev/ubd* /dev/ubd/*"
        # iSeries devices
        DEVICES="$DEVICES /dev/iseries/vcd*"
+       # builtin mmc/sd card reader devices
+       DEVICES="$DEVICES /dev/mmcblk* /dev/mmcblk*/*"
+       # fallback scanning, this might scan something twice, but it's better than
+       # failing to boot.
+       [ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)"
        echo ${DEVICES}
 }
 
@@ -166,7 +159,7 @@ bootstrapCD() {
        # a bunch of extra devices
        [ -n "${CDROOT_DEV}" ] && DEVICES="${CDROOT_DEV}"
 
-       findmediamount "cdrom" "${SUBDIR}/livecd" "REAL_ROOT" "${NEW_ROOT}" ${DEVICES}
+       findmediamount "cdrom" "${SUBDIR}/livecd" "REAL_ROOT" "${CDROOT_PATH}" ${DEVICES}
 }
 
 bootstrapKey() {
@@ -174,7 +167,7 @@ bootstrapKey() {
        local KEYDEVS=`devicelist`
        eval local keyloc='"${CRYPT_'${1}'_KEY}"'
 
-       findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "" ${KEYDEVS}
+       findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS}
 }
 
 cache_cd_contents() {
@@ -195,22 +188,21 @@ cache_cd_contents() {
                        good_msg "Copying loop file for caching..."
                        # Verify that the needed directory exists
                        mkdir -p "$(dirname ${NEW_ROOT}/mnt/${LOOP})"
-                       cp -a ${NEW_ROOT}/mnt/cdrom/${LOOP} ${NEW_ROOT}/mnt/${LOOP}
+                       cp -a ${CDROOT_PATH}/${LOOP} ${NEW_ROOT}/mnt/${LOOP}
                        if [ $? -ne 0 ]
                        then
-                               bad_msg "Failed to cache the loop file! Lack of space?"
+                               warn_msg "Failed to cache the loop file! Lack of RAM?"
+                               rm -rf ${NEW_ROOT}/mnt/${LOOP} 2>/dev/null
                                rm -rf ${NEW_ROOT}/mnt/livecd.* 2>/dev/null
                                rm -rf ${NEW_ROOT}/mnt/image.* 2>/dev/null
                                rm -rf ${NEW_ROOT}/mnt/zisofs 2>/dev/null
-                       else
-                               LOOPEXT='../'
                        fi
                fi
        fi
 }
 
 mount_sysfs() {
-       mount -t sysfs /sys /sys >/dev/null 2>&1
+       mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null 2>&1
        ret=$?
        [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!"
 }
@@ -266,7 +258,7 @@ findnfsmount() {
                        if [ "${CDROOT}" != '0' ]
                        then
                                good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}"
-                               mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT}/mnt/cdrom
+                               mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH}
                                if [ "$?" = '0' ]
                                then
                                        REAL_ROOT="/dev/nfs"
@@ -291,7 +283,7 @@ findnfsmount() {
 }
 
 check_loop() {
-       if [ "${LOOP}" = '' -o ! -e "mnt/cdrom/${LOOP}" ]
+       if [ "${LOOP}" = '' -o ! -e "${CDROOT_PATH}/${LOOP}" ]
        then
        
                bad_msg "Invalid loop location: ${LOOP}"
@@ -306,9 +298,25 @@ run_shell() {
        /bin/ash
 }
 
-runmdev() {
-       # busybox udev replacement
-       mdev -s
+mount_devfs () {
+       # Use devtmpfs if enabled in kernel,
+       # else tmpfs. Always run mdev just in case
+       devfs=tmpfs
+       if grep -qs devtmpfs /proc/filesystems ; then
+               devfs=devtmpfs
+       fi
+
+       # Options copied from /etc/init.d/udev-mount, should probably be kept in sync
+       if awk 'BEGIN{m=0;} /devtmpfs/{if($3 == "devtmpfs") {m=1;} } END { exit m;}' /proc/mounts; then
+               mount -t $devfs -o "exec,nosuid,mode=0755,size=10M" udev /dev \
+                       || bad_msg "Failed to mount /dev as ${devfs}"
+       fi
+
+       # http://git.busybox.net/busybox/plain/docs/mdev.txt
+       if awk 'BEGIN{m=0;} /devpts/{if($3 == "devpts") {m=1;} } END { exit m;}' /proc/mounts; then
+               mkdir -m 0755 /dev/pts
+               mount -t devpts -o gid=5,mode=0620 devpts /dev/pts  || bad_msg "Failed to mount /dev/pts"
+       fi
 }
 
 test_success() {
@@ -357,14 +365,16 @@ crypt_filter() {
        else
                splash 'verbose' > /dev/null &
                eval $1
-               if [ $? -eq 0 ]
+               res=$?
+               if [ ${res} -eq 0 ]
                then
                        splash set_msg 'Disk unlocked.'
                fi
+               return ${res}
        fi
 }
 
-whereis(){
+prompt_user(){
        # $1 = variable whose value is the path (examples: "REAL_ROOT",
        #      "LUKS_KEYDEV")
        # $2 = label
@@ -373,7 +383,7 @@ whereis(){
        eval local oldvalue='$'${1}
 
        [ \( $# != 2 \) -a \( $# != 3 \) ] && \
-               bad_msg "Bad invocation of function whereis, please file a bug \
+               bad_msg "Bad invocation of function prompt_user, please file a bug \
                report with this message" && exit 1
        [ -n "${3}" ] && local explnt=" or : ${3}" || local explnt="."
        
@@ -398,19 +408,13 @@ whereis(){
        esac
 }
 
-setup_hotplug() {
-       if [ "${KV_2_6_OR_GREATER}" ]
-       then
-               echo /sbin/mdev > /proc/sys/kernel/hotplug
-       fi
-}
-
 setup_slowusb() {
-       # slowusb already set?
-       if [ "${DO_slowusb}" = "1" ]
-       then
-               return
-       fi
+       # This function removes unset DO_slowusb if there is no usb-storage attached.
+       # If noslowusb is set, skip this function
+       [ "${DO_slowusb}" ] || return
+
+       # Unset DO_slowusb, so we can set it again if usb-storage has something attached
+       unset DO_slowusb
 
        local usb_storage_dir="/sys/bus/usb/drivers/usb-storage"
        if [ ! -d "${usb_storage_dir}" ]
@@ -425,16 +429,6 @@ setup_slowusb() {
        done
 }
 
-start_dev_mgr() {
-       if [ "${KV_2_6_OR_GREATER}" ]
-       then
-               cd /sys
-               good_msg 'Activating mdev'
-               runmdev
-               cd /
-       fi
-}
-
 cmdline_hwopts() {
        # Scan CMDLINE for any "doscsi" or "noscsi"-type arguments
        local FOUND
@@ -453,7 +447,7 @@ cmdline_hwopts() {
                        fi
                        if [ "$(echo ${y} | cut -b -7)" = "keymap=" ]
                        then
-                               MY_HWOPTS="${MY_HWOPTS} dokeymap"
+                               MY_HWOPTS="${MY_HWOPTS} keymap"
                        fi
                done
        done
@@ -567,6 +561,7 @@ chooseKeymap() {
                        40|uk) keymap=uk ;;
                        41|us) keymap=us ;;
                        42|wangbe) keymap=wangbe ;;
+                       43|sf|ch*) keymap=sf ;;
                esac
        fi
        if [ -e /lib/keymaps/${keymap}.map ]
@@ -577,7 +572,7 @@ chooseKeymap() {
 #              echo ${keymap} | egrep -e "[0-9]+" >/dev/null 2>&1
 #              if [ $? -eq 0 ]
 #              then
-#                      xkeymap=`tail -n 7 /lib/keymaps/keymapList | grep ${keymap} | sed -r "s/.*\s+${keymap}\s+([a-z-]+).*/\1/g" | egrep -v 1`
+#                      xkeymap=`tail -n 8 /lib/keymaps/keymapList | grep ${keymap} | sed -r "s/.*\s+${keymap}\s+([a-z-]+).*/\1/g" | egrep -v 1`
 #              fi
                mkdir -p /etc/sysconfig
 #              echo "XKEYBOARD=${xkeymap}" > /etc/sysconfig/keyboard
@@ -608,12 +603,12 @@ startVolumes() {
        
        if [ "${USE_MDADM}" = '1' ]
        then
-               if [ ! -e '/etc/mdadm.conf' ]
+               if [ -e '/sbin/mdadm' ]
                then
-                       echo "DEVICE /dev/sd[a-z]* /dev/hd[a-z]*" >/etc/mdadm.conf
-                       /sbin/mdadm --examine --scan >>/etc/mdadm.conf
+                       /sbin/mdadm --assemble --scan
+               else
+                       bad_msg "mdadm not found: skipping mdadm raid assembly!"
                fi
-               /sbin/mdadm --assemble --scan
        fi
 
        if [ "${USE_DMRAID_NORMAL}" = '1' ]
@@ -641,42 +636,79 @@ startVolumes() {
 
                        # This is needed for /bin/lvm to accept the following logic
                        lvm_commands="#! /bin/lvm"
+
                        # If there is a cahe, update it. Unbreak at least dmcrypt
-                       [ -d /etc/lvm/cache ] && lvm_commands="$lvm_commands \nvgscan"
+                       [ -d /etc/lvm/cache ] && lvm_commands="${lvm_commands} \nvgscan"
+
                        # To activate volumegroups on all devices in the cache
-                       lvm_commands="$lvm_commands \nvgchange -ay --sysinit"
+                       lvm_commands="${lvm_commands} \nvgchange -ay --sysinit"
+                       
+                       # To create symlinks so users can use real_root=/dev/vg/root
+                       # This needs to run after vgchange, using vgchange --mknodes is too
+                       # early.
+                       lvm_commands="${lvm_commands} \nvgmknodes --ignorelockingfailure"
+
                        # And finally execute it all (/proc/... needed if lvm is compiled without readline)
                        good_msg "Scanning for and activating Volume Groups"
-                       printf "%b\n" "$lvm_commands" | /bin/lvm /proc/self/fd/0
-
-                       # Disable EVMS since lvm is activated and they dont work together.
-                       if [ "${USE_EVMS_NORMAL}" = '1' ]
-                       then
-                               bad_msg "Disabling EVMS Support because LVM started"
-                               bad_msg "Do not add dolvm to the cmdline if this is not what you want"
-                               bad_msg "LVM and EVMS do not work well together"
-                               USE_EVMS_NORMAL=0
-                       fi
+                       printf "%b\n" "${lvm_commands}" | /bin/lvm /proc/self/fd/0
                else
                        bad_msg "vgscan or vgchange not found: skipping LVM volume group activation!"
                fi
        fi
-
-       if [ "${USE_EVMS_NORMAL}" = '1' ]
+       
+       if [ "${USE_ZFS}" = '1' ]
        then
-               if [ -e '/sbin/evms_activate' ]
+               if [ -z "${ZFS_POOL}" ]
                then
-                       good_msg "Activating EVMS"
-                       evms_activate
+                       good_msg "Importing ZFS pools"
+
+                       /sbin/zpool import -N -a "${ZPOOL_FORCE}"
+
+                       if [ "$?" = '0' ]
+                       then
+                               good_msg "Importing ZFS pools succeeded"
+                       else
+                               bad_msg "Imported ZFS pools failed"
+                       fi
+               else
+
+                       if [ "$(zpool list -H -o name ${ZFS_POOL} 2>&1)" = "$ZFS_POOL" ]
+                       then
+                               good_msg "ZFS pool ${ZFS_POOL} already imported."
+
+                               if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ]
+                               then
+                                       good_msg "LUKS detected. Reimporting ${ZFS_POOL}"
+                                       /sbin/zpool export -f "${ZFS_POOL}"
+                                       /sbin/zpool import -N "${ZPOOL_FORCE}" "${ZFS_POOL}"
+                               fi
+                       else
+                               good_msg "Importing ZFS pool ${ZFS_POOL}"
+
+                               /sbin/zpool import -N "${ZPOOL_FORCE}" "${ZFS_POOL}"
+
+                               if [ "$?" = '0' ]
+                               then
+                                       good_msg "Importing ${ZFS_POOL} succeeded"
+                               else
+                                       bad_msg "Importing ${ZFS_POOL} failed"
+                               fi
+                       fi
                fi
        fi
 }
 
 startiscsi() {
+       
+       if [ ! -n "${ISCSI_NOIBFT}" ]
+       then
+               good_msg "Activating iSCSI via iBFT"
+               iscsistart -b
+       fi
 
        if [ -n "${ISCSI_INITIATORNAME}" ] && [ -n "${ISCSI_TARGET}" ] && [ -n "${ISCSI_ADDRESS}" ]
        then
-               good_msg "Activating iSCSI"
+               good_msg "Activating iSCSI via cmdline"
 
                if [ "${ISCSI_TGPT}" ]
                then
@@ -739,7 +771,7 @@ openLUKS() {
                        ;;
        esac
 
-       eval local LUKS_DEVICE='"${CRYPT_'${TYPE}'}"' LUKS_NAME="$1" LUKS_KEY='"${CRYPT_'${TYPE}'_KEY}"' LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"'
+       eval local LUKS_DEVICE='"${CRYPT_'${TYPE}'}"' LUKS_NAME="$1" LUKS_KEY='"${CRYPT_'${TYPE}'_KEY}"' LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' LUKS_TRIM='"${CRYPT_'${TYPE}'_TRIM}"'
        local DEV_ERROR=0 KEY_ERROR=0 KEYDEV_ERROR=0
        local mntkey="/mnt/key/" cryptsetup_options=''
 
@@ -753,15 +785,15 @@ openLUKS() {
                        run_shell
                elif [ ${DEV_ERROR} -eq 1 ]
                then
-                       whereis "LUKS_DEVICE" "${LUKS_NAME}"
+                       prompt_user "LUKS_DEVICE" "${LUKS_NAME}"
                        DEV_ERROR=0
                elif [ ${KEY_ERROR} -eq 1 ]
                then
-                       whereis "LUKS_KEY" "${LUKS_NAME} key"
+                       prompt_user "LUKS_KEY" "${LUKS_NAME} key"
                        KEY_ERROR=0
                elif [ ${KEYDEV_ERROR} -eq 1 ]
                then
-                       whereis "LUKS_KEYDEV" "${LUKS_NAME} key device"
+                       prompt_user "LUKS_KEYDEV" "${LUKS_NAME} key device"
                        KEYDEV_ERROR=0
                else
                        case "${LUKS_DEVICE}" in
@@ -780,7 +812,7 @@ openLUKS() {
                                        fi
 
                                        if [ "${retval}" -ne 0 ]; then
-                                               REAL_LUKS=`blkid -l -t "${LUKS_DEVICE}" | cut -d ":" -f 1 2>/dev/null`
+                                               REAL_LUKS=`blkid -o device -l -t "${LUKS_DEVICE}"`
                                                retval=$?
                                        fi
 
@@ -800,6 +832,12 @@ openLUKS() {
                                continue
                        else
                                # Handle keys
+                               if [ "x${LUKS_TRIM}" = "xyes" ]
+                               then
+                                       good_msg "Enabling TRIM support for ${LUKS_NAME}." ${CRYPT_SILENT}
+                                       cryptsetup_options="${cryptsetup_options} --allow-discards"
+                               fi
+
                                if [ -n "${LUKS_KEY}" ] 
                                then
                                        if [ ! -e "${mntkey}${LUKS_KEY}" ] 
@@ -858,7 +896,7 @@ openLUKS() {
                                        fi
                                        # At this point a candidate key exists (either mounted before or not)
                                        good_msg "${LUKS_KEY} on device ${LUKS_KEYDEV} found" ${CRYPT_SILENT}
-                                       if [ $(echo ${LUKS_KEY} | grep -o '.gpg$') = ".gpg" ] && [ -e /sbin/gpg ] ; then
+                                       if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ] && [ -e /sbin/gpg ] ; then
                                                [ -e /dev/tty ] && mv /dev/tty /dev/tty.org
                                                mknod /dev/tty c 5 1
                                                cryptsetup_options="-d -"
@@ -869,7 +907,13 @@ openLUKS() {
                                fi
                                # At this point, keyfile or not, we're ready!
                                crypt_filter "${gpg_cmd}cryptsetup ${cryptsetup_options} luksOpen ${LUKS_DEVICE} ${LUKS_NAME}"
-                               if [ $? -eq 0 ]
+                               crypt_filter_ret=$?
+
+                               [ -e /dev/tty.org ] \
+                                       && rm -f /dev/tty \
+                                       && mv /dev/tty.org /dev/tty
+
+                               if [ ${crypt_filter_ret} -eq 0 ]
                                then
                                        good_msg "LUKS device ${LUKS_DEVICE} opened" ${CRYPT_SILENT}
                                        break
@@ -922,8 +966,15 @@ sdelay() {
        # Sleep a specific number of seconds if SDELAY is set
        if [ "${SDELAY}" ]
        then
-               good_msg 'Waiting ${SDELAY} seconds...'
+               good_msg "Waiting ${SDELAY} seconds..."
                sleep ${SDELAY}
+       elif [ "${CDROOT}" = '1' ]
+       then
+               # many CD/DVD drives require extra sleep, especially when
+               # connected via USB. Many people reported that 1 second sleep
+               # is not enough on their notebooks, that's why sleep 3, when booting
+               # off a livecd is a better default.
+               sleep 3
        else
                good_msg 'Hint: Use parameter scandelay[=seconds] if you need waiting here'
        fi
@@ -943,10 +994,10 @@ verbose_kmsg() {
 cdupdate() {
        if [ "${CDROOT}" = '1' ]
        then
-               if [ -x /${NEW_ROOT}/mnt/cdrom/cdupdate.sh ]
+               if [ -x /${CDROOT_PATH}/cdupdate.sh ]
                then
                        good_msg "Running cdupdate.sh"
-                       ${NEW_ROOT}/mnt/cdrom/cdupdate.sh
+                       ${CDROOT_PATH}/cdupdate.sh
                        if [ "$?" != '0' ]
                        then
                                bad_msg "Executing cdupdate.sh failed!"
@@ -982,12 +1033,16 @@ setup_md_device() {
        fi
 }
 
+do_rundebugshell() {
+       good_msg 'Type "exit" to continue with normal bootup.'
+       [ -x /bin/sh ] && /bin/sh || /bin/ash
+}
+
 rundebugshell() {
        if [ -n "$DEBUG" ]
        then
                good_msg 'Starting debug shell as requested by "debug" option.'
-               good_msg 'Type "exit" to continue with normal bootup.'
-               [ -x /bin/sh ] && /bin/sh || /bin/ash
+               do_rundebugshell
        fi
 }
 
@@ -1061,10 +1116,9 @@ tuxonice_resume() {
 }
 
 find_loop() {
-       CDROM="${NEW_ROOT}/mnt/cdrom"
        for loop in ${LOOPS}
        do
-               if [ -e "${CDROM}""${loop}" ]
+               if [ -e "${CDROOT_PATH}""${loop}" ]
                then
                        LOOP="${loop}"
                fi
@@ -1082,6 +1136,34 @@ getdvhoff() {
        echo $(( $(hexdump -n 4 -s $((316 + 12 * $2)) -e '"%i"' $1) * 512))
 }
 
+setup_squashfs_aufs() {
+       (
+       # Setup aufs directories and vars
+       local overlay=/mnt/overlay
+       local static=/mnt/livecd
+
+       for i in "${overlay}" "${static}"; do
+               [ ! -d "${i}" ] && mkdir -p "${i}"
+       done
+       good_msg "Loading aufs"
+       modprobe aufs > /dev/null 2>&1
+
+       mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${static}"
+       mount -t tmpfs none "${overlay}"
+       mount -t aufs -o br:${overlay}:${static} aufs "${NEW_ROOT}"
+
+       [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}"
+       [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}"
+       echo "aufs / aufs defaults 0 0" > "${NEW_ROOT}"/etc/fstab
+       for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done
+
+       # have handy /mnt/cdrom (CDROOT_PATH) as well
+       local new_cdroot="${NEW_ROOT}${CDROOT_PATH}"
+       [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}"
+       mount --bind "${CDROOT_PATH}" "${new_cdroot}"
+       )
+}
+
 setup_unionfs() {
        local rw_dir=$1
        local ro_dir=$2
@@ -1139,7 +1221,54 @@ setup_unionfs() {
                        bad_msg "Can't setup union mount!"
                        USE_UNIONFS_NORMAL=0
                fi
+               [ ! -d "${NEW_ROOT}${CDROOT_PATH}" ] && mkdir -p "${NEW_ROOT}${CDROOT_PATH}"
+               mount --bind "${CDROOT_PATH}" "${NEW_ROOT}${CDROOT_PATH}"
        else
                USE_UNIONFS_NORMAL=0
        fi
 }
+
+get_mounts_list()
+{
+       awk '
+               /^[[:blank:]]*#/ { next }
+               { print $1 }
+               ' ${NEW_ROOT}/etc/initramfs.mounts
+}
+
+get_mount_fstype()
+{
+       [ -e "${NEW_ROOT}"/etc/fstab ] || return 1
+       awk -v fs="$1" '
+               /^[[:blank:]]*#/ { next }
+               $2 == fs { print $3 }
+               ' ${NEW_ROOT}/etc/fstab
+}
+
+get_mount_options()
+{
+       [ -e "${NEW_ROOT}"/etc/fstab ] || return 1
+       awk -v fs="$1" '
+               /^[[:blank:]]*#/ { next }
+               $2 == fs { print $4 }
+               ' ${NEW_ROOT}/etc/fstab
+}
+
+get_mount_device()
+{
+       [ -e "${NEW_ROOT}"/etc/fstab ] || return 1
+       awk -v fs="$1" '
+               /^[[:blank:]]*#/ { next }
+               $2 == fs { print $1 }
+               ' ${NEW_ROOT}/etc/fstab
+}
+
+# If the kernel is handed a mount option is does not recognize, it WILL fail to
+# mount. util-linux handles auto/noauto, but busybox passes it straight to the kernel
+# which then rejects the mount.
+# To make like a little easier, busybox mount does not care about leading,
+# trailing or duplicate commas.
+strip_mount_options()
+{
+       sed -r 's/(,|^)(no)?auto(,|$)/,/g'
+}