Skip to content

Commit b74467f

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 db67772 commit b74467f

8 files changed

+149
-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="$(echo "$SCRIPT_NAME" | sed -e "s/^sysext_mangle_//" -e "s/\.sh$//")"
7+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
8+
. "$DIR/sysext_mangle_kmod"
9+
10+
rootfs="${1}"
11+
12+
pushd "${rootfs}"
13+
configure_modprobe "$SYSEXT_NAME"
14+
popd
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="$(echo "$SCRIPT_NAME" | sed -e "s/^sysext_mangle_//" -e "s/\.sh$//")"
7+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
8+
. "$DIR/sysext_mangle_kmod"
9+
10+
rootfs="${1}"
11+
12+
pushd "${rootfs}"
13+
configure_modprobe "$SYSEXT_NAME"
14+
popd
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="$(echo "$SCRIPT_NAME" | sed -e "s/^sysext_mangle_//" -e "s/\.sh$//")"
7+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
8+
. "$DIR/sysext_mangle_kmod"
9+
10+
rootfs="${1}"
11+
12+
pushd "${rootfs}"
13+
configure_modprobe "$SYSEXT_NAME"
14+
popd
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="$(echo "$SCRIPT_NAME" | sed -e "s/^sysext_mangle_//" -e "s/\.sh$//")"
7+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
8+
. "$DIR/sysext_mangle_kmod"
9+
10+
rootfs="${1}"
11+
12+
pushd "${rootfs}"
13+
configure_modprobe "$SYSEXT_NAME"
14+
popd
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="$(echo "$SCRIPT_NAME" | sed -e "s/^sysext_mangle_//" -e "s/\.sh$//")"
7+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
8+
. "$DIR/sysext_mangle_kmod"
9+
10+
rootfs="${1}"
11+
12+
pushd "${rootfs}"
13+
configure_modprobe "$SYSEXT_NAME"
14+
popd
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="$(echo "$SCRIPT_NAME" | sed -e "s/^sysext_mangle_//" -e "s/\.sh$//")"
7+
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
8+
. "$DIR/sysext_mangle_kmod"
9+
10+
rootfs="${1}"
11+
12+
pushd "${rootfs}"
13+
configure_modprobe "$SYSEXT_NAME"
14+
popd

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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
configure_modprobe() {
4+
local sysext_name="${1}"
5+
shift
6+
7+
local module_directory=(./usr/lib/modules/*-flatcar/)
8+
9+
mkdir -p ./usr/lib/modprobe.d/
10+
for module_name in $(find "${module_directory[0]}" -type f \( -name "*.ko" -o -name "*.ko.xz" \) -printf "%f\n" | sed -E 's/\.ko(\.xz)?$//'); 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+
remove $module_name /usr/local/bin/_${sysext_name}_modprobe_helper -r $module_name
14+
EOF
15+
done
16+
17+
mkdir -p ./usr/local/bin/
18+
cat <<'EOF' > "./usr/local/bin/_${sysext_name}_modprobe_helper"
19+
#!/bin/bash
20+
21+
set -euo pipefail
22+
23+
cleanup() {
24+
if [ -d "$TMP_DIR" ]; then
25+
rm -rf "$TMP_DIR"
26+
fi
27+
}
28+
trap cleanup EXIT
29+
30+
action="Loading"
31+
for arg in "$@"; do
32+
if [[ $arg == "-r" ]]; then
33+
action="Unloading"
34+
fi
35+
done
36+
echo "$action kernel module from a sysext..."
37+
38+
KMOD_PATH="/usr/lib/modules/$(uname -r)"
39+
TMP_DIR="$(mktemp -d)"
40+
TMP_KMOD_PATH="$TMP_DIR/${KMOD_PATH#*/*/}"
41+
42+
if [ ! -d "$TMP_DIR" ]; then
43+
echo "Failed to create temporary directory for depmod"
44+
exit 1
45+
fi
46+
mkdir -p "$TMP_KMOD_PATH"
47+
48+
# copy and symlink files from the system
49+
cp "$KMOD_PATH"/modules.{order,builtin{,.modinfo}} "$TMP_KMOD_PATH"
50+
for dir_name in $(find $KMOD_PATH -maxdepth 1 -mindepth 1 -type d -exec basename {} \;); do
51+
ln -s "$KMOD_PATH/$dir_name" "$TMP_KMOD_PATH/$dir_name"
52+
done
53+
54+
depmod -a -o $TMP_DIR
55+
modprobe --ignore-install -d $TMP_DIR $* || true
56+
EOF
57+
chmod +x "./usr/local/bin/_${sysext_name}_modprobe_helper"
58+
59+
# prevent the sysext from masking /usr/lib/modules/*-flatcar/modules.XXX
60+
find "${module_directory[0]}" -maxdepth 1 -mindepth 1 -type f -delete
61+
}

0 commit comments

Comments
 (0)