diff options
author | madduck <madduck@3cfab66f-1918-0410-86b3-c06b76f9a464> | 2006-08-23 14:18:29 +0000 |
---|---|---|
committer | madduck <madduck@3cfab66f-1918-0410-86b3-c06b76f9a464> | 2006-08-23 14:18:29 +0000 |
commit | fdf4826cc6fb9f9894d0761392262c297205253c (patch) | |
tree | de536b14c88e4fcd13f78fe29f5b37248000db1e /debian/initramfs | |
parent | c3a6e42bad58a0f83d43eac7a93f99e88595118a (diff) |
* Improved initramfs hook; now does not rely on initramfs to provide RAID
assembly:
- if a checked mdadm.conf file is present, use that.
- if an unchecked mdadm.conf is present, create a temporary one
- if that fails, use the unchecked one iff it contains at least one
ARRAY statement. Otherwise rely on auto-generation from the initramfs
during the book (and hope for the best).
- if no mdadm.conf is found, create one on the fly
- if that fails, hope that the auto-generation will work during boot
* Improved the messages printed by the initramfs script.
* Do not store the debconf answer for whether arrays not listed in the
configuration file should be used.
* Now asks again for the devices to start (preseeded with 'all') if the user
does not want to proceed with devices not listed in the configuration
file.
Diffstat (limited to 'debian/initramfs')
-rw-r--r-- | debian/initramfs/hook | 155 | ||||
-rw-r--r-- | debian/initramfs/script.local-top | 28 |
2 files changed, 117 insertions, 66 deletions
diff --git a/debian/initramfs/hook b/debian/initramfs/hook index 6f199de1..dee88b3b 100644 --- a/debian/initramfs/hook +++ b/debian/initramfs/hook @@ -43,78 +43,123 @@ MDADM=$(command -v mdadm 2>/dev/null) || : [ -r /usr/share/initramfs-tools/hook-functions ] || exit 0 . /usr/share/initramfs-tools/hook-functions +# copy the binary as early as possible +copy_exec $MDADM /sbin + +# copy all modules into the initramfs, just for safety. +# we copy raid456 / raid5+raid6 because the hook script just won't do +# anything when the module cannot be found. +modules="linear multipath raid0 raid1 raid456 raid5 raid6 raid10" +for mod in $modules; do manual_add_modules $mod; done + +# read in the configuration CONFIG=/etc/mdadm/mdadm.conf ALTCONFIG=/etc/mdadm.conf +[ ! -f $CONFIG ] && [ -f $ALTCONFIG ] && CONFIG=$ALTCONFIG || : + +DEBIANCONFIG=/etc/default/mdadm +INITRDSTART=all +[ -s $DEBIANCONFIG ] && . $DEBIANCONFIG +[ -z "$INITRDSTART" ] && INITRDSTART=none -[ ! -f $CONFIG ] && [ -f $ALTCONFIG ] && CONFIG=$ALTCONFIG +DESTMDADMCONF=$DESTDIR/etc/mdadm/mdadm.conf +DESTCONFIG=$DESTDIR/conf/md.conf + +# save the homehost for now, even if we don't use it yet if [ -f $CONFIG ]; then - if [ -e /var/lib/mdadm/CONF-UNCHECKED ]; then - # the file comes from an old installation and hence is not guaranteed to - # work. We thus refuse to work. + homehost="$(sed -ne 's,^[[:space:]]*HOMEHOST[[:space:]]*,,p' $CONFIG)" +fi +if [ -z "${homehost:-}" ] || [ "${homehost:-}" = '<system>' ]; then + homehost="$(hostname)" +fi +echo "MD_HOMEHOST='$homehost'" > $DESTCONFIG - echo "E: mdadm: unchecked mdadm.conf file found." >&2 - echo "I: mdadm: please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." >&2 - echo "I: mdadm: leaving RAID initialisation to initramfs (mdrun) for now." >&2 - exit 0 - fi +install_config() +{ + # install the configuration file + mkdir -p ${2%/*} + # only copy ARRAY and DEVICE lines, and merge continuation lines into one + sed -e :a -re '$!N;s/\n[[:space:]]+/ /;ta' -ne '/^(ARRAY|DEVICE)/P;D' $1 > $2 +} -else +if [ ! -f $CONFIG ]; then # there is no configuration file, so let's create one + if /usr/share/mdadm/mkconf generate $CONFIG; then + # all is well + install_config $CONFIG $DESTMDADMCONF echo "I: mdadm: auto-generated the mdadm.conf configuration file." >&2 else - echo "E: mdadm: failed to autogenerate the mdadm.conf file." >&2 - echo "I: mdadm: leaving RAID initialisation to initramfs (mdrun) for now." >&2 + # we failed to auto-generate, so remove the file and let the emergency + # procedure take over rm -f $CONFIG - exit 0 + echo "W: mdadm: failed to auto-generate the mdadm.conf file." >&2 + echo "W: mdadm: please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." >&2 fi -fi + +else + + if [ -e /var/lib/mdadm/CONF-UNCHECKED ]; then + # the file comes from an old installation and hence is not guaranteed to + # work. We thus better create one and start all arrays to be sure. + + echo "W: mdadm: unchecked configuration file: $CONFIG" >&2 + echo "W: mdadm: please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." >&2 + + tmpfile="${DESTMDADMCONF}.tmp" + if /usr/share/mdadm/mkconf generate $tmpfile; then + # all is well, we now have a temporary configuration file + echo "I: mdadm: auto-generated temporary mdadm.conf configuration file." >&2 + install_config $tmpfile $DESTMDADMCONF + else + # stuff's really broke, as we failed to generate a temporary file. + # let's hope the unchecked file works, provided it contains at least one + # ARRAY statement... + echo "W: mdadm: failed to auto-generate temporary mdadm.conf file." >&2 + if grep -q '^ARRAY' $CONFIG; then + echo "W: mdadm: using the unchecked file and hoping for the best..." >&2 + install_config $CONFIG $DESTMDADMCONF + else + echo "W: mdadm: no ARRAYs defined in unchecked mdadm.conf, cannot use..." >&2 + fi + fi + rm -f $tmpfile -# install the configuration file -mkdir -p $DESTDIR/etc/mdadm -sed -e :a -re '$!N;s/\n[[:space:]]+/ /;ta' -ne '/^(ARRAY|DEVICE)/P;D' \ - < $CONFIG > $DESTDIR/etc/mdadm/mdadm.conf - -# obtain dev:level pairs from config file, honouring multiline entries -devpairs="$( - while read line; do - for atom in $line; do - case "$atom" in - (/dev*) dev=$atom;; - (level=*) level=${atom#level=};; - (*) :;; - esac - done - [ -n "${dev:-}" ] && echo -n "${dev}:${level} " - done < $DESTDIR/etc/mdadm/mdadm.conf)" + else + # this is the ideal case + install_config $CONFIG $DESTMDADMCONF + echo "I: mdadm: using configuration file: $CONFIG" >&2 + fi -copy_exec $MDADM /sbin +fi -# copy all modules into the initramfs, just for safety. -# we copy raid456 / raid5+raid6 because the hook script just won't do -# anything when the module cannot be found. -modules="linear multipath raid0 raid1 raid456 raid5 raid6 raid10" -for mod in $modules; do manual_add_modules $mod; done +# if at this point, $DESTMDADMCONF does not exist, we must let the initramfs +# handle stuff. +if [ ! -f $DESTMDADMCONF ]; then + echo "W: mdadm: falling back to emergency procedure in initramfs." >&2 + exit 0 +else + # obtain dev:level pairs from config file, honouring multiline entries + devpairs="$( + while read line; do + for atom in $line; do + case "$atom" in + (/dev*) dev=$atom;; + (level=*) level=${atom#level=};; + (*) :;; + esac + done + [ -n "${dev:-}" ] && echo -n "${dev}:${level} " + done < $DESTMDADMCONF)" +fi uniquify() { for i in $@; do echo "$i"; done | sort -u } -DEBIANCONFIG=/etc/default/mdadm -INITRDSTART=all -[ -s $DEBIANCONFIG ] && . $DEBIANCONFIG - -# save the homehost for now, even if we don't use it yet -homehost="$(sed -ne 's,^[[:space:]]*HOMEHOST[[:space:]]*,,p' $CONFIG)" -if [ -z "$homehost" ] || [ "$homehost" = '<system>' ]; then - homehost="$(hostname)" -fi -echo "MD_HOMEHOST='$homehost'" > $DESTDIR/conf/md.conf - -[ -z "$INITRDSTART" ] && INITRDSTART=none if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then - echo "MD_DEVPAIRS='${devpairs% }'" >> $DESTDIR/conf/md.conf + echo "MD_DEVPAIRS='${devpairs% }'" >> $DESTCONFIG devs=''; levels='' for i in $devpairs; do @@ -143,11 +188,11 @@ if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then break done - echo "MD_LEVELS='$levels'" >> $DESTDIR/conf/md.conf + echo "MD_LEVELS='$levels'" >> $DESTCONFIG if [ "$INITRDSTART" = all ]; then - echo "MD_DEVS=all" >> $DESTDIR/conf/md.conf + echo "MD_DEVS=all" >> $DESTCONFIG else - echo "MD_DEVS='$devs'" >> $DESTDIR/conf/md.conf + echo "MD_DEVS='$devs'" >> $DESTCONFIG fi # raid4 is handled by raid5 @@ -158,7 +203,7 @@ if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then && modules="$(echo $modules | sed -e 's,raid[456],raid456,g')" modules="$(uniquify $modules | tr '\n' ' ')" - echo "MD_MODULES='${modules% }'" >> $DESTDIR/conf/md.conf + echo "MD_MODULES='${modules% }'" >> $DESTCONFIG if [ "$INITRDSTART" = all ]; then echo "I: mdadm: will start all available MD arrays from the initial ramdisk." >&2 @@ -169,7 +214,7 @@ if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then fi else - echo "MD_DEVS=none" >> $DESTDIR/conf/md.conf + echo "MD_DEVS=none" >> $DESTCONFIG echo "I: mdadm: no MD arrays will be started from the initial ramdisk." >&2 fi diff --git a/debian/initramfs/script.local-top b/debian/initramfs/script.local-top index eecbed6a..621f617a 100644 --- a/debian/initramfs/script.local-top +++ b/debian/initramfs/script.local-top @@ -26,7 +26,7 @@ esac . /scripts/functions if [ -e /scripts/local-top/md ]; then - log_failure_msg "old md initialisation script found, getting out of its way..." + log_warning_msg "old md initialisation script found, getting out of its way..." exit 1 fi @@ -51,7 +51,7 @@ for module in ${MD_MODULES:-}; do if modprobe --syslog "$module"; then verbose && log_success_msg "loaded module ${module}." else - verbose && log_failure_msg "failed to load module ${module}." + log_failure_msg "failed to load module ${module}." fi done log_end_msg @@ -65,36 +65,42 @@ fi mkdir --parent /dev/md CONFIG=/etc/mdadm/mdadm.conf -# this really should not be needed, but also doesn't hurt. -[ -e $CONFIG ] || \ +# in case the hook failed to install a configuration file, this is out last +# attempt... the "emergency procedure"... <drumroll> +if [ ! -e $CONFIG ]; then + log_warning_msg "missing mdadm.conf file, trying to create one..." + mkdir -p ${CONFIG%/*} $MDADM --examine --scan --config=partitions > $CONFIG + if [ -s $CONFIG ]; then + verbose && log_success_msg "mdadm.conf created." + else + verbose && log_failure_msg "could not create mdadm.conf, the boot will likely fail." + fi + MD_DEVS=all +fi if [ "$MD_DEVS" = all ]; then verbose && log_begin_msg "Assembling all MD arrays" - extra_args='' [ -n "$MD_HOMEHOST" ] && \ extra_args="--homehost='$MD_HOMEHOST' --auto-update-homehost" if $MDADM --assemble --scan --run --auto=yes $extra_args; then - verbose && log_success_msg "success" + verbose && log_success_msg "assembled all arrays." else - verbose && log_failure_msg "failed" + log_failure_msg "failed to assemble all arrays." fi - verbose && log_end_msg elif [ "$MD_DEVS" != none ]; then for dev in $MD_DEVS; do verbose && log_begin_msg "Assembling MD array $dev" - if $MDADM --assemble --run --auto=yes $dev; then verbose && log_success_msg "started $dev" else - verbose && log_failure_msg "failed to start $dev" + log_failure_msg "failed to start $dev" fi - verbose && log_end_msg done |