summaryrefslogtreecommitdiffstats
path: root/modules.d/90dmraid/dmraid.sh
blob: c12d92e389910db6fd06309885f7af4c27ae00ae (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
45
46
#!/bin/sh

type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh

devenc=$(str_replace "$1" '/' '\2f')

[ -e /tmp/dmraid."$devenc" ] && exit 0

: > /tmp/dmraid."$devenc"

DM_RAIDS=$(getargs rd.dm.uuid -d rd_DM_UUID=)

if [ -n "$DM_RAIDS" ] || getargbool 0 rd.auto; then
    # run dmraid if udev has settled
    info "Scanning for dmraid devices $DM_RAIDS"
    SETS=$(dmraid -c -s)

    if [ "$SETS" = "no raid disks" ] || [ "$SETS" = "no raid sets" ]; then
        return
    fi

    info "Found dmraid sets:"
    echo "$SETS" | vinfo

    if [ -n "$DM_RAIDS" ]; then
        # only activate specified DM RAIDS
        for r in $DM_RAIDS; do
            for s in $SETS; do
                if [ "${s##"$r"}" != "$s" ]; then
                    info "Activating $s"
                    dmraid -ay -i -p --rm_partitions "$s" 2>&1 | vinfo
                fi
            done
        done
    else
        # scan and activate all DM RAIDS
        for s in $SETS; do
            info "Activating $s"
            dmraid -ay -i -p --rm_partitions "$s" 2>&1 | vinfo
            [ -e "/dev/mapper/$s" ] && kpartx -a "/dev/mapper/$s" 2>&1 | vinfo
            udevsettle
        done
    fi

    need_shutdown
fi