Skip to content

Commit 3e9383d

Browse files
authored
Merge pull request #2976 from flatcar/danzatt/depmod-fix
build_library: Fix depmod issues with sysext kmods
2 parents 1a65456 + 9c51990 commit 3e9383d

8 files changed

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

0 commit comments

Comments
 (0)