Skip to content

Commit

Permalink
fix(dracut.sh): split drivers_dir check
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aafeijoo-suse authored and johannbg committed Dec 21, 2022
1 parent 8d46cc0 commit d32d221
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
((stdloglvl < 0)) && stdloglvl=0

[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
drivers_dir="${drivers_dir%%+(/)}"
[[ $do_strip_l ]] && do_strip=$do_strip_l
[[ $do_strip ]] || do_strip=yes
[[ $aggressive_strip_l ]] && aggressive_strip=$aggressive_strip_l
Expand Down Expand Up @@ -1204,20 +1205,25 @@ esac
[[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
case "${drivers_dir}" in
'' | *lib/modules/${kernel} | *lib/modules/${kernel}/) ;;
*)
[[ "$DRACUT_KMODDIR_OVERRIDE" ]] || {
printf "%s\n" 'dracut: -k/--kmoddir path must contain "lib/modules" as a parent of your kernel module directory,'
printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs."
printf "%s\n" "dracut: was given: ${drivers_dir}"
printf "%s\n" "dracut: expected: $(dirname "${drivers_dir}")/lib/modules/${kernel}"
printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location,"
printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check."
exit 1
}
;;
esac
if [[ -z $DRACUT_KMODDIR_OVERRIDE && -n $drivers_dir ]]; then
drivers_basename="${drivers_dir##*/}"
if [[ -n $drivers_basename && $drivers_basename != "$kernel" ]]; then
printf "%s\n" "dracut: The provided directory where to look for kernel modules ($drivers_basename)" >&2
printf "%s\n" "dracut: does not match the kernel version set for the initramfs ($kernel)." >&2
printf "%s\n" "dracut: Set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
exit 1
fi
drivers_dirname="${drivers_dir%/*}/"
if [[ ! $drivers_dirname =~ .*/lib/modules/$ ]]; then
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
printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs." >&2
printf "%s\n" "dracut: was given: ${drivers_dir}" >&2
printf "%s\n" "dracut: expected: ${drivers_dirname}lib/modules/${kernel}" >&2
printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location," >&2
printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
exit 1
fi
fi
# shellcheck disable=SC2155
readonly TMPDIR="$(realpath -e "$tmpdir")"
Expand Down

0 comments on commit d32d221

Please sign in to comment.