diff options
author | rbalocca <rbalocca@vyatta.com> | 2008-10-28 14:49:35 -0700 |
---|---|---|
committer | rbalocca <rbalocca@vyatta.com> | 2008-10-28 14:49:35 -0700 |
commit | 3939e96a8830755228bd2bbedb50db6808d36f80 (patch) | |
tree | 6c55ccb42447ad90946ee6157dab49e573ec92d2 /scripts | |
download | initramfs-tools-3939e96a8830755228bd2bbedb50db6808d36f80.tar.gz initramfs-tools-3939e96a8830755228bd2bbedb50db6808d36f80.zip |
initramfs-tools-0.92j from mirrrors.kernel.orgdebian/0.92j
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/functions | 308 | ||||
-rwxr-xr-x | scripts/init-premount/blacklist | 25 | ||||
-rwxr-xr-x | scripts/init-premount/thermal | 37 | ||||
-rwxr-xr-x | scripts/init-top/all_generic_ide | 22 | ||||
-rwxr-xr-x | scripts/init-top/framebuffer | 87 | ||||
-rwxr-xr-x | scripts/init-top/keymap | 27 | ||||
-rw-r--r-- | scripts/local | 125 | ||||
-rwxr-xr-x | scripts/local-premount/resume | 40 | ||||
-rwxr-xr-x | scripts/local-top/lvm | 74 | ||||
-rw-r--r-- | scripts/nfs | 85 |
10 files changed, 830 insertions, 0 deletions
diff --git a/scripts/functions b/scripts/functions new file mode 100644 index 0000000..299c29c --- /dev/null +++ b/scripts/functions @@ -0,0 +1,308 @@ +# -*- shell-script -*- + +_log_msg() +{ + if [ "$quiet" = "y" ]; then return; fi + printf "$@" +} + +log_success_msg() +{ + _log_msg "Success: $@\n" +} + +log_failure_msg() +{ + _log_msg "Failure: $@\n" +} + +log_warning_msg() +{ + _log_msg "Warning: $@\n" +} + +log_begin_msg() +{ + if [ -x /sbin/usplash_write ]; then + /sbin/usplash_write "TEXT $@" + fi + _log_msg "Begin: $@ ... " +} + +log_end_msg() +{ + if [ -x /sbin/usplash_write ]; then + /sbin/usplash_write "SUCCESS ok" + fi + _log_msg "done.\n" +} + +panic() +{ + if [ -x /sbin/usplash_write ]; then + /sbin/usplash_write "QUIT" + fi + # Disallow console access + if [ -n "${panic}" ]; then + sleep ${panic} + reboot + fi + modprobe i8042 + modprobe atkbd + echo $@ + PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1 +} + +maybe_break() +{ + if [ "${break}" = "$1" ]; then + panic "Spawning shell within the initramfs" + fi +} + +render() +{ + eval "echo -n \${$@}" +} + +set_initlist() +{ + unset initlist + for si_x in ${initdir}/*; do + # skip empty dirs without warning + [ "${si_x}" = "${initdir}/*" ] && return + + # only allow variable name chars + case ${si_x#${initdir}/} in + *[![:alnum:]_]*) + [ "${verbose}" = "y" ] \ + && echo "$si_x ignored: not alphanumeric or '_' file" + continue + ;; + esac + + # skip non executable scripts + if [ ! -x ${si_x} ]; then + [ "${verbose}" = "y" ] \ + && echo "$si_x ignored: not executable" + continue + fi + + # skip directories + if [ -d ${si_x} ]; then + [ "${verbose}" = "y" ] \ + && echo "$si_x ignored: a directory" + continue + fi + + initlist="${initlist} ${si_x#${initdir}/}" + done +} + +reduce_satisfied() +{ + deplist="$(render array_${1})" + unset tmpdeplist + for rs_y in ${deplist}; do + # only allow variable name chars + case ${rs_y} in + *[![:alnum:]_]*) + continue + ;; + esac + # skip non executable scripts + if [ ! -x ${initdir}/${rs_y} ]; then + continue + fi + # skip directories + if [ -d ${initdir}/${rs_y} ]; then + continue + fi + tmpdeplist="${tmpdeplist} ${rs_y}" + done + deplist=${tmpdeplist} + for rs_x in ${runlist}; do + pop_list_item ${rs_x} ${deplist} + deplist=${tmppop} + done + eval array_${1}=\"${deplist}\" +} + +get_prereqs() +{ + set_initlist + for gp_x in ${initlist}; do + tmp=$(${initdir}/${gp_x} prereqs) + eval array_${gp_x}=\"${tmp}\" + done +} + +count_unsatisfied() +{ + set -- ${@} + return ${#} +} + +# Removes $1 from initlist +pop_list_item() +{ + item=${1} + shift + set -- ${@} + unset tmppop + # Iterate + for pop in ${@}; do + if [ ${pop} = ${item} ]; then + continue + fi + tmppop="${tmppop} ${pop}" + done + +} + +# This function generates the runlist, so we clear it first. +reduce_prereqs() +{ + unset runlist + set -- ${initlist} + i=$# + # Loop until there's no more in the queue to loop through + while [ ${i} -ne 0 ]; do + oldi=${i} + for rp_x in ${initlist}; do + reduce_satisfied ${rp_x} + count_unsatisfied $(render array_${rp_x}) + cnt=${?} + if [ ${cnt} -eq 0 ]; then + runlist="${runlist} ${rp_x}" + pop_list_item ${rp_x} ${initlist} + initlist=${tmppop} + i=$((${i} - 1)) + fi + done + if [ ${i} -eq ${oldi} ]; then + panic "PANIC: Circular dependancy. Exiting." + fi + done +} + +call_scripts() +{ + for cs_x in ${runlist}; do + # mkinitramfs verbose output + if [ "${verbose}" = "y" ]; then + echo "Calling hook ${cs_x}" + fi + ${initdir}/${cs_x} + # allow boot scripts to modify exported boot paramaters + if [ -e /conf/param.conf ]; then + . /conf/param.conf + fi + done +} + +run_scripts() +{ + initdir=${1} + [ ! -d ${initdir} ] && return + get_prereqs + reduce_prereqs + call_scripts +} + +# Load custom modules first +load_modules() +{ + if [ -e /conf/modules ]; then + cat /conf/modules | while read m; do + # Skip empty lines + if [ -z "$m" ]; then + continue + fi + # Skip comments - d?ash removes whitespace prefix + com=$(printf "%.1s" "${m}") + if [ "$com" = "#" ]; then + continue + fi + modprobe $m + done + fi +} + +# lilo compatibility +parse_numeric() { + case $1 in + "") + return + ;; + /*) + return + ;; + *:*) + minor=${1#*:} + major=${1%:*} + ;; + [A-Fa-f0-9]*) + value=$(( 0x${1} )) + minor=$(( ${value} % 256 )) + major=$(( ${value} / 256 )) + ;; + *) + return + ;; + esac + + mknod -m 600 /dev/root b ${major} ${minor} + ROOT=/dev/root +} + +configure_networking() +{ + # networking already configured thus bail out + [ -n "${DEVICE}" ] && [ -e /tmp/net-"${DEVICE}".conf ] && return 0 + + # support ip options see linux sources Documentation/nfsroot.txt + case ${IPOPTS} in + none|off) + # Do nothing + ;; + ""|on|any) + # Bring up device + ipconfig ${DEVICE} + ;; + dhcp|bootp|rarp|both) + ipconfig -c ${IPOPTS} -d ${DEVICE} + ;; + *) + ipconfig -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 + + # source ipconfig output + if [ -n "${DEVICE}" ]; then + # source specific bootdevice + . /tmp/net-${DEVICE}.conf + else + # source any interface as not exaclty specified + . /tmp/net-*.conf + fi +} + +# Wait for queued kernel/udev events +wait_for_udev() +{ + [ -x "$(command -v udevadm)" ] && return 0 + udevadm settle ${1:+--timeout=$1} +} diff --git a/scripts/init-premount/blacklist b/scripts/init-premount/blacklist new file mode 100755 index 0000000..1dd9dbc --- /dev/null +++ b/scripts/init-premount/blacklist @@ -0,0 +1,25 @@ +#!/bin/sh + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +# sanity check +[ -z "${blacklist}" ] && exit 0 + +# write blacklist to modprobe.d +IFS=',' +for b in ${blacklist}; do + echo "blacklist $b" >> /etc/modprobe.d/initramfs +done diff --git a/scripts/init-premount/thermal b/scripts/init-premount/thermal new file mode 100755 index 0000000..aa146ec --- /dev/null +++ b/scripts/init-premount/thermal @@ -0,0 +1,37 @@ +#!/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 new file mode 100755 index 0000000..28b519a --- /dev/null +++ b/scripts/init-top/all_generic_ide @@ -0,0 +1,22 @@ +#!/bin/sh + +PREREQ="" +prereqs() +{ + echo "$PREREQ" +} +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +for x in $(cat /proc/cmdline); do + case ${x} in + all_generic_ide) + modprobe ide-generic + ;; + esac +done diff --git a/scripts/init-top/framebuffer b/scripts/init-top/framebuffer new file mode 100755 index 0000000..21a6b19 --- /dev/null +++ b/scripts/init-top/framebuffer @@ -0,0 +1,87 @@ +#!/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 +case ${FB} in +matroxfb) + FB=matroxfb_base + ;; +*) + ;; +esac + +if [ -n "${FB}" ]; then + modprobe fbcon + modprobe ${FB} ${OPTS} +fi diff --git a/scripts/init-top/keymap b/scripts/init-top/keymap new file mode 100755 index 0000000..f011abf --- /dev/null +++ b/scripts/init-top/keymap @@ -0,0 +1,27 @@ +#!/bin/sh + +PREREQ="" +prereqs() +{ + echo "$PREREQ" +} +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +OPTS="-q" + +# Should terminal be in UTF8 mode? +if [ -x /bin/kbd_mode ]; then + /bin/kbd_mode -u + OPTS="${OPTS} -u" +fi + +# Load custom keymap +if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]; then + loadkeys ${OPTS} /etc/boottime.kmap.gz +fi diff --git a/scripts/local b/scripts/local new file mode 100644 index 0000000..85d62af --- /dev/null +++ b/scripts/local @@ -0,0 +1,125 @@ +# 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 () +{ + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top" + run_scripts /scripts/local-top + [ "$quiet" != "y" ] && log_end_msg + + wait_for_udev 10 + + # 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 + if [ -x /sbin/usplash_write ]; then + /sbin/usplash_write "TIMEOUT ${slumber}" || true + fi + + slumber=$(( ${slumber} * 10 )) + while [ ! -e "${ROOT}" ] \ + || ! $(get_fstype "${ROOT}" >/dev/null); do + /bin/sleep 0.1 + slumber=$(( ${slumber} - 1 )) + [ ${slumber} -gt 0 ] || break + done + + if [ ${slumber} -gt 0 ]; then + log_end_msg 0 + else + log_end_msg 1 || true + fi + if [ -x /sbin/usplash_write ]; then + /sbin/usplash_write "TIMEOUT 15" || true + fi + fi + + # 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 + /dev/hd*) + suffix="${ROOT#/dev/hd}" + major="${suffix%[[:digit:]]}" + major="${major%[[:digit:]]}" + if [ -d "/sys/block/sd${major}" ]; then + echo "WARNING bootdevice may be renamed. Try root=/dev/sd${suffix}" + fi + ;; + /dev/sd*) + suffix="${ROOT#/dev/sd}" + major="${suffix%[[:digit:]]}" + major="${major%[[:digit:]]}" + if [ -d "/sys/block/hd${major}" ]; then + echo "WARNING bootdevice may be renamed. Try root=/dev/hd${suffix}" + fi + ;; + esac + echo "Gave up waiting for root device. Common problems:" + echo " - Boot args (cat /proc/cmdline)" + echo " - Check rootdelay= (did the system wait long enough?)" + echo " - Check root= (did the system wait for the right device?)" + echo " - Missing modules (cat /proc/modules; ls /dev)" + panic "ALERT! ${ROOT} does not exist. Dropping to a shell!" + done + + # Get the root filesystem type if not set + if [ -z "${ROOTFSTYPE}" ]; then + FSTYPE=$(get_fstype "${ROOT}") + else + FSTYPE=${ROOTFSTYPE} + fi + + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount" + run_scripts /scripts/local-premount + [ "$quiet" != "y" ] && log_end_msg + + if [ "${readonly}" = "y" ]; then + roflag=-r + else + roflag=-w + fi + + # FIXME This has no error checking + modprobe ${FSTYPE} + + # FIXME This has no error checking + # Mount root + mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt} + + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom" + run_scripts /scripts/local-bottom + [ "$quiet" != "y" ] && log_end_msg +} diff --git a/scripts/local-premount/resume b/scripts/local-premount/resume new file mode 100755 index 0000000..6bf95e5 --- /dev/null +++ b/scripts/local-premount/resume @@ -0,0 +1,40 @@ +#!/bin/sh + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +if [ -z "${resume}" ]; then + exit 0 +fi + +case $resume in + LABEL=*) + resume="/dev/disk/by-label/${resume#LABEL=}" + ;; + UUID=*) + resume="/dev/disk/by-uuid/${resume#UUID=}" + ;; +esac + +[ ! -e "${resume}" ] && exit 0 + +[ ! -e /sys/power/resume ] && exit 0 + +# hardcode path, uswsusp ships an resume binary too +if [ -n "${resume_offset}" ]; then + /bin/resume ${resume} ${resume_offset} +else + /bin/resume ${resume} +fi diff --git a/scripts/local-top/lvm b/scripts/local-top/lvm new file mode 100755 index 0000000..4cf48ad --- /dev/null +++ b/scripts/local-top/lvm @@ -0,0 +1,74 @@ +#!/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 new file mode 100644 index 0000000..435d2d0 --- /dev/null +++ b/scripts/nfs @@ -0,0 +1,85 @@ +# NFS filesystem mounting -*- shell-script -*- + +# FIXME This needs error checking + +retry_nr=0 + +# parse nfs bootargs and mount nfs +do_nfsmount() +{ + + configure_networking + + # get nfs root from dhcp + if [ "x${NFSROOT}" = "xauto" ]; then + # check if server ip is part of dhcp root-path + if [ "${ROOTPATH#*:}" = "${ROOTPATH}" ]; then + NFSROOT=${ROOTSERVER}:${ROOTPATH} + else + NFSROOT=${ROOTPATH} + fi + + # nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>] + elif [ -n "${NFSROOT}" ]; then + # nfs options are an optional arg + if [ "${NFSROOT#*,}" != "${NFSROOT}" ]; then + NFSOPTS="-o ${NFSROOT#*,}" + fi + NFSROOT=${NFSROOT%%,*} + if [ "${NFSROOT#*:}" = "$NFSROOT" ]; then + NFSROOT=${ROOTSERVER}:${NFSROOT} + fi + fi + + if [ -z "${NFSOPTS}" ]; then + NFSOPTS="-o retrans=10" + fi + + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-premount" + run_scripts /scripts/nfs-premount + [ "$quiet" != "y" ] && log_end_msg + + if [ ${readonly} = y ]; then + roflag="-o ro" + else + roflag="-o rw" + fi + + nfsmount -o nolock ${roflag} ${NFSOPTS} ${NFSROOT} ${rootmnt} +} + +# NFS root mounting +mountroot() +{ + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-top" + run_scripts /scripts/nfs-top + [ "$quiet" != "y" ] && log_end_msg + + modprobe nfs + # For DHCP + modprobe af_packet + + wait_for_udev 10 + + # Default delay is around 180s + # FIXME: add usplash_write info + if [ -z "${ROOTDELAY}" ]; then + delay=180 + else + delay=${ROOTDELAY} + fi + + # loop until nfsmount succeds + while [ ${retry_nr} -lt ${delay} ] && [ ! -e ${rootmnt}${init} ]; do + [ ${retry_nr} -gt 0 ] && \ + [ "$quiet" != "y" ] && log_begin_msg "Retrying nfs mount" + do_nfsmount + retry_nr=$(( ${retry_nr} + 1 )) + [ ! -e ${rootmnt}${init} ] && /bin/sleep 1 + [ ${retry_nr} -gt 0 ] && [ "$quiet" != "y" ] && log_end_msg + done + + [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/nfs-bottom" + run_scripts /scripts/nfs-bottom + [ "$quiet" != "y" ] && log_end_msg +} |