flatcar-scripts/build_library/sysext_mangle_flatcar-zfs
Daniel Zatovic 9c51990f8a 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>
2025-08-11 14:34:27 +02:00

48 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
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/}
rm -rf ./usr/lib/dracut/
rm -rf ./usr/share/initramfs-tools
rm -rf ./usr/src
mkdir -p ./usr/share/zfs/etc
rm -rf ./etc/{csh.env,environment.d/,profile.env}
cp -a ./etc/. ./usr/share/zfs/etc/
pushd ./usr/lib/systemd/system
while read cmd unit; do
if [ "$cmd" = enable ]; then
target=$(awk -F= '/WantedBy/ { print $2 }' $unit)
mkdir -p "${target}.wants"
ln -svr "${unit}" "${target}".wants/
fi
done < <(grep -v '^#' "${rootfs}"/usr/lib/systemd/system-preset/50-zfs.preset)
mkdir -p "multi-user.target.d"
{ echo "[Unit]"; echo "Upholds=zfs.target"; } > "multi-user.target.d/10-zfs.conf"
popd
mkdir -p ./usr/lib/tmpfiles.d
cat <<EOF >./usr/lib/tmpfiles.d/10-zfs.conf
d /etc/zfs 0755 root root - -
L /etc/zfs/zed.d - - - - /usr/share/zfs/etc/zfs/zed.d
L /etc/zfs/zfs-functions - - - - /usr/share/zfs/etc/zfs/zfs-functions
L /etc/zfs/zpool.d - - - - /usr/share/zfs/etc/zfs/zpool.d
C /etc/systemd/system/systemd-udevd.service.d/10-zfs.conf - - - - /usr/lib/systemd/system/systemd-udevd.service.d/10-zfs.conf
EOF
mkdir -p ./usr/lib/systemd/system/systemd-udevd.service.d
cat <<EOF >./usr/lib/systemd/system/systemd-udevd.service.d/10-zfs.conf
[Unit]
After=systemd-sysext.service
EOF
configure_modprobe flatcar-zfs
popd