Restore previous handling of real_root due to report of regressions (bug #419965)
[genkernel.git] / defaults / initrd.scripts
index 609c52f7734bb3bc41942108761ef386ee1d2f13..258f2bd0ebe6e429f581f7eee531d2ac00980e15 100755 (executable)
@@ -97,7 +97,7 @@ findmediamount() {
                                then
                                        continue
                                fi
-                               good_msg "Attempting to mount media:- ${x}" ${CRYPT_SILENT}
+                               good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT}
 
                                mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1
                                if [ "$?" = '0' ]
@@ -149,7 +149,7 @@ devicelist(){
        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 -r '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)"
+       [ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)"
        echo ${DEVICES}
 }
 
@@ -191,12 +191,11 @@ cache_cd_contents() {
                        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
@@ -299,7 +298,7 @@ run_shell() {
        /bin/ash
 }
 
-runmdev() {
+mount_devfs () {
        # Use devtmpfs if enabled in kernel,
        # else tmpfs. Always run mdev just in case
        devfs=tmpfs
@@ -314,7 +313,6 @@ runmdev() {
        # http://git.busybox.net/busybox/plain/docs/mdev.txt
        mkdir -m 0755 /dev/pts
        mount -t devpts -o gid=5,mode=0620 devpts /dev/pts  || bad_msg "Failed to mount /dev/pts"
-       mdev -s  || bad_msg "Failed to receive dynamic updates from mdev"
 }
 
 test_success() {
@@ -406,13 +404,6 @@ prompt_user(){
        esac
 }
 
-setup_hotplug() {
-       if [ "${KV_2_6_OR_GREATER}" ]
-       then
-               echo /sbin/mdev > /proc/sys/kernel/hotplug
-       fi
-}
-
 setup_slowusb() {
        # This function removes unset DO_slowusb if there is no usb-storage attached.
        # If noslowusb is set, skip this function
@@ -434,16 +425,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
@@ -576,6 +557,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 ]
@@ -586,7 +568,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
@@ -617,7 +599,12 @@ startVolumes() {
        
        if [ "${USE_MDADM}" = '1' ]
        then
-               /sbin/mdadm --assemble --scan
+               if [ -e '/sbin/mdadm' ]
+               then
+                       /sbin/mdadm --assemble --scan
+               else
+                       bad_msg "mdadm not found: skipping mdadm raid assembly!"
+               fi
        fi
 
        if [ "${USE_DMRAID_NORMAL}" = '1' ]
@@ -664,6 +651,40 @@ startVolumes() {
                        bad_msg "vgscan or vgchange not found: skipping LVM volume group activation!"
                fi
        fi
+       
+       if [ "${USE_ZFS}" = '1' ]
+       then
+               if [ -z "${ZFS_POOL}" ]
+               then
+                       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"
+                       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() {
@@ -780,7 +801,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
 
@@ -875,7 +896,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
@@ -995,12 +1022,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
 }
 
@@ -1194,19 +1225,39 @@ get_mounts_list()
                ' ${NEW_ROOT}/etc/initramfs.mounts
 }
 
-get_mount_options()
+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'
+}