flatcar-scripts/build_library/sysext_mangle_flatcar-zfs
Jeremi Piotrowski 87262e4f91 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 <jpiotrowski@microsoft.com>
2024-03-11 11:57:45 +00:00

44 lines
1.5 KiB
Bash
Executable File

#!/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 <<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
popd