Skip to content

Commit 97c9e72

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 <[email protected]>
1 parent 191af7f commit 97c9e72

8 files changed

+64
-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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
echo "Loading kernel module from a sysext..."
23+
24+
KMOD_PATH=/usr/lib/modules/$(uname -r)
25+
TMP_DIR=$(mktemp -d)
26+
trap "rm -rf -- '${TMP_DIR}'" EXIT
27+
mkdir "${TMP_DIR}"/{upper,work}
28+
29+
unshare -m bash -s -- "${@}" <<FOE
30+
set -euo pipefail
31+
if ! mountpoint -q "${KMOD_PATH}"; then
32+
mount -t overlay overlay -o lowerdir="${KMOD_PATH}",upperdir="${TMP_DIR}"/upper,workdir="${TMP_DIR}"/work "${KMOD_PATH}"
33+
depmod
34+
fi
35+
modprobe --ignore-install "\${@}"
36+
FOE
37+
EOF
38+
39+
# prevent the sysext from masking /usr/lib/modules/*-flatcar/modules.XXX
40+
find "${module_directories[@]}" -maxdepth 1 -mindepth 1 -type f -delete
41+
}

0 commit comments

Comments
 (0)