X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=defaults%2Finitrd.scripts;h=258f2bd0ebe6e429f581f7eee531d2ac00980e15;hb=51dcb157423d660f652e44a795cfb9a51724ad1e;hp=4a12b73ed44abd4a5c45e435ea7bb158d1c574ea;hpb=5a33ee4b485a902051beeece531d1e70b1fa73c0;p=genkernel.git diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 4a12b73..258f2bd 100755 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -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,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 @@ -319,9 +311,8 @@ runmdev() { || bad_msg "Failed to mount /dev as ${devfs}" # http://git.busybox.net/busybox/plain/docs/mdev.txt - mkdir /dev/pts - mount -t devpts devpts /dev/pts || bad_msg "Failed to mount /dev/pts" - mdev -s || bad_msg "Failed to receive dynamic updates from mdev" + mkdir -m 0755 /dev/pts + mount -t devpts -o gid=5,mode=0620 devpts /dev/pts || bad_msg "Failed to mount /dev/pts" } test_success() { @@ -370,14 +361,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 @@ -386,7 +379,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="." @@ -411,13 +404,6 @@ whereis(){ 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 @@ -439,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 @@ -581,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 ] @@ -591,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 @@ -622,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' ] @@ -656,30 +638,51 @@ startVolumes() { # To activate volumegroups on all devices in the cache 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 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" + 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 } @@ -757,7 +760,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='' @@ -771,15 +774,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 @@ -798,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 @@ -818,6 +821,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}" ] @@ -876,7 +885,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 -" @@ -887,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 @@ -940,8 +955,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 @@ -961,10 +983,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!" @@ -1000,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 } @@ -1079,10 +1105,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 @@ -1100,6 +1125,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 @@ -1157,7 +1210,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' +}