Skip to content

Commit 5d3ac48

Browse files
authored
minimal-init: Try to load modules for all devices again after a timeout (#114)
Normally it works to do one full module load and then the drive is detected but in case this takes longer and mdev doesn't do the job of module loading we can fall back to a full load again to try to progress. So far we don't know if this helps (it won't for completly missing kernel modules of course) but it's good to have this done automatically instead of having to ask users if it helps for them when they hit an issue. ## How to use ## Testing done With a wrong verity usr kernel cmdline arg it now prints "Still waiting" every five seconds.
2 parents 66edf6f + 3c78905 commit 5d3ac48

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

minimal-init

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ if [ "$(cmdline_arg rd.earlytrace)" != "" ]; then
4444
set -x
4545
fi
4646

47+
loadmodules() {
48+
# Coldplugging but with using /sbin/modprobe (which is kmod) instead of busybox's modprobe
49+
# because busybox doesn't properly support the globs in modules.alias
50+
find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | xargs -0 /sbin/modprobe -abq || true
51+
}
52+
4753
mdev -d
4854
mdev -s
49-
# Coldplugging but with using /sbin/modprobe (which is kmod) instead of busybox's modprobe
50-
# because busybox doesn't properly support the globs in modules.alias
51-
find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | xargs -0 /sbin/modprobe -abq || true
55+
loadmodules
5256
# Required to access disks, but not autoloaded:
5357
/sbin/modprobe sd_mod
5458

@@ -100,7 +104,13 @@ find_drive() {
100104
echo "ERROR: Timeout waiting for drive: ${ueventline}${blkidmatch}" >&2
101105
return 1 # Throw error
102106
fi
103-
# No "sleep 0.1", so this is rather busy polling
107+
if [ $((now - starttime)) -gt 10 ]; then
108+
sleep 5
109+
echo "Still waiting for drive..." >&2
110+
loadmodules
111+
fi
112+
# No "sleep 0.1", so this is rather busy polling but normally it works on first try
113+
# and after some time we stop busy polling and have the longer sleep above
104114
if [ "${ueventline}" != "" ]; then
105115
drive="$({ grep -s -l -m 1 -r "${ueventline}" /sys/class/block/*/uevent || true; } | cut -d / -f 5)"
106116
else

0 commit comments

Comments
 (0)