Skip to content

Commit 348c1fc

Browse files
committed
build_library: Fix depmod issues with sysext kmods
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>
1 parent 191af7f commit 348c1fc

8 files changed

+70
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_NAME=$(basename "$(realpath "${BASH_SOURCE[0]}")")
6+
SYSEXT_NAME=${SCRIPT_NAME#sysext_mangle_}
7+
SYSEXT_NAME=${SYSEXT_NAME%.sh}
8+
DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
9+
. "$DIR/sysext_mangle_kmod"
10+
11+
rootfs="${1}"
12+
13+
cd "${rootfs}"
14+
configure_modprobe "$SYSEXT_NAME"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sysext_mangle_flatcar-nvidia-drivers-535
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sysext_mangle_flatcar-nvidia-drivers-535
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sysext_mangle_flatcar-nvidia-drivers-535
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sysext_mangle_flatcar-nvidia-drivers-535
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sysext_mangle_flatcar-nvidia-drivers-535

build_library/sysext_mangle_flatcar-zfs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
set -euo pipefail
44
rootfs="${1}"
55

6+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
7+
. "$DIR/sysext_mangle_kmod"
8+
69
pushd "${rootfs}"
710

811
rm -rf ./usr/{lib/debug/,lib64/cmake/,include/}
@@ -40,4 +43,5 @@ cat <<EOF >./usr/lib/systemd/system/systemd-udevd.service.d/10-zfs.conf
4043
[Unit]
4144
After=systemd-sysext.service
4245
EOF
46+
configure_modprobe flatcar-zfs
4347
popd

build_library/sysext_mangle_kmod

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
configure_modprobe() {
4+
local sysext_name="${1}"
5+
shift
6+
7+
local module_directories=(./usr/lib/modules/*-flatcar/)
8+
9+
mkdir -p ./usr/lib/modprobe.d/
10+
for module_name in $(find "${module_directories[@]}" -type f \( -name "*.ko" -o -name "*.ko.*" \) -printf "%f\n" | sed -E 's/\.ko(\.\w+)?$//'); do
11+
cat <<EOF >> "./usr/lib/modprobe.d/10-${sysext_name}-kmod-sysext.conf"
12+
install $module_name /usr/local/bin/_${sysext_name}_modprobe_helper $module_name
13+
EOF
14+
done
15+
16+
mkdir -p ./usr/local/bin/
17+
install -m0755 -D /dev/stdin "./usr/local/bin/_${sysext_name}_modprobe_helper" <<'EOF'
18+
#!/bin/bash
19+
20+
set -euo pipefail
21+
22+
action="Loading"
23+
for arg in "$@"; do
24+
if [[ $arg == "-r" ]]; then
25+
action="Unloading"
26+
fi
27+
done
28+
echo "$action kernel module from a sysext..."
29+
30+
KMOD_PATH=/usr/lib/modules/$(uname -r)
31+
TMP_DIR=$(mktemp -d)
32+
trap "rm -rf -- '${TMP_DIR}'" EXIT
33+
mkdir "${TMP_DIR}"/{upper,work}
34+
35+
unshare -m bash -s -- "${@}" <<FOE
36+
set -euo pipefail
37+
if ! mountpoint -q "${KMOD_PATH}"; then
38+
mount -t overlay overlay -o lowerdir="${KMOD_PATH}",upperdir="${TMP_DIR}"/upper,workdir="${TMP_DIR}"/work "${KMOD_PATH}"
39+
depmod
40+
fi
41+
modprobe --ignore-install "\${@}"
42+
FOE
43+
EOF
44+
45+
# prevent the sysext from masking /usr/lib/modules/*-flatcar/modules.XXX
46+
find "${module_directories[@]}" -maxdepth 1 -mindepth 1 -type f -delete
47+
}

0 commit comments

Comments
 (0)