/
autodetect
39 lines (32 loc) · 1.19 KB
/
autodetect
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
#!/bin/bash
build() {
if [[ ! -d /sys/devices ]]; then
err "/sys does not appear to be mounted. Unable to use autodetection"
return 1
fi
# generate a list of modules from aliases in /sys/devices
find /sys/devices -name modalias -exec sort -u {} + |
xargs modprobe -d "${basedir:-/}" -S "$kernver" -aR |
sort -u >>"$autodetect_cache"
if (( UID == 0 )) || in_array 'disk' $(groups); then
if ! findmnt -uno fstype ${basedir:-/} >>"$autodetect_cache"; then
err "failed to detect root filesystem"
fi
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 >>"$autodetect_cache"
fi
else
err "User does not have proper permissions to read superblocks, raid and filesystem modules are not detected"
fi
}
helpmsg() {
cat<<HELPEOF
This builder autodetects needed modules for the initramfs. This does not add
any modules on its own, but rather serves as a basis for limiting what the
following builders will add. Any buidlers placed prior to this will be
installed in full.
HELPEOF
}
# vim: set et ts=2 sw=2: