From 87262e4f915c03596547d63159d2c30ac459beeb Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Mon, 11 Mar 2024 09:41:01 +0000 Subject: [PATCH] build_library: Add mangle script for zfs sysext There are two challenges with the sysext: it needs config files in /etc and it needs udev rules for mounting during boot to work. The etc files are placed in the standard flatcar etc overlay path but the overlay is mounted from the initrd. So instead, we create a tmpfiles.d rule that symlinks the best important files over. For the udev issue, we create a drop-in in /etc that ensures udev runs after systemd-sysext. We also can't rely on systemd presets to work, so instead parse the preset file and statically create the service dependencies. For the primary zfs.target we rely on an Upholds entry. Users can still disabled unwanted services if they want. We also removed unnecessary files: - development files - initramfs related scripts Signed-off-by: Jeremi Piotrowski --- build_library/sysext_mangle_flatcar-zfs | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 build_library/sysext_mangle_flatcar-zfs diff --git a/build_library/sysext_mangle_flatcar-zfs b/build_library/sysext_mangle_flatcar-zfs new file mode 100755 index 0000000000..13e9135b3c --- /dev/null +++ b/build_library/sysext_mangle_flatcar-zfs @@ -0,0 +1,43 @@ +#!/bin/bash + +set -euo pipefail +rootfs="${1}" + +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 <./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 <./usr/lib/systemd/system/systemd-udevd.service.d/10-zfs.conf +[Unit] +After=systemd-sysext.service +EOF +popd