#!/bin/sh # # Copyright © 2006-2008 Martin F. Krafft # based on the scripts in the initramfs-tools package. # released under the terms of the Artistic Licence. # set -eu case ${1:-} in prereqs) exit 0;; esac . /scripts/functions maybe_break pre-mdadm MDADM=/sbin/mdadm [ -x "$MDADM" ] || exit 0 verbose() { case "$quiet" in y*|Y*|1|t*|T*) return 1;; *) return 0;; esac } MD_DEVS=all MD_MODULES='linear multipath raid0 raid1 raid456 raid5 raid6 raid10' [ -s /conf/conf.d/md ] && . /conf/conf.d/md verbose && log_begin_msg Loading MD modules for module in ${MD_MODULES:-}; do if /sbin/modprobe -q "$module"; then verbose && log_success_msg "loaded module ${module}." else log_failure_msg "failed to load module ${module}." fi done log_end_msg if [ ! -f /proc/mdstat ]; then verbose && panic "cannot initialise MD subsystem (/proc/mdstat missing)" exit 1 fi # handle /dev/md/X nodes mkdir -p /dev/md CONFIG=/etc/mdadm.conf # in case the hook failed to install a configuration file, this is our last # attempt... the "emergency procedure"... if [ ! -e $CONFIG ]; then log_warning_msg "missing mdadm.conf file, trying to create one..." mkdir -p ${CONFIG%/*} echo DEVICE partitions > $CONFIG $MDADM --examine --scan >> $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 # prevent writes/syncs so that resuming works (#415441). echo 1 > /sys/module/md_mod/parameters/start_ro 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 "assembled all arrays." else 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 --scan --run --auto=yes $dev; then verbose && log_success_msg "started $dev" else log_failure_msg "failed to start $dev" fi verbose && log_end_msg done fi if [ -x "$(command -v udevadm)" ]; then verbose && log_begin_msg "Waiting for udev to process events" udevadm settle || true verbose && log_end_msg fi maybe_break post-mdadm exit 0