5 # if we should init md (softraid) at boot
8 # setup geninitrd module
11 mdadm=$(find_tool /sbin/mdadm $initrd_dir/mdadm /sbin/initrd-mdadm)
12 if [ ! -x "$mdadm" ]; then
17 # return true if mdadm is set on $devpath
18 # @param string $devpath device node to be examined
24 if ! is_yes "$USE_MD"; then
28 if [[ "$devpath" == /dev/md* ]]; then
35 # find md modules for $devpath
36 # @param $devpath device to be examined
37 # @return false if $devpath is not on md
42 if [ -f /etc/mdadm.conf ]; then
43 verbose "Finding RAID details using mdadm for rootdev=$1"
44 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" '
50 rootdev_alias = rootdev;
51 # alternative name: normalize from /dev/md/X to /dev/mdX
52 if (rootdev_alias ~ /\/dev\/md\/[0-9]+/) {
53 gsub(/\/dev\/md\//,"/dev/md",rootdev_alias);
55 # alternative name: normalize from /dev/mdXpY to /dev/mdX
56 if (rootdev_alias ~/\/dev\/md[0-9]+p[0-9]+/) {
57 gsub(/p[0-9]+/,"",rootdev_alias);
63 # normalize to /dev/mdX form
64 if (arr_device ~ /\/dev\/md\/[0-9]+/) {
65 gsub(/\/dev\/md\//,"/dev/md",arr_device);
67 if ((arr_device == rootdev) || (arr_device == rootdev_alias)) {
69 rootdev_new=arr_device
70 gsub(/level=/,NUL,raidlevel);
71 if (raidlevel ~ /^raid([0-6]|10)/) {
72 gsub(/raid/,NUL,raidlevel);
78 gsub(".*devices=", NUL, dev_list);
79 gsub(",", " ", dev_list);
85 print "rootdev_new=" rootdev_new;
86 print "have_md=" found;
87 print "raidlevel=" raidlevel;
88 print "dev_list=\"" dev_list "\"";
92 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
93 die "raidtools are not longer supported. Please migrate to mdadm setup!"
96 if is_yes "$have_md"; then
99 find_module "raid$raidlevel"
102 find_module "-raid$raidlevel"
103 find_module "-raid456"
109 warn "raid level $number (in mdadm config) not recognized"
113 die "RAID devices not found for \"$1\", check your configuration!"
116 verbose "md: found rootdev=$1 on device $rootdev_new with devices list ${dev_list}"
118 rootdev_nr=$(( $rootdev_nr + 1 ))
119 eval "rootdev${rootdev_nr}=\"$rootdev_new\""
120 eval "dev_list${rootdev_nr}=\"${dev_list}\""
122 for device in $dev_list; do
123 find_modules_for_devpath $device
128 # generate initrd fragment for md
131 if ! is_yes "$have_md"; then
134 verbose "Setting up mdadm..."
136 inst_exec $mdadm /sbin/mdadm
138 echo "DEVICE partitions containers" >> "$DESTDIR/etc/mdadm.conf"
141 local dev_list_extra ex_dev
142 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
143 new_dev_list_extra=""
144 for ex_dev in $dev_list_extra; do
145 if [ "$ex_dev" = "partitions" -o "$ex_dev" = "containers" ]; then
146 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
147 # FIXME: find and copy partition devices from /proc/partitions
148 # - best if done at runtime, now initrd gen time
151 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
152 new_dev_list_extra="$new_dev_list_extra $ex_dev"
154 dev_list_extra=$new_dev_list_extra
156 local cr_rootdev cr_dev_list do_md0=1 nr cr_dev_list_md f cr_md_conf
157 for nr in `seq 1 $rootdev_nr`; do
158 eval cr_rootdev="\$rootdev${nr}"
159 eval cr_dev_list="\$dev_list${nr}"
160 verbose "Setting up array ($cr_rootdev = $cr_dev_list)"
162 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
164 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
165 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
166 cr_md_conf=$($mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
167 if [ -n "$cr_md_conf" ]; then
168 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
170 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
173 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
174 # mkdir in case of devfs name
176 [ -e "$DESTDIR/$f" ] && continue
177 # this works fine with and without devfs
182 echo "wait_for_files $cr_dev_list" | add_linuxrc
184 /sbin/mdadm --assemble --scan
186 if [ "$DEBUGINITRD" ]; then
187 [ -e /proc/mdstat ] && echo "/proc/mdstat contents:" && cat /proc/mdstat
191 # needed to determine md-version
192 if [ "$do_md0" -eq 1 ]; then
193 mknod -m 660 $DESTDIR/dev/md0 b 9 0