#!/bin/bash #%stage: softraid #%programs: /sbin/mdadm /sbin/mdmon #%modules: raid0 raid1 raid10 raid456 #%if: -n "$need_mdadm" # ##### MD (Software-)Raid ## ## This activates and waits for an MD software raid. ## ## Command line parameters ## ----------------------- ## ## need_mdadm=1 use MD raid ## md_uuid the uuid of the raid to activate ## # load the necessary module before we initialize the raid system load_modules # put the mdmon socked and pid file to /dev/.mdadm rm -rf /var/run/mdadm mkdir -p /var/run ln -s /dev/.mdadm /var/run/mdadm mkdir -p /dev/.mdadm [ "$mduuid" ] && md_uuid="$mduuid" md_major=$(sed -ne 's/\s*\([0-9]\+\)\s*md$/\1/p' /proc/devices) if [ -n "$md_major" -a "$md_major" = "$maj" ]; then md_minor="$min" md_dev="/dev/md$md_minor" fi # Always start md devices read/only. They will get set to rw as soon # as the first write occurs. This way we can guarantee that no # restore occurs before resume. if [ -f /sys/module/md_mod/parameters/start_ro ]; then echo 1 > /sys/module/md_mod/parameters/start_ro fi md_assemble() { local dev=$1 mdconf container if test -e "$dev"; then return fi case "$dev" in /dev/md[0-9]*p[0-9]*) dev=${dev%p[0-9]*} esac if test -f /etc/mdadm.conf; then mdconf="-c /etc/mdadm.conf" container=$( \ sed -rn "s:^ARRAY +$dev .*container=([^ ]*).*:\\1:p" \ /etc/mdadm.conf) else mdconf="-c partitions" fi case "$container" in "") ;; /dev/*) mdadm -A $mdconf $container ;; [0-9a-f]*[0-9a-f]) mdadm -A $mdconf --uuid="$container" /dev/md/container ;; *) echo "unrecognized container for $dev: $container" ;; esac mdadm -A $mdconf $mdarg "$dev" } if [ -n "$need_mdadm" ]; then if [ -n "$md_uuid" ] ; then mdarg="--uuid=$md_uuid" fi case $resumedev in /dev/md*) md_assemble "$resumedev" esac if [ -n "$md_dev" ] ; then md_assemble "$md_dev" fi for dev in $md_devs; do md_assemble "$dev" done wait_for_events fi