diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/functions | 205 | ||||
-rwxr-xr-x | scripts/init-premount/thermal | 37 | ||||
-rwxr-xr-x | scripts/init-top/all_generic_ide | 4 | ||||
-rwxr-xr-x | scripts/init-top/blacklist (renamed from scripts/init-premount/blacklist) | 2 | ||||
-rwxr-xr-x | scripts/init-top/framebuffer | 102 | ||||
-rw-r--r-- | scripts/local | 62 | ||||
-rwxr-xr-x | scripts/local-premount/resume | 29 | ||||
-rwxr-xr-x | scripts/local-top/lvm | 74 | ||||
-rw-r--r-- | scripts/nfs | 17 |
9 files changed, 223 insertions, 309 deletions
diff --git a/scripts/functions b/scripts/functions index f715e68..419203a 100644 --- a/scripts/functions +++ b/scripts/functions @@ -42,6 +42,11 @@ panic() if [ -x /sbin/usplash_write ]; then /sbin/usplash_write "QUIT" fi + + if command -v chvt >/dev/null 2>&1; then + chvt 1 + fi + # Disallow console access if [ -n "${panic}" ]; then sleep ${panic} @@ -49,8 +54,8 @@ panic() fi modprobe i8042 modprobe atkbd - echo $@ - PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1 + echo "$@" + REASON="$@" PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1 } maybe_break() @@ -74,7 +79,7 @@ set_initlist() # only allow variable name chars case ${si_x#${initdir}/} in - *[![:alnum:]_]*) + *[![:alnum:]\._-]*) [ "${verbose}" = "y" ] \ && echo "$si_x ignored: not alphanumeric or '_' file" continue @@ -95,7 +100,14 @@ set_initlist() continue fi - initlist="${initlist} ${si_x#${initdir}/}" + # skip bad syntax + if ! sh -n ${si_x} ; then + [ "${verbose}" = "y" ] \ + && echo "$si_x ignored: bad syntax" + continue + fi + + initlist="${initlist:-} ${si_x#${initdir}/}" done } @@ -106,18 +118,17 @@ reduce_satisfied() for rs_y in ${deplist}; do # only allow variable name chars case ${rs_y} in - *[![:alnum:]_]*) + *[![:alnum:]\._-]*) continue ;; esac # skip non executable scripts - if [ ! -x ${initdir}/${rs_y} ]; then - continue - fi + [ ! -x ${initdir}/${rs_y} ] && continue # skip directories - if [ -d ${initdir}/${rs_y} ]; then - continue - fi + [ -d ${initdir}/${rs_y} ] && continue + # skip bad syntax + sh -n ${initdir}/${rs_y} || continue + tmpdeplist="${tmpdeplist} ${rs_y}" done deplist=${tmpdeplist} @@ -186,28 +197,57 @@ reduce_prereqs() done } +get_prereq_pairs() +{ + set_initlist + for gp_x in ${initlist:-}; do + echo ${gp_x} ${gp_x} + prereqs=$(${initdir}/${gp_x} prereqs) + for prereq in ${prereqs}; do + echo ${prereq} ${gp_x} + done + done +} + call_scripts() { + set -e for cs_x in ${runlist}; do + [ -f ${initdir}/${cs_x} ] || continue # mkinitramfs verbose output if [ "${verbose}" = "y" ]; then echo "Calling hook ${cs_x}" fi - ${initdir}/${cs_x} - # allow boot scripts to modify exported boot paramaters + ${initdir}/${cs_x} && ec=$? || ec=$? + # allow hooks to abort build: + if [ "$ec" -ne 0 ]; then + echo "E: ${initdir}/${cs_x} failed with return $ec." + # only errexit on mkinitramfs + [ -n "${version}" ] && exit $ec + fi + # allow boot scripts to modify exported boot parameters if [ -e /conf/param.conf ]; then . /conf/param.conf fi done + set +e } run_scripts() { initdir=${1} [ ! -d ${initdir} ] && return - get_prereqs - reduce_prereqs - call_scripts + + if [ -f ${initdir}/ORDER ]; then + . ${initdir}/ORDER + elif command -v tsort >/dev/null 2>&1; then + runlist=$(get_prereq_pairs | tsort) + call_scripts ${2:-} + else + get_prereqs + reduce_prereqs + call_scripts + fi } # Load custom modules first @@ -256,47 +296,122 @@ parse_numeric() { ROOT=/dev/root } +# Parameter: device node to check +# Echos fstype to stdout +# Return value: indicates if an fs could be recognized +get_fstype () +{ + local FS FSTYPE FSSIZE RET + FS="${1}" + + # blkid has a more complete list of file systems, + # but fstype is more robust + eval $(fstype "${FS}" 2> /dev/null) + if [ "$FSTYPE" = "unknown" ] && command -v blkid >/dev/null 2>&1 ; then + FSTYPE=$(blkid -o value -s TYPE "${FS}") + elif [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then + FSTYPE=$(/lib/udev/vol_id -t "${FS}" 2> /dev/null) + fi + RET=$? + + if [ -z "${FSTYPE}" ]; then + FSTYPE="unknown" + fi + + echo "${FSTYPE}" + return ${RET} +} + configure_networking() { + if [ -n "${BOOTIF}" ]; then + # pxelinux sets BOOTIF to a value based on the mac address of the + # network card used to PXE boot, so use this value for DEVICE rather + # than a hard-coded device name from initramfs.conf. this facilitates + # network booting when machines may have multiple network cards. + # pxelinux sets BOOTIF to 01-$mac_address + + # strip off the leading "01-", which isn't part of the mac + # address + temp_mac=${BOOTIF#*-} + + # convert to typical mac address format by replacing "-" with ":" + bootif_mac="" + IFS='-' + for x in $temp_mac ; do + if [ -z "$bootif_mac" ]; then + bootif_mac="$x" + else + bootif_mac="$bootif_mac:$x" + fi + done + unset IFS + + # look for devices with matching mac address, and set DEVICE to + # appropriate value if match is found. + for device in /sys/class/net/* ; do + if [ -f "$device/address" ]; then + current_mac=$(cat "$device/address") + if [ "$bootif_mac" = "$current_mac" ]; then + DEVICE=${device##*/} + break + fi + fi + done + fi + # networking already configured thus bail out [ -n "${DEVICE}" ] && [ -e /tmp/net-"${DEVICE}".conf ] && return 0 # support ip options see linux sources # Documentation/filesystems/nfsroot.txt - case ${IPOPTS} in - none|off) - # Do nothing - ;; - ""|on|any) - # Bring up device - ipconfig -t 180 ${DEVICE} - ;; - dhcp|bootp|rarp|both) - ipconfig -t 180 -c ${IPOPTS} -d ${DEVICE} - ;; - *) - ipconfig -t 180 -d $IPOPTS - - # grab device entry from ip option - NEW_DEVICE=${IPOPTS#*:*:*:*:*:*} - if [ "${NEW_DEVICE}" != "${IPOPTS}" ]; then - NEW_DEVICE=${NEW_DEVICE%:*} - else - # wrong parse, possibly only a partial string - NEW_DEVICE= - fi - if [ -n "${NEW_DEVICE}" ]; then - DEVICE="${NEW_DEVICE}" - fi - ;; - esac + # Documentation/frv/booting.txt + + for ROUNDTTT in 2 3 4 6 9 16 25 36 64 100; do + + # The NIC is to be configured if this file does not exist. + # Ip-Config tries to create this file and when it succeds + # creating the file, ipconfig is not run again. + for x in /tmp/net-"${DEVICE}".conf /tmp/net-*.conf ; do + [ -e "$x" ] && break 2 + done + + case ${IP} in + none|off) + # Do nothing + ;; + ""|on|any) + # Bring up device + ipconfig -t ${ROUNDTTT} "${DEVICE}" + ;; + dhcp|bootp|rarp|both) + ipconfig -t ${ROUNDTTT} -c ${IP} -d "${DEVICE}" + ;; + *) + ipconfig -t ${ROUNDTTT} -d $IP + + # grab device entry from ip option + NEW_DEVICE=${IP#*:*:*:*:*:*} + if [ "${NEW_DEVICE}" != "${IP}" ]; then + NEW_DEVICE=${NEW_DEVICE%:*} + else + # wrong parse, possibly only a partial string + NEW_DEVICE= + fi + if [ -n "${NEW_DEVICE}" ]; then + DEVICE="${NEW_DEVICE}" + fi + ;; + esac + done # source ipconfig output if [ -n "${DEVICE}" ]; then # source specific bootdevice . /tmp/net-${DEVICE}.conf else - # source any interface as not exaclty specified + # source any interface... + # ipconfig should have quit after first response . /tmp/net-*.conf fi } @@ -304,6 +419,6 @@ configure_networking() # Wait for queued kernel/udev events wait_for_udev() { - [ -x "$(command -v udevadm)" ] || return 0 + command -v udevadm >/dev/null 2>&1 || return 0 udevadm settle ${1:+--timeout=$1} } diff --git a/scripts/init-premount/thermal b/scripts/init-premount/thermal deleted file mode 100755 index aa146ec..0000000 --- a/scripts/init-premount/thermal +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -PREREQ="" - -prereqs() -{ - echo "$PREREQ" -} - -case $1 in -# get pre-requisites -prereqs) - prereqs - exit 0 - ;; -esac - -case "$DPKG_ARCH" in -# load the right modules -powerpc|ppc64) - modprobe i2c-powermac - modprobe therm_pm72 - modprobe windfarm_cpufreq_clamp - modprobe windfarm_lm75_sensor - modprobe windfarm_max6690_sensor - modprobe windfarm_pm112 - modprobe windfarm_pm81 - modprobe windfarm_pm91 - modprobe windfarm_smu_controls - modprobe windfarm_smu_sat - modprobe windfarm_smu_sensors - ;; -i386|amd64|ia64) - modprobe fan - modprobe thermal - ;; -esac diff --git a/scripts/init-top/all_generic_ide b/scripts/init-top/all_generic_ide index 3274ee8..e9539d8 100755 --- a/scripts/init-top/all_generic_ide +++ b/scripts/init-top/all_generic_ide @@ -16,11 +16,11 @@ esac for x in $(cat /proc/cmdline); do case ${x} in all_generic_ide) - modprobe ide-generic + modprobe ata_generic all_generic_ide=1 ;; all_generic_ide=*) if [ ${x#all_generic_ide=} ]; then - modprobe ide-generic + modprobe ata_generic all_generic_ide=1 fi ;; esac diff --git a/scripts/init-premount/blacklist b/scripts/init-top/blacklist index 1dd9dbc..2164906 100755 --- a/scripts/init-premount/blacklist +++ b/scripts/init-top/blacklist @@ -21,5 +21,5 @@ esac # write blacklist to modprobe.d IFS=',' for b in ${blacklist}; do - echo "blacklist $b" >> /etc/modprobe.d/initramfs + echo "blacklist $b" >> /etc/modprobe.d/initramfs.conf done diff --git a/scripts/init-top/framebuffer b/scripts/init-top/framebuffer deleted file mode 100755 index 0ed798e..0000000 --- a/scripts/init-top/framebuffer +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/sh - -PREREQ="" -prereqs() -{ - echo "$PREREQ" -} -case $1 in -# get pre-requisites -prereqs) - prereqs - exit 0 - ;; -esac - - -# The options part of the kernel "video=" argument (i.e. everyting -# after "video=<fbdriver>:") has very inconsistent rules. -# -# Generally the following applies: -# 1) options are comma-separated -# 2) options can be in either of these three forms: -# <arg>=<value>, <arg>:<value>, <boolean-arg>. -# 3) the "mode" option has the form <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] -# and may or may not start with "mode=" -# -# When the options are used with modules, they need to be space-separated -# and the following conversions are needed: -# <arg>:<value> -> <arg>=<value> -# <boolean-arg> -> <boolean-arg>=1 -# <modevalue> -> mode=<modevalue> -parse_video_opts() -{ - local OPTS="$1" - local IFS="," - - # Must be a line like video=<fbdriver>:<opt1>,[opt2]... - if [ "${OPTS}" = "${OPTS%%:*}" ]; then - return - fi - OPTS="${OPTS#*:}" - for opt in ${OPTS}; do - # Already in the "<arg>=<value>" form - if [ "${opt}" != "${opt#*=}" ]; then - echo -n "$opt " - # In the "<arg>:<value>" form - elif [ "${opt}" != "${opt#*:}" ]; then - echo -n "${opt%:*}=${opt#*:} " - # Presumably a modevalue without the "mode=" prefix - elif [ "${opt}" != "${opt#[0-9]*x[0-9]}" ]; then - echo -n "mode=$opt " - # Presumably a boolean - else - echo -n "${opt}=1 " - fi - done -} - -FB="" -OPTS="" - -for x in $(cat /proc/cmdline); do - case ${x} in - vga=*) - FB="vesafb"; - OPTS=""; - ;; - video=*) - FB=${x#*=} - FB="${FB%%:*}" - OPTS="$(parse_video_opts "${x}")" - esac -done - -# Map command line name to module name and other tweaks -case ${FB} in -matroxfb) - FB=matroxfb_base - ;; -uvesafb) - # v86d requires /dev/zero and dev/mem, but udev haven't been started yet - [ -e /dev/zero ] || mknod -m 0666 /dev/zero c 1 5 - [ -e /dev/mem ] || mknod -m 0640 /dev/mem c 1 1 - ;; -*) - ;; -esac - -if [ -n "${FB}" ]; then - modprobe fbcon - modprobe ${FB} ${OPTS} -fi - -if [ -e /proc/fb ]; then - while read fbno desc; do - if [ $(($fbno < 32)) ]; then - mknod -m 0640 /dev/fb${fbno} c 29 ${fbno} - fi - done < /proc/fb -else - mknod -m 0640 /dev/fb0 c 29 0 -fi diff --git a/scripts/local b/scripts/local index 85d62af..8cb279a 100644 --- a/scripts/local +++ b/scripts/local @@ -1,31 +1,6 @@ # Local filesystem mounting -*- shell-script -*- -# Parameter: device node to check -# Echos fstype to stdout -# Return value: indicates if an fs could be recognized -get_fstype () -{ - local FS FSTYPE FSSIZE RET - FS="${1}" - - # vol_id has a more complete list of file systems, - # but fstype is more robust - eval $(fstype "${FS}" 2> /dev/null) - if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then - FSTYPE=$(/lib/udev/vol_id -t "${FS}" 2> /dev/null) - fi - RET=$? - - if [ -z "${FSTYPE}" ]; then - FSTYPE="unknown" - fi - - echo "${FSTYPE}" - return ${RET} -} - -# Parameter: Where to mount the filesystem -mountroot () +pre_mountroot() { [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top" run_scripts /scripts/local-top @@ -33,17 +8,27 @@ mountroot () wait_for_udev 10 + # Load ubi with the correct MTD partition and return since fstype + # doesn't work with a char device like ubi. + if [ -n "$UBIMTD" ]; then + modprobe ubi mtd=$UBIMTD + return + fi + + # Don't wait for a root device that doesn't have a corresponding + # device in /dev (ie, mtd0) + if [ "${ROOT#/dev}" = "${ROOT}" ]; then + return + fi + # If the root device hasn't shown up yet, give it a little while # to deal with removable devices if [ ! -e "${ROOT}" ] || ! $(get_fstype "${ROOT}" >/dev/null); then log_begin_msg "Waiting for root file system" - # Default delay is 180s - if [ -z "${ROOTDELAY}" ]; then - slumber=180 - else - slumber=${ROOTDELAY} - fi + # Default delay is 30s + slumber=${ROOTDELAY:-30} + if [ -x /sbin/usplash_write ]; then /sbin/usplash_write "TIMEOUT ${slumber}" || true fi @@ -69,7 +54,7 @@ mountroot () # We've given up, but we'll let the user fix matters if they can while [ ! -e "${ROOT}" ]; do # give hint about renamed root - case "${ROOT}" in + case "${ROOT}" in /dev/hd*) suffix="${ROOT#/dev/hd}" major="${suffix%[[:digit:]]}" @@ -94,6 +79,11 @@ mountroot () echo " - Missing modules (cat /proc/modules; ls /dev)" panic "ALERT! ${ROOT} does not exist. Dropping to a shell!" done +} + +mountroot() +{ + pre_mountroot # Get the root filesystem type if not set if [ -z "${ROOTFSTYPE}" ]; then @@ -117,7 +107,11 @@ mountroot () # FIXME This has no error checking # Mount root - mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt} + if [ "${FSTYPE}" != "unknown" ]; then + mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt} + else + mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt} + fi [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom" run_scripts /scripts/local-bottom diff --git a/scripts/local-premount/resume b/scripts/local-premount/resume index 6bf95e5..11acfc7 100755 --- a/scripts/local-premount/resume +++ b/scripts/local-premount/resume @@ -20,10 +20,33 @@ if [ -z "${resume}" ]; then fi case $resume in - LABEL=*) - resume="/dev/disk/by-label/${resume#LABEL=}" +LABEL=*) + resume="${resume#LABEL=}" + + # support any / in LABEL= path (escape to \x2f) + case "${resume}" in + */*) + if command -v sed >/dev/null 2>&1; then + resume="$(echo ${resume} | sed 's,/,\\x2f,g')" + else + if [ "${resume}" != "${resume#/}" ]; then + resume="\x2f${resume#/}" + fi + if [ "${resume}" != "${resume%/}" ]; then + resume="${resume%/}\x2f" + fi + IFS='/' + newresume= + for s in $resume; do + newresume="${newresume:+${newresume}\\x2f}${s}" + done + unset IFS + resume="${newresume}" + fi + esac + resume="/dev/disk/by-label/${resume}" ;; - UUID=*) +UUID=*) resume="/dev/disk/by-uuid/${resume#UUID=}" ;; esac diff --git a/scripts/local-top/lvm b/scripts/local-top/lvm deleted file mode 100755 index 4cf48ad..0000000 --- a/scripts/local-top/lvm +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh - -PREREQ="mdadm mdrun lvm2" - -prereqs() -{ - echo "$PREREQ" -} - -case $1 in -# get pre-requisites -prereqs) - prereqs - exit 0 - ;; -esac - -activate_vg() -{ - local vg="$1" - - # Make sure that we have a non-empty argument - if [ -z "${vg}" ]; then - return 1 - fi - - # Take care of lilo boot arg, risky activating of all vg - case $vg in - fe[0-9]*) - vgchange -ay - exit 0 - ;; - # FIXME: check major - /dev/root) - vgchange -ay - exit 0 - ;; - esac - - # Make sure that we have a d-m path - vg=${vg#/dev/mapper/} - if [ "$vg" = "$1" ]; then - return 1 - fi - - # Make sure that the device includes at least one dash - if [ "$(echo -n "$vg" | tr -d -)" = "$vg" ]; then - return 1 - fi - - # Split volume group from logical volume. - vg=$(echo ${vg} | sed -e 's#\(.*\)\([^-]\)-[^-].*#\1\2#') - # Reduce padded --'s to -'s - vg=$(echo ${vg} | sed -e 's#--#-#g') - - vgchange -ay ${vg} -} - -if [ -e /scripts/local-top/lvm2 ]; then - exit 0 -fi - -if [ ! -e /sbin/vgchange ]; then - exit 0 -fi - -modprobe dm-mod -modprobe dm-snapshot -modprobe dm-mirror - -activate_vg "$ROOT" -activate_vg "$resume" - -exit 0 diff --git a/scripts/nfs b/scripts/nfs index 435d2d0..6fa0c43 100644 --- a/scripts/nfs +++ b/scripts/nfs @@ -4,7 +4,7 @@ retry_nr=0 -# parse nfs bootargs and mount nfs +# parse nfs bootargs and mount nfs do_nfsmount() { @@ -62,21 +62,16 @@ mountroot() wait_for_udev 10 # Default delay is around 180s - # FIXME: add usplash_write info - if [ -z "${ROOTDELAY}" ]; then - delay=180 - else - delay=${ROOTDELAY} - fi + delay=${ROOTDELAY:-180} - # loop until nfsmount succeds + # loop until nfsmount succeeds + do_nfsmount while [ ${retry_nr} -lt ${delay} ] && [ ! -e ${rootmnt}${init} ]; do - [ ${retry_nr} -gt 0 ] && \ [ "$quiet" != "y" ] && log_begin_msg "Retrying nfs mount" + /bin/sleep 1 do_nfsmount retry_nr=$(( ${retry_nr} + 1 )) - [ ! -e ${rootmnt}${init} ] && /bin/sleep 1 - [ ${retry_nr} -gt 0 ] && [ "$quiet" != "y" ] && log_end_msg + [ "$quiet" != "y" ] && log_end_msg done [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-bottom" |