#!/bin/sh
-#
# geninitrd mod: mdadm
USE_MD=${USE_MD:-yes}
# setup geninitrd module
# @access public
setup_mod_md() {
- mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
- if [ ! -x "$mdassemble" ]; then
- USE_MD=no
- fi
mdadm=$(find_tool /sbin/mdadm $initrd_dir/mdadm /sbin/initrd-mdadm)
if [ ! -x "$mdadm" ]; then
USE_MD=no
local found raidlevel
if [ -f /etc/mdadm.conf ]; then
- debug "Finding RAID details using mdadm for rootdev=$1"
+ verbose "Finding RAID details using mdadm for rootdev=$1"
eval `($mdadm -v --examine --scan --config=/etc/mdadm.conf 2> /dev/null;$mdadm -v --detail --scan --config=/etc/mdadm.conf 2> /dev/null) | awk -v rootdev="$1" '
BEGIN {
found = "no";
die "RAID devices not found for \"$1\", check your configuration!"
fi
- debug "md: found rootdev=$1 on device $rootdev_new with devices list ${dev_list}"
+ verbose "md: found rootdev=$1 on device $rootdev_new with devices list ${dev_list}"
rootdev_nr=$(( $rootdev_nr + 1 ))
eval "rootdev${rootdev_nr}=\"$rootdev_new\""
# generate initrd fragment for md
# @access public
initrd_gen_md() {
- debug "Setting up mdadm..."
+ if ! is_yes "$have_md"; then
+ return
+ fi
+ verbose "Setting up mdadm..."
- inst_exec $mdassemble /bin/mdassemble
+ inst_exec $mdadm /sbin/mdadm
+
+ echo "DEVICE partitions containers" >> "$DESTDIR/etc/mdadm.conf"
# LVM on RAID case
local dev_list_extra ex_dev
dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
- if [ "$dev_list_extra" = "partitions" ]; then
- # FIXME: handle this case (see man mdadm.conf)
- echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
- dev_list_extra=""
- else
- for ex_dev in $dev_list_extra; do
+ new_dev_list_extra=""
+ for ex_dev in $dev_list_extra; do
+ if [ "$ex_dev" = "partitions" -o "$ex_dev" = "containers" ]; then
echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
- done
- fi
+ # FIXME: find and copy partition devices from /proc/partitions
+ # - best if done at runtime, now initrd gen time
+ continue
+ fi
+ echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
+ new_dev_list_extra="$new_dev_list_extra $ex_dev"
+ done
+ dev_list_extra=$new_dev_list_extra
local cr_rootdev cr_dev_list do_md0=1 nr cr_dev_list_md f cr_md_conf
for nr in `seq 1 $rootdev_nr`; do
eval cr_rootdev="\$rootdev${nr}"
eval cr_dev_list="\$dev_list${nr}"
- debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
+ verbose "Setting up array ($cr_rootdev = $cr_dev_list)"
[ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
done
done
- echo "mdassemble" | add_linuxrc
+ echo "wait_for_files $cr_dev_list" | add_linuxrc
+ add_linuxrc <<-'EOF'
+ /sbin/mdadm --assemble --scan
+
+ if [ "$DEBUGINITRD" ]; then
+ [ -e /proc/mdstat ] && echo "/proc/mdstat contents:" && cat /proc/mdstat
+ fi
+ EOF
# needed to determine md-version
if [ "$do_md0" -eq 1 ]; then
- mknod $DESTDIR/dev/md0 b 9 0
+ mknod -m 660 $DESTDIR/dev/md0 b 9 0
fi
}