blob: 1b5b438c9c66577ff377424a0b052348ce5e5cfb (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/bin/bash
build() {
local -a md_devs
local dev insufficient_perms
MODULE_FILE=$workdir/autodetect_modules
add_if_avail() {
local resolved
# treat this as an alias, since ext3 might be aliased to ext4.
IFS=$'\n' read -rd '' -a resolved < \
<(modprobe -S "$KERNELVERSION" -R "$1" 2>/dev/null)
if (( ${#resolved[*]} )); then
printf '%s\n' "${resolved[@]}" >>"$MODULE_FILE"
fi
}
if [[ ! -d /sys/devices ]]; then
error "/sys does not appear to be mounted. Unable to use autodetection"
return 1
fi
auto_modules >"$MODULE_FILE"
if ! rootfstype=$(findmnt -uno fstype "${BASEDIR:-/}"); then
error "failed to detect root filesystem"
fs_autodetect_failed=1
fi
# filesystem module might be a builtin
add_if_avail "$rootfstype"
# detect separate /usr
if usrfstype=$(findmnt -snero fstype --tab-file "$BASEDIR/etc/fstab" /usr); then
add_if_avail "$usrfstype"
fi
# look for raid devices
shopt -s nullglob
for dev in /sys/class/block/*/md/dev-*; do
dev=/dev/${dev#*/dev-}
[[ -r $dev ]] || insufficient_perms=1
md_devs+=("$dev")
done
shopt -u nullglob
# scan members of raid devices if found
if (( ${#md_devs[*]} )); then
(( !QUIET )) && plain "found %d raid members to scan" "${#md_devs[*]}"
if (( ! insufficient_perms )); then
mdadm -Esv "${md_devs[@]}" |
sed -n 's/.*level=\([^ ]\+\) .*/\1/p' |
sed 's/\<raid[456]\>/raid456/g' | sort -u >>"$MODULE_FILE"
else
warning "Insufficient permission to perform autodetection for mdadm devices"
raid_autodetect_failed=1
fi
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:
|