From f37e773fe397778858ea8d51601554863c252536 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 6 May 2012 00:02:44 +0000 Subject: Sun May 6 00:02:43 UTC 2012 --- core/mdadm/mdadm_hook | 65 +++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'core/mdadm/mdadm_hook') diff --git a/core/mdadm/mdadm_hook b/core/mdadm/mdadm_hook index 7b2dc1ad1..787be5d0c 100755 --- a/core/mdadm/mdadm_hook +++ b/core/mdadm/mdadm_hook @@ -1,44 +1,49 @@ -# vim: set ft=sh: -run_hook () -{ - input="$(cat /proc/cmdline)" - mdconfig="/etc/mdadm.conf" +#!/usr/bin/ash + +run_hook() { + local i= mdconfig=/etc/mdadm.conf + # for partitionable raid, we need to load md_mod first! modprobe md_mod 2>/dev/null - # If md is specified on commandline, create config file from those parameters. - if [ "$(echo $input | grep "md=")" ]; then - #Create initial mdadm.conf - # scan all devices in /proc/partitions - echo DEVICE partitions > $mdconfig - for i in $input; do + + if [ -n "$md" ]; then + echo 'DEVICE partitions' >"$mdconfig" + for i in $(cat /proc/cmdline); do case $i in - # raid + # raid md=[0-9]*,/*) - device="$(echo "$i" | sed -e 's|,/.*||g' -e 's|=||g')" - array="$(echo $i | cut -d, -f2-)" - echo "ARRAY /dev/$device devices=$array" >> $mdconfig + device=${i%%,*} + device=${device/=/} + array=${i#*,} + echo "ARRAY /dev/$device devices=$array" ;; # partitionable raid md=d[0-9]*,/*) - device="$(echo "$i" | sed -e 's|,/.*||g' -e 's|=|_|g')" - array="$(echo $i | cut -d, -f2-)" - echo "ARRAY /dev/$device devices=$array" >> $mdconfig + device=${i%%,*} + device=${device/=/_} + array=${i#*,} + echo "ARRAY /dev/$device devices=$array" ;; - # raid UUID - md=[0-9]*,[0-9,a-z]*) - device="$(echo "$i" | sed -e 's|,.*||g' -e 's|=||g')" - array="$(echo $i | cut -d, -f2-)" - echo "ARRAY /dev/$device UUID=$array" >> $mdconfig + # raid UUID + md=[0-9]*,[0-9,a-fA-F]*) + device=${i%%,*} + device=${device/=/} + array=${i#*,} + echo "ARRAY /dev/$device UUID=$array" ;; # partitionable raid UUID - md=d[0-9]*,[0-9,a-z]*) - device="$(echo "$i" | sed -e 's|,.*||g' -e 's|=|_|g')" - array="$(echo $i | cut -d, -f2-)" - echo "ARRAY /dev/$device UUID=$array" >> $mdconfig + md=d[0-9]*,[0-9,a-fA-F]*) + device=${i%%,*} + device=${device/=/_} + array=${i#*,} + echo "ARRAY /dev/$device UUID=$array" ;; - esac - done + esac + done >>"$mdconfig" fi + # assemble everything - [ -e $mdconfig ] && /sbin/mdassemble + [ -s "$mdconfig" ] && /sbin/mdassemble } + +# vim: set ft=sh ts=4 sw=4 et: -- cgit v1.2.3-54-g00ecf