summaryrefslogtreecommitdiffstats
path: root/abs/core/mdadm/mdadm_hook
blob: 57799d3b80cbc3f8a515c4f42c2670276e7693eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# vim: set ft=sh:
run_hook ()
{
    input="$(cat /proc/cmdline)"
    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 
            case $i in
                # 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
                    ;;
                # 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
                    ;;
                # 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
                    ;;
                # 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
                    ;;
            esac 
        done
    fi
    # assemble everything
    [ -e $mdconfig ] && /sbin/mdassemble
}