mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-25 23:51:07 +02:00
OS-dependent sysexts that ship kernel modules, usually also ship the files in /usr/lib/modules/*-flatcar/modules.XXX When multiple such sysexts get activated, depmod files from just one sysext win and other kernel modules cannot be loaded using modprobe. We get around this by removing the depmod files from every sysext with kernel modules. Instead, we set up modprobe hook, which dynamically runs depmod in a temporary directory on every sysext kernel module activation. Signed-off-by: Daniel Zatovic <daniel.zatovic@gmail.com>
49 lines
1.4 KiB
Bash
49 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
configure_modprobe() {
|
|
local sysext_name="${1}"
|
|
shift
|
|
|
|
local module_directories=(./usr/lib/modules/*-flatcar/)
|
|
|
|
mkdir -p ./usr/lib/modprobe.d/
|
|
for module_name in $(find "${module_directories[@]}" -type f \( -name "*.ko" -o -name "*.ko.*" \) -printf "%f\n" | sed -E 's/\.ko(\.\w+)?$//'); do
|
|
cat <<EOF >> "./usr/lib/modprobe.d/10-${sysext_name}-kmod-sysext.conf"
|
|
install $module_name /usr/libexec/_${sysext_name}_modprobe_helper $module_name
|
|
remove $module_name /usr/libexec/_${sysext_name}_modprobe_helper -r $module_name
|
|
EOF
|
|
done
|
|
|
|
mkdir -p ./usr/libexec/
|
|
install -m0755 -D /dev/stdin "./usr/libexec/_${sysext_name}_modprobe_helper" <<'EOF'
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
action="Loading"
|
|
for arg in "$@"; do
|
|
if [[ $arg == "-r" ]]; then
|
|
action="Unloading"
|
|
fi
|
|
done
|
|
echo "$action kernel module from a sysext..."
|
|
|
|
KMOD_PATH=/usr/lib/modules/$(uname -r)
|
|
TMP_DIR=$(mktemp -d)
|
|
trap "rm -rf -- '${TMP_DIR}'" EXIT
|
|
mkdir "${TMP_DIR}"/{upper,work}
|
|
|
|
unshare -m bash -s -- "${@}" <<FOE
|
|
set -euo pipefail
|
|
if ! mountpoint -q "${KMOD_PATH}"; then
|
|
mount -t overlay overlay -o lowerdir="${KMOD_PATH}",upperdir="${TMP_DIR}"/upper,workdir="${TMP_DIR}"/work "${KMOD_PATH}"
|
|
depmod
|
|
fi
|
|
modprobe --ignore-install "\${@}"
|
|
FOE
|
|
EOF
|
|
|
|
# prevent the sysext from masking /usr/lib/modules/*-flatcar/modules.XXX
|
|
find "${module_directories[@]}" -maxdepth 1 -mindepth 1 -type f -delete
|
|
}
|