From: "alexander.heinisch via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Cc: jan.kiszka@siemens.com, felix.moessbauer@siemens.com,
cedric.hombourger@siemens.com, wzh@ilbers.de,
Alexander Heinisch <alexander.heinisch@siemens.com>
Subject: [PATCH v4 2/2] classes/image-postproc: Enable systemd units based on systemd presets
Date: Thu, 30 Oct 2025 12:33:32 +0100 [thread overview]
Message-ID: <20251030113332.1809425-3-alexander.heinisch@siemens.com> (raw)
In-Reply-To: <20251030113332.1809425-1-alexander.heinisch@siemens.com>
From: Alexander Heinisch <alexander.heinisch@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.heinisch@siemens.com>
---
RECIPE-API-CHANGELOG.md | 20 +++++++++++++++++++-
meta/classes/image.bbclass | 1 +
meta/classes/rootfs.bbclass | 12 ++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index cf04fa5c..e173ee53 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -790,4 +790,22 @@ unset (the default), `Rules-Requires-Root` will not be added. Otherwise,
Set `Rules-Requires-Root: no` in `debian/control` files to prevent unnecessary
invocation of fakeroot during package builds. This follows Debian guidelines
recommending not to use fakeroot when no privileged operations (e.g., `chown`,
-root file modifications) are required.
+root file modifications) are required.
+
+### 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 08715647..f4b9989c 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 2fef3120..e9e8cde0 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"
@@ -520,6 +521,17 @@ 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() {
+ SYSTEMD_INSTALLED=$(sudo chroot '${ROOTFSDIR}' dpkg-query \
+ --showformat='${db:Status-Status}' \
+ --show systemd || echo "" )
+
+ if (test "$SYSTEMD_INSTALLED" = "installed"); then
+ sudo chroot '${ROOTFSDIR}' systemctl preset-all --preset-mode="enable-only"
+ fi
+}
+
do_rootfs_postprocess[vardeps] = "${ROOTFS_POSTPROCESS_COMMAND}"
do_rootfs_postprocess[network] = "${TASK_USE_SUDO}"
python do_rootfs_postprocess() {
--
2.39.5
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20251030113332.1809425-3-alexander.heinisch%40siemens.com.
prev parent reply other threads:[~2025-10-30 11:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 11:33 [PATCH v4 0/2] " alexander.heinisch via isar-users
2025-10-30 11:33 ` [PATCH v4 1/2] Minor cleanup: Refactor ROOTFS_FEATURES assignment for image to make upcoming changes more easily trackable alexander.heinisch via isar-users
2025-10-30 11:33 ` alexander.heinisch via isar-users [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251030113332.1809425-3-alexander.heinisch@siemens.com \
--to=isar-users@googlegroups.com \
--cc=alexander.heinisch@siemens.com \
--cc=cedric.hombourger@siemens.com \
--cc=felix.moessbauer@siemens.com \
--cc=jan.kiszka@siemens.com \
--cc=wzh@ilbers.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox