summaryrefslogtreecommitdiffstats
path: root/install/autodetect
blob: 400197771ba875e6d61c1102b039b6bade4901b2 (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
#!/bin/bash

build() {
    MODULE_FILE=$TMPDIR/autodetect_modules

    if [[ ! -d /sys/devices ]]; then
        error "/sys does not appear to be mounted. Unable to use autodetection"
        return 1
    fi

    auto_modules | grep -xEv '(ata|ide)_generic' >"$MODULE_FILE"

    if ! findmnt -uno fstype "${BASEDIR:-/}" >>"$MODULE_FILE"; then
        error "failed to detect root filesystem"
        fs_autodetect_failed=1
    fi

    if (( UID == 0 )) || in_array 'disk' $(groups); then
        if [[ -x /sbin/mdadm ]]; then
            /sbin/mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* |
                sed -n 's/.*level=\([^ ]\+\) .*/\1/p' |
                sed 's/\<raid[456]\>/raid456/g' | sort -u >>"$MODULE_FILE"
        fi
    else
        error "Insufficient permission to perform autodetection for mdadm devices"
        raid_autodetect_failed=1
    fi

    if (( !QUIET )) && [[ -s $MODULE_FILE ]]; then
        plain "caching %d modules" $(wc -l < "$MODULE_FILE")
    fi
}

help() {
    cat <<HELPEOF
This hook shrinks your initramdisk to a smaller size by autodetecting your
needed modules. Be sure to verify included modules are correct and none are
missing.  This hook must be run before other subsystem hooks in order to take
advantage of auto-detection.  Any hooks placed before 'autodetect' will be
installed in full.
HELPEOF
}

# vim: set ft=sh ts=4 sw=4 et: