[PATCH v3 0/2] Enable systemd units based on systemd presets

4 views
Skip to first unread message

alexander...@siemens.com

unread,
Sep 17, 2025, 6:35:27 AM (10 days ago) Sep 17
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, Alexander Heinisch
From: Alexander Heinisch <alexander...@siemens.com>

By default population of the presets is automatically done by systemd
on first-boot.

There were several issues with that:

1. The rootfs we get as a build artifact does not reflect the actual
system running in the field.

2. For setups without writeable /etc this fails. With that addition
it happens already at build time.

Note: Additional services are enabled only. Services already enabled
during the package installation won't be changed.

Opt-out: `ROOTFS_FEATURES:remove = "populate-systemd-preset"`

Changes since v2:
- Enable postprocessing to populate systemd presets via ROOTFS_FEATURES

Alexander Heinisch (2):
Minor cleanup: Refactor ROOTFS_FEATURES assignment for image to make
upcoming changes more easily trackable.
classes/image-postproc: Enable systemd units based on systemd presets

RECIPE-API-CHANGELOG.md | 18 ++++++++++++++++++
meta/classes/image.bbclass | 10 +++++++++-
meta/classes/rootfs.bbclass | 6 ++++++
3 files changed, 33 insertions(+), 1 deletion(-)

--
2.39.5

alexander...@siemens.com

unread,
Sep 17, 2025, 6:35:32 AM (10 days ago) Sep 17
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, Alexander Heinisch
From: Alexander Heinisch <alexander...@siemens.com>

Signed-off-by: Alexander Heinisch <alexander...@siemens.com>
---
meta/classes/image.bbclass | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index bd1b8552..d833564f 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -66,7 +66,14 @@ inherit multiarch
inherit essential

ROOTFSDIR = "${IMAGE_ROOTFS}"
-ROOTFS_FEATURES += "clean-package-cache clean-pycache generate-manifest export-dpkg-status clean-log-files clean-debconf-cache"
+ROOTFS_FEATURES += "\
+ clean-package-cache \
+ clean-pycache \
+ generate-manifest \
+ export-dpkg-status \
+ clean-log-files \
+ clean-debconf-cache \
+ "
# when using a custom initrd, do not generate one as part of the image rootfs
ROOTFS_FEATURES += "${@ '' if d.getVar('INITRD_IMAGE') == '' else 'no-generate-initrd'}"
ROOTFS_PACKAGES += "${IMAGE_PREINSTALL} ${@isar_multiarch_packages('IMAGE_INSTALL', d)}"
--
2.39.5

alexander...@siemens.com

unread,
Sep 17, 2025, 6:35:33 AM (10 days ago) Sep 17
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, Alexander Heinisch
From: Alexander Heinisch <alexander...@siemens.com>

By default population of the presets is automatically done by systemd
on first-boot.

There were several issues with that:

1. The rootfs we get as a build artifact does not reflect the actual
system running in the field.

2. For setups without writeable /etc this fails. With that addition
it happens already at build time.

Note: Additional services are enabled only. Services already enabled
during the package installation won't be changed.

Opt-out: `ROOTFS_FEATURES:remove = "populate-systemd-preset"`

Signed-off-by: Alexander Heinisch <alexander...@siemens.com>
---
RECIPE-API-CHANGELOG.md | 18 ++++++++++++++++++
meta/classes/image.bbclass | 1 +
meta/classes/rootfs.bbclass | 6 ++++++
3 files changed, 25 insertions(+)

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 92e7811c..f2e21088 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -741,3 +741,21 @@ By setting `MS_TPM_20_REF_DIR` in an optee-ftpm recipe, it is now possible to
use the new optee_ftpm code base from the OP-TEE project. That variable has to
point to a subdir in `WORKDIR` which contains the unpacked ms-tpm-20-ref source
code.
+
+### Populate systemd units based on presets during image postprocessing
+
+By default population of the presets is automatically done by systemd
+on first-boot.
+
+There were several issues with that:
+
+1. The rootfs we get as a build artifact does not reflect the actual
+system running in the field.
+
+2. For setups without writeable /etc this fails. With that addition
+it happens already at build time.
+
+**Note**: Additional services are enabled only. Services already enabled
+during the package installation won't be changed.
+
+Opt-out: `ROOTFS_FEATURES:remove = "populate-systemd-preset"`
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index d833564f..44b59420 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -73,6 +73,7 @@ ROOTFS_FEATURES += "\
export-dpkg-status \
clean-log-files \
clean-debconf-cache \
+ populate-systemd-preset \
"
# when using a custom initrd, do not generate one as part of the image rootfs
ROOTFS_FEATURES += "${@ '' if d.getVar('INITRD_IMAGE') == '' else 'no-generate-initrd'}"
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index ebe3bf4a..fdfad2fa 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -15,6 +15,7 @@ ROOTFS_BASE_DISTRO ?= "${BASE_DISTRO}"
# 'export-dpkg-status' - exports /var/lib/dpkg/status file to ${ROOTFS_DPKGSTATUS_DEPLOY_DIR}
# 'clean-log-files' - delete log files that are not owned by packages
# 'no-generate-initrd' - do not generate debian default initrd
+# 'populate-systemd-preset' - enable systemd units according to systemd presets
ROOTFS_FEATURES ?= ""

ROOTFS_APT_ARGS="install --yes -o Debug::pkgProblemResolver=yes"
@@ -429,6 +430,11 @@ rootfs_cleanup_base_apt() {
EOSUDO
}

+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'populate-systemd-preset', 'image_postprocess_populate_systemd_preset', '', d)}"
+image_postprocess_populate_systemd_preset() {
+ sudo chroot '${ROOTFSDIR}' systemctl preset-all --preset-mode="enable-only"
+}
+
do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND}"
do_rootfs_postprocess[network] = "${TASK_USE_SUDO}"
python do_rootfs_postprocess() {
--
2.39.5

Reply all
Reply to author
Forward
0 new messages