Merge pull request #2976 from flatcar/danzatt/depmod-fix

build_library: Fix depmod issues with sysext kmods
This commit is contained in:
Daniel 2025-08-12 13:25:46 +02:00 committed by GitHub
commit 3e9383d724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
SCRIPT_NAME=$(basename "$(realpath "${BASH_SOURCE[0]}")")
SYSEXT_NAME=${SCRIPT_NAME#sysext_mangle_}
SYSEXT_NAME=${SYSEXT_NAME%.sh}
DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
. "$DIR/sysext_mangle_kmod"
rootfs="${1}"
cd "${rootfs}"
configure_modprobe "$SYSEXT_NAME"

View File

@ -0,0 +1 @@
sysext_mangle_flatcar-nvidia-drivers-535

View File

@ -0,0 +1 @@
sysext_mangle_flatcar-nvidia-drivers-535

View File

@ -0,0 +1 @@
sysext_mangle_flatcar-nvidia-drivers-535

View File

@ -0,0 +1 @@
sysext_mangle_flatcar-nvidia-drivers-535

View File

@ -0,0 +1 @@
sysext_mangle_flatcar-nvidia-drivers-535

View File

@ -3,6 +3,9 @@
set -euo pipefail
rootfs="${1}"
DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
. "$DIR/sysext_mangle_kmod"
pushd "${rootfs}"
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
[Unit]
After=systemd-sysext.service
EOF
configure_modprobe flatcar-zfs
popd

View File

@ -0,0 +1,48 @@
#!/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
}