From c75a6e89593799daf7360e897764a9f1f1d421dd Mon Sep 17 00:00:00 2001 From: madduck Date: Tue, 10 Jul 2007 08:01:14 +0000 Subject: * Does some sanity checking for proper format of level= arguments in mdadm.conf and bails if an error is found. Since the RAID levels are used verbatim as module names, a discrepancy might lead to an unusable system. Instead, we thus use the emergency fallback. Thanks to Andrew Sackville-West for spotting this and helping me with the fix. --- debian/initramfs/hook | 65 ++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'debian/initramfs') diff --git a/debian/initramfs/hook b/debian/initramfs/hook index 4d180430..1f879a5d 100644 --- a/debian/initramfs/hook +++ b/debian/initramfs/hook @@ -53,16 +53,16 @@ err() } if [ -e /usr/share/initramfs-tools/hooks/md ]; then - warn "initramfs md hook still present, stepping out of its way." >&2 - warn "Please see /usr/share/doc/mdadm/README.initramfs-transition ." >&2 + warn "initramfs md hook still present, stepping out of its way." + warn "Please see /usr/share/doc/mdadm/README.initramfs-transition ." exit 0 fi if [ -e /etc/initramfs-tools/hooks/md ]; then - warn "I found /etc/initramfs-tools/hooks/md, which may conflict" >&2 - warn "with this version of mdadm. Please see /usr/share/doc/mdadm/README.mdrun" >&2 - warn "and /usr/share/initramfs-tools/hooks/mdadm for reference and update" >&2 - warn "(or remove) the file." >&2 + warn "I found /etc/initramfs-tools/hooks/md, which may conflict" + warn "with this version of mdadm. Please see /usr/share/doc/mdadm/README.mdrun" + warn "and /usr/share/initramfs-tools/hooks/mdadm for reference and update" + warn "(or remove) the file." exit 0 fi @@ -117,11 +117,11 @@ if [ ! -f $CONFIG ]; then if /usr/share/mdadm/mkconf generate $CONFIG; then # all is well install_config $CONFIG $DESTMDADMCONF - info "auto-generated the mdadm.conf configuration file." >&2 + info "auto-generated the mdadm.conf configuration file." else # we failed to auto-generate, so let the emergency procedure take over - warn "failed to auto-generate the mdadm.conf file." >&2 - warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." >&2 + warn "failed to auto-generate the mdadm.conf file." + warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." fi else @@ -131,21 +131,21 @@ else # 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. - warn "unchecked configuration file: $CONFIG" >&2 - warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." >&2 + warn "unchecked configuration file: $CONFIG" + warn "please read /usr/share/doc/mdadm/README.upgrading-2.5.3.gz ." use_temp=1 elif ! grep -q '^ARRAY' $CONFIG; then # the file defines no ARRAYs. We better create a temporary file to be # sure. - warn "$CONFIG defines no arrays." >&2 + warn "$CONFIG defines no arrays." use_temp=1 else # this is the ideal case install_config $CONFIG $DESTMDADMCONF - info "using configuration file: $CONFIG" >&2 + info "using configuration file: $CONFIG" fi if [ $use_temp -eq 1 ]; then @@ -153,15 +153,15 @@ else tmpfile="${DESTMDADMCONF}.tmp" if /usr/share/mdadm/mkconf > $tmpfile; then # all is well, we now have a temporary configuration file - info "auto-generated temporary mdadm.conf configuration file." >&2 + info "auto-generated temporary mdadm.conf configuration file." 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... - warn "failed to auto-generate temporary mdadm.conf file." >&2 + warn "failed to auto-generate temporary mdadm.conf file." if grep -q '^ARRAY' $CONFIG; then - warn "using the unchecked file and hoping for the best..." >&2 + warn "using the unchecked file and hoping for the best..." install_config $CONFIG $DESTMDADMCONF fi fi @@ -173,12 +173,12 @@ fi # if at this point, $DESTMDADMCONF does not exist or it does not contain any # ARRAY statements, we must let the initramfs handle stuff. if [ ! -f $DESTMDADMCONF ]; then - warn "no configuration file available." >&2 - warn "falling back to emergency procedure in initramfs." >&2 + warn "no configuration file available." + warn "falling back to emergency procedure in initramfs." exit 0 elif ! grep -q '^ARRAY' $DESTMDADMCONF; then - warn "no arrays defined in configuration file." >&2 - warn "falling back to emergency procedure in initramfs." >&2 + warn "no arrays defined in configuration file." + warn "falling back to emergency procedure in initramfs." exit 0 else # obtain dev:level pairs from config file, honouring multiline entries @@ -191,7 +191,14 @@ else for atom in $line; do case "$atom" in (/dev*) dev=$atom;; - (level=*) level=${atom#level=};; + (level=raid*|level=linear|level=multipath) level=${atom#level=};; + (level=*) + err "invalid level specified in ARRAY statement in $CONFIG:" + err " $line" + err "levels should be either raid*, linear, or multipath." + warn "falling back to emergency procedure in initramfs." + exit 1 + ;; (*) :;; esac done @@ -203,7 +210,7 @@ else echo -n "$($MDADM --detail $dev | sed -rne 's,[[:space:]]+Raid Level : ,,p')" fi echo -n ' ' - done < $DESTMDADMCONF)" + done < $DESTMDADMCONF)" || exit $? fi uniquify() @@ -234,9 +241,9 @@ if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then *) :;; esac - warn "I am supposed to start $i from the initial ramdisk," >&2 - warn "yet I cannot find the array in the configuration file." >&2 - warn "I am thus reverting to starting all arrays." >&2 + warn "I am supposed to start $i from the initial ramdisk," + warn "yet I cannot find the array in the configuration file." + warn "I am thus reverting to starting all arrays." INITRDSTART=all break done @@ -259,21 +266,21 @@ if [ "$INITRDSTART" != none ] && [ -n "$devpairs" ]; then echo "MD_MODULES='${modules% }'" >> $DESTCONFIG if [ "$INITRDSTART" = all ]; then - info "will start all available MD arrays from the initial ramdisk." >&2 + info "will start all available MD arrays from the initial ramdisk." else for i in $devs; do - info "will start MD array $i from the initial ramdisk." >&2 + info "will start MD array $i from the initial ramdisk." done fi else echo "MD_DEVS=none" >> $DESTCONFIG echo "MD_MODULES=''" >> $DESTCONFIG - info "no MD arrays will be started from the initial ramdisk." >&2 + info "no MD arrays will be started from the initial ramdisk." fi # only output this on Debian systems [ -s /etc/default/mdadm ] && \ - info 'use `dpkg-reconfigure --priority=low mdadm` to change this.' >&2 + info 'use `dpkg-reconfigure --priority=low mdadm` to change this.' exit 0 -- cgit v1.2.3