Skip to content

Commit 01eea0f

Browse files
committed
Use systemd-confext instead of custom /etc overlay mount
For A/B-updated /etc contents we used a custom overlay mount that provides the default files through a lowerdir loaded from /usr. Since then we upstreamed mutable systemd-confext support and now we can switch to it. This pulls in flatcar/init#138 and flatcar/bootengine#115 together with backported systemd patches that have opened or merged upstream PRs to fix --root= issues and add a refresh skip check to prevent boot disruptions due to the multiple daemon reloads and - more important - the missing atomic remount that would mean /etc is gone for a few milliseconds during boot. The skip logic works best with verity hashes and thus the default confext must be a verity extension image. User-provided confext don't work well yet unless they use verity due to the missing atomic remount and reliance on the skipping logic. We also need to look into stacking order and other mutabiliy settings. The backported systemd patches relate to the following upstream PRs: systemd/systemd#39843 for vpick-Don-t-use-openat-directly-but-resolve-symlinks discover-image-Follow-symlinks-in-a-given-root sysext-Use-correct-image-name-for-extension-release test-Add-tests-for-handling-symlinks-with-systemd-sy Note that the patch in the PR relies on 0859fe3f32774f1e0c787974cc252ff922a1b868 but the backport patch not. systemd/systemd#39980 for sysext-Create-mutable-directory-with-the-right-mode sysext-Skip-refresh-if-no-changes-are-found systemd/systemd#39991 for sysext-Get-verity-user-certs-from-given-root systemd/systemd#40063 for sysext-Fix-config-file-support-with-root which relies on systemd/systemd#38250 for man-sysext.conf-add-systemd-sysext-config-files sysext-introduce-global-config-file sysext-support-ImagePolicy-global-config-option Signed-off-by: Kai Lueke <kailuke@microsoft.com>
1 parent c24579a commit 01eea0f

18 files changed

Lines changed: 2691 additions & 21 deletions

‎build_library/build_image_util.sh‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,35 @@ EOF
743743
if [[ $(sudo find "${root_fs_dir}/usr/share/flatcar/etc" -size +0 ! -type d 2>/dev/null | wc -l) -gt 0 ]]; then
744744
die "Unexpected non-empty files in ${root_fs_dir}/usr/share/flatcar/etc"
745745
fi
746+
# Some backwards-compat symlinks still use this folder as target,
747+
# we can't remove it yet
746748
sudo rm -rf "${root_fs_dir}/usr/share/flatcar/etc"
747749
sudo cp -a "${root_fs_dir}/etc" "${root_fs_dir}/usr/share/flatcar/etc"
748-
749-
# Remove the rootfs state as it should be recreated through the
750-
# tmpfiles and may not be present on updating machines. This
751-
# makes sure our tests cover the case of missing files in the
750+
# Now set up a default confext and enable it.
751+
# It's important to use dm-verity not only for stricter image policies
752+
# but also because it allows us the refresh to identify this image and
753+
# skip setting it up again in the final boot, which not only saves us
754+
# a daemon-reload during boot but also from /etc contents shortly
755+
# disappearing until systemd-sysext uses mount beneath for an atomic
756+
# remount. Instead of a temporary directory we first prepare it as
757+
# folder and then convert it to a DDI and remove the folder.
758+
sudo rm -rf "${root_fs_dir}/usr/lib/confexts/00-flatcar-default"
759+
sudo mkdir -p "${root_fs_dir}/usr/lib/confexts/00-flatcar-default"
760+
# Do a copy because we keep /etc for the flatcar (.tar) container and the developer container
761+
sudo cp -a "${root_fs_dir}/etc" "${root_fs_dir}/usr/lib/confexts/00-flatcar-default/etc"
762+
sudo mkdir -p "${root_fs_dir}/usr/lib/confexts/00-flatcar-default/etc/extension-release.d/"
763+
echo ID=_any | sudo tee "${root_fs_dir}/usr/lib/confexts/00-flatcar-default/etc/extension-release.d/extension-release.00-flatcar-default" > /dev/null
764+
sudo systemd-repart \
765+
--private-key="${SYSEXT_SIGNING_KEY_DIR}/sysexts.key" \
766+
--certificate="${SYSEXT_SIGNING_KEY_DIR}/sysexts.crt" \
767+
--make-ddi=confext \
768+
--copy-source="${root_fs_dir}/usr/lib/confexts/00-flatcar-default" \
769+
"${root_fs_dir}/usr/lib/confexts/00-flatcar-default.raw"
770+
sudo rm -rf "${root_fs_dir}/usr/lib/confexts/00-flatcar-default"
771+
772+
# Remove the rootfs state as it should be recreated through tmpfiles
773+
# (and for /etc we use a confext) and may not be present on updating machines.
774+
# This makes sure our tests cover the case of missing files in the
752775
# rootfs and don't rely on the new image. Not done for the developer
753776
# container.
754777
if [[ -n "${image_kernel}" ]]; then
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Switched `/etc/` from a custom overlayfs for A/B updates to using a systemd-confext extension providing the default contents by using systemd-confext in the mutable mode where `/etc/` gets used as upperdir [scripts#3555](https://github.com/flatcar/scripts/pull/3555)
2+
- Moved systemd-sysext image mounting into the initrd, so that system extensions can better define the behavior of the final system at boot without workarounds to apply settings late at boot. This means `.wants` symlinks for systemd units work as expected now and, therefore, we dropped the `ensure-sysext.service` workaround. We still recommend extensions to keep their workarounds, e.g., using `.upholds` instead of `.wants`, to better support live reloading. A skipping logic prevents an extension refresh late at boot but only if no changes were found. For extensions that are not stored on a custom filesystem, such as a separate `/var` partition, the new extension mounting from the initrd won't be able to load them early but they will be picked up late at boot through the extension refresh. This is another case where it's good if extensions keep workarounds for late loading.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DIST coreos-init-860090d932a0bcdf71a73619f270845a06b64af0.tar.gz 59420 BLAKE2B 4e68bf5e2f5d64a0c701cbfccf8641f362597073f599ad7e14816e6eb2167609b2312b81a40276736441f51cc1833677a985a3f8d81a21879b987028e60f8d0a SHA512 357f3ff2ac7e4f2ef412626674f8e81c71f38924b80d54fcdf23246c772373e6a6f9f940f66fcab19f09b759d547b7600c6fb97171c95db97e208392d66ce8ca
1+
DIST coreos-init-ca7b51b85e303d95a38bc6d20f459aac07439eb0.tar.gz 59695 BLAKE2B 02c67fa98ee0b97123cb322fb6eabacf7ae7a282914408a8246371552ed222cc3eb56f27d5c42230158a4f7907db9cdfd4b7f51e96995aac2a0f903ff34d034d SHA512 d1282837b52f550855e6c0990796e270c32d7b0882b062f401aff9c9eea7a7c8fba4f2a051f9c42be9316022fa8ee214dc28a8078b306577629d01d96e32d5e8

‎sdk_container/src/third_party/coreos-overlay/coreos-base/coreos-init/coreos-init-9999.ebuild‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [[ ${PV} == 9999 ]]; then
1414
EGIT_REPO_URI="https://github.com/flatcar/init.git"
1515
inherit git-r3
1616
else
17-
EGIT_VERSION="860090d932a0bcdf71a73619f270845a06b64af0" # flatcar-master
17+
EGIT_VERSION="1660f54f79dbba285a64c52d3338f5566e1d770d" # flatcar-master
1818
SRC_URI="https://github.com/flatcar/init/archive/${EGIT_VERSION}.tar.gz -> ${PN}-${EGIT_VERSION}.tar.gz"
1919
S="${WORKDIR}/init-${EGIT_VERSION}"
2020
KEYWORDS="amd64 arm arm64 x86"

‎sdk_container/src/third_party/coreos-overlay/coreos/config/env/sys-apps/systemd‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,6 @@ EOF
160160
-e '/^C!* \/etc\/pam\.d/d' \
161161
-e '/^C!* \/etc\/issue/d' || die
162162

163-
(
164-
# Some OEMs prefer chronyd, so allow them to replace
165-
# systemd-timesyncd with it.
166-
insinto "$(systemd_get_systemunitdir)/systemd-timesyncd.service.d"
167-
newins - flatcar.conf <<'EOF'
168-
# Allow sysexts to ship timesyncd replacements which can have
169-
# a Conflicts=systemd-timesyncd directive that would result
170-
# in systemd-timesyncd not being started.
171-
[Unit]
172-
After=ensure-sysext.service
173-
EOF
174-
)
175-
176163
(
177164
# Allow @mount syscalls for systemd-udevd.service
178165
insinto "$(systemd_get_systemunitdir)/systemd-udevd.service.d"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 6f4b065b626edd8a06ff0c8028173e060b5e444b Mon Sep 17 00:00:00 2001
2+
From: Kai Lueke <kailuke@microsoft.com>
3+
Date: Thu, 20 Nov 2025 23:43:55 +0900
4+
Subject: [PATCH 03/10] vpick: Don't use openat directly but resolve symlinks
5+
in given root
6+
7+
With systemd-sysext --root= all symlinks should be followed relative to
8+
the given root and direct openat usage doesn't work.
9+
Change the openat call to use the chase helper function to resolve the
10+
symlink in the given root.
11+
---
12+
src/shared/vpick.c | 4 ++--
13+
1 file changed, 2 insertions(+), 2 deletions(-)
14+
15+
diff --git a/src/shared/vpick.c b/src/shared/vpick.c
16+
index b1b2d93054..dfe58cafa5 100644
17+
--- a/src/shared/vpick.c
18+
+++ b/src/shared/vpick.c
19+
@@ -471,9 +471,9 @@ static int make_choice(
20+
if (!p)
21+
return log_oom_debug();
22+
23+
- object_fd = openat(dir_fd, best_filename, O_CLOEXEC|O_PATH);
24+
+ object_fd = chase_and_openat(toplevel_fd, p, CHASE_AT_RESOLVE_IN_ROOT, O_PATH|O_CLOEXEC, NULL);
25+
if (object_fd < 0)
26+
- return log_debug_errno(errno, "Failed to open '%s/%s': %m",
27+
+ return log_debug_errno(object_fd, "Failed to open '%s/%s': %m",
28+
empty_to_root(toplevel_path), skip_leading_slash(inode_path));
29+
30+
return pin_choice(
31+
--
32+
2.52.0
33+

0 commit comments

Comments
 (0)