Skip to content

Commit f7f20c1

Browse files
committed
initrd-setup-root: Use systemd-confext instead of custom overlay mount
So far we had a custom overlay mount for /etc that provided the A/B updated files from /usr in a lowerdir. Since then we upstreamed a mutable mode for sysext and confext. We can now switch over to it and provide a default confext by using the mutable mode. Because there is no atomic remount yet and also because we want to avoid daemon reloads during boot, this relies on a new skip logic in systemd-sysext/confext to only refresh in the final system boot when changes are found. Through only using verity images we know that no changes can be there because they get compared by hash and not mtime. When we would hit a refresh during boot then /etc contents are shortly gone and services sometimes fail during boot. A bit specific to Flatcar/Ignition is that we load confext twice in the initrd, once because we have a default confext that provides /etc contents for Ignition and a second time for loading user confexts for the final system (when users added new ones through Ignition). Signed-off-by: Kai Lueke <[email protected]>
1 parent 5d3ac48 commit f7f20c1

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

dracut/99setup-root/initrd-setup-root

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ COREOS_BLANK_MACHINE_ID="42000000000000000000000000000042"
3232
MACHINE_ID_FILE="/sysroot/etc/machine-id"
3333

3434
# Allow to rerun the script
35-
if usrbin mountpoint -q /sysroot/etc; then
36-
umount /sysroot/etc
35+
if SYSTEMD_IN_INITRD=0 systemd-confext --root=/sysroot status | grep flatcar-default; then
36+
SYSTEMD_IN_INITRD=0 systemd-confext --root=/sysroot unmerge
3737
fi
3838

3939
function selectiveosreset() {
@@ -159,9 +159,21 @@ if [ ! -e "/sysroot/etc/.no-dup-update" ]; then
159159
walksysroot /etc overlaycleanup
160160
fi
161161

162-
# Set up overlay mount for /etc (as long as we can't use syscfg for that)
163-
mkdir -p /sysroot/.etc-work
164-
mount -t overlay overlay -o lowerdir=/sysroot/usr/share/flatcar/etc,upperdir=/sysroot/etc,workdir=/sysroot/.etc-work,redirect_dir=on,metacopy=off,noatime /sysroot/etc
162+
# Set up overlay mount for /etc (done here until we have an upstream systemd unit doing it)
163+
# This is done early here so that Ignition and the Flatcar extension fetching and A/B setup can use /etc
164+
mkdir -p /sysroot/var/lib/extensions.mutable/
165+
if [ ! -L /sysroot/var/lib/extensions.mutable/etc ] && [ ! -e /sysroot/var/lib/extensions.mutable/etc ]; then
166+
ln -s /etc /sysroot/var/lib/extensions.mutable/etc
167+
fi
168+
# Workaround until 259: Set SYSTEMD_IN_INITRD because even with --root=
169+
# this would otherwise look for initrd extension metadata.
170+
SYSTEMD_IN_INITRD=0 systemd-confext --root=/sysroot merge
171+
SYSTEMD_IN_INITRD=0 systemd-confext --root=/sysroot status | grep flatcar-default || { echo "error: flatcar-default confext not loaded" ; exit 1 ; }
172+
# Even when the planned sysext/confext .services units are there
173+
# the above call should stay because we first need confext for Ignition
174+
# to have default files but then we need to reload for any user confexts
175+
# to be applied and we can later rely on the confext/sysext .services
176+
# for that while the above call is specific to Flatcar/Ignition.
165177

166178
# PXE initrds may provide OEM. Despite OEM partition being moved to
167179
# /oem in general, we keep checking /usr/share/oem in initrds to avoid

dracut/99setup-root/initrd-setup-root-after-ignition

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ for NAME in $(grep -h -o '^[^#]*' /sysroot/etc/flatcar/enabled-sysext.conf /sysr
166166
rm -f "/sysroot/etc/extensions/flatcar-${NAME}.raw"
167167
fi
168168
done
169+
170+
# Here we load a second time so that any user-supplied configuration extensions are present at boot
171+
SYSTEMD_IN_INITRD=0 systemd-confext --root=/sysroot refresh
172+
# Then for the first time we can also apply system extensions so that the final system has them at boot
173+
# (done here until we have an upstream systemd unit doing it).
174+
SYSTEMD_IN_INITRD=0 systemd-sysext --root=/sysroot merge
175+
# Once the planned sysext/confext .services units are there we can remove the two calls above and
176+
# order them to start after initrd-setup-root-after-ignition.service (sysext after confext)

dracut/99setup-root/module-setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ install() {
2121
"${systemdsystemunitdir}/initrd-setup-root-after-ignition.service"
2222
inst_script "$moddir/gpg-agent-wrapper" \
2323
"/usr/bin/gpg-agent"
24+
25+
inst_multiple systemd-sysext systemd-confext
2426
}

0 commit comments

Comments
 (0)