Skip to content

Commit d32d221

Browse files
aafeijoo-susejohannbg
authored andcommitted
fix(dracut.sh): split drivers_dir check
The directory where to look for kernel modules can be set via the -k/--kmoddir command line option or the drivers_dir configuration option. Its current check should be split into two different ones to avoid misleading error messages (see referenced issue): - First check that its basename matches the kernel version set for the initramfs (via --kver or automatically set by "uname -r"). - Second check that the parent directory of the last provided directory contains "/lib/modules/". This check was also fixed to avoid accepting other directories like "xxxlib/modules". Fixes issue #1608
1 parent 8d46cc0 commit d32d221

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

dracut.sh

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
10311031
((stdloglvl < 0)) && stdloglvl=0
10321032

10331033
[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
1034+
drivers_dir="${drivers_dir%%+(/)}"
10341035
[[ $do_strip_l ]] && do_strip=$do_strip_l
10351036
[[ $do_strip ]] || do_strip=yes
10361037
[[ $aggressive_strip_l ]] && aggressive_strip=$aggressive_strip_l
@@ -1204,20 +1205,25 @@ esac
12041205
12051206
[[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
12061207
1207-
case "${drivers_dir}" in
1208-
'' | *lib/modules/${kernel} | *lib/modules/${kernel}/) ;;
1209-
*)
1210-
[[ "$DRACUT_KMODDIR_OVERRIDE" ]] || {
1211-
printf "%s\n" 'dracut: -k/--kmoddir path must contain "lib/modules" as a parent of your kernel module directory,'
1212-
printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs."
1213-
printf "%s\n" "dracut: was given: ${drivers_dir}"
1214-
printf "%s\n" "dracut: expected: $(dirname "${drivers_dir}")/lib/modules/${kernel}"
1215-
printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location,"
1216-
printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check."
1217-
exit 1
1218-
}
1219-
;;
1220-
esac
1208+
if [[ -z $DRACUT_KMODDIR_OVERRIDE && -n $drivers_dir ]]; then
1209+
drivers_basename="${drivers_dir##*/}"
1210+
if [[ -n $drivers_basename && $drivers_basename != "$kernel" ]]; then
1211+
printf "%s\n" "dracut: The provided directory where to look for kernel modules ($drivers_basename)" >&2
1212+
printf "%s\n" "dracut: does not match the kernel version set for the initramfs ($kernel)." >&2
1213+
printf "%s\n" "dracut: Set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
1214+
exit 1
1215+
fi
1216+
drivers_dirname="${drivers_dir%/*}/"
1217+
if [[ ! $drivers_dirname =~ .*/lib/modules/$ ]]; then
1218+
printf "%s\n" "dracut: drivers_dir path ${drivers_dir_l:+"set via -k/--kmoddir "}must contain \"/lib/modules/\" as a parent of your kernel module directory," >&2
1219+
printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs." >&2
1220+
printf "%s\n" "dracut: was given: ${drivers_dir}" >&2
1221+
printf "%s\n" "dracut: expected: ${drivers_dirname}lib/modules/${kernel}" >&2
1222+
printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location," >&2
1223+
printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
1224+
exit 1
1225+
fi
1226+
fi
12211227
12221228
# shellcheck disable=SC2155
12231229
readonly TMPDIR="$(realpath -e "$tmpdir")"

0 commit comments

Comments
 (0)