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

12 views
Skip to first unread message

alexander...@siemens.com

unread,
Sep 17, 2025, 6:35:27 AMSep 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 AMSep 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 AMSep 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

Heinisch, Alexander

unread,
Oct 21, 2025, 7:23:58 AM (11 days ago) Oct 21
to isar-...@googlegroups.com, Kiszka, Jan, MOESSBAUER, Felix
Any updates on this patchset? Seems it got lost.

BR Alexander

On Wed, 2025-09-17 at 12:35 +0200, alexander...@siemens.com
wrote:
--
Alexander Heinisch
Siemens AG
www.siemens.com

cedric.h...@siemens.com

unread,
Oct 21, 2025, 12:07:20 PM (11 days ago) Oct 21
to Heinisch, Alexander, isar-...@googlegroups.com, Kiszka, Jan, MOESSBAUER, Felix
On Tue, 2025-10-21 at 11:21 +0000, 'Heinisch, Alexander' via isar-users
wrote:
> Any updates on this patchset? Seems it got lost.
>
> BR Alexander
>
> On Wed, 2025-09-17 at 12:35 +0200, alexander...@siemens.com
> wrote:
> > 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"`

Since we have ROOTFS_FEATURES in LIST_VARIABLES (see bitbake.conf), a
more elegant way to opt is IMO:

ROOTFS_FEATURES:append = " ~populate-systemd-preset" # (or
alternatively " -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 Heinisch
> Siemens AG
> www.siemens.com
>

--
Cedric Hombourger
Siemens AG
www.siemens.com

Zhihang Wei

unread,
Oct 23, 2025, 5:29:54 AM (9 days ago) Oct 23
to Heinisch, Alexander, isar-...@googlegroups.com, Kiszka, Jan, MOESSBAUER, Felix
Hi,

when testing this patch on CI, the following test failed:
- citest.py:DevTest.test_dev

Error log from avocado:
2025-10-22 17:42:41,056 cibuilder        L0322 ERROR| ERROR:
mc:qemuarm-bookworm:isar-image-base-sdk-1.0-r0 do_rootfs_postprocess:
ExecutionError('/work/build/tmp/work/debian-bookworm-armhf/isar-image-base-sdk-qemuarm/1.0-r0/temp/run.image_postprocess_populate_systemd_preset.287029',
127, None, None)
2025-10-22 17:42:41,059 cibuilder        L0322 ERROR| ERROR: Logfile of
failure stored in:
/work/build/tmp/work/debian-bookworm-armhf/isar-image-base-sdk-qemuarm/1.0-r0/temp/log.do_rootfs_postprocess.287029
......
2025-10-22 17:42:41,983 cibuilder        L0322 ERROR| ERROR: Task
(mc:qemuarm-bookworm:virtual:sdk:/work/meta-isar/recipes-core/images/isar-image-base.bb:do_rootfs_postprocess)
failed with exit code '1'
......

Error log from log.do_rootfs_postprocess.287029:
......
DEBUG: Executing shell function rootfs_cleanup_isar_apt
DEBUG: Shell function rootfs_cleanup_isar_apt finished
DEBUG: Executing shell function image_postprocess_populate_systemd_preset
chroot: failed to run command ‘systemctl’: No such file or directory
WARNING: exit code 127 from a shell command.
DEBUG: Executing shell function rootfs_do_umounts
DEBUG: Shell function rootfs_do_umounts finished
DEBUG: Python function do_rootfs_postprocess finished

You can redo the test on your machine using avocado:
1. Have a clean clone of isar, checkout to branch next and apply your
patches:
$ git clone -b next https://github.com/ilbers/isar.git
$ cd isar
$ git am /path-to/0001-my-contribution-to-isar.patch
2.Run kas shell, setup CI prerequisites (avocado, qemu) and cleanup:
$ ./kas/kas-container shell kas/isar.yaml --command \
    "rm -rf /work/build/conf && /work/scripts/ci_setup.sh"
3.Run the failed test:
$ cd /work/testsuite
$ avocado run citest.py:DevTest.test_dev --max-parallel-tasks=1

On my machine (CPU: AMD 7840U, 32G RAM) it took around 16 minutes for the
error to show up.

Best regards,
Zhihang

Heinisch, Alexander

unread,
Oct 30, 2025, 7:33:13 AM (2 days ago) Oct 30
to isar-...@googlegroups.com, cedric.h...@siemens.com, Kiszka, Jan, MOESSBAUER, Felix
On Tue, 2025-10-21 at 16:07 +0000, Hombourger, Cedric (FT FDS CES LX)
wrote:
Thx, for pointing that out, but I decided, to keep opting out in v4 as
is. Imo ":remove" is easier to read than "-" inbetween and also more
intuitive than "~".

BR Alexander

alexander...@siemens.com

unread,
Oct 30, 2025, 7:33:40 AM (2 days ago) Oct 30
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, cedric.h...@siemens.com, w...@ilbers.de, 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 v1:
- Documented changes in RECIPE-API-CHANGELOG.md

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

Changes since v3:
- Check if systemctl is installed on the target rootfs before invoking it.

=> Tests fixed:
```
$ avocado run citest.py:DevTest.test_dev --max-parallel-tasks=1
JOB ID : 131df887f543d582a4e23d18759ef4d908a13485
JOB LOG : /tmp/tmpaj335w6s/avocado/job-results/job-2025-10-30T10.32-131df88/job.log
(1/6) citest.py:DevTest.test_dev: STARTED
(1/6) citest.py:DevTest.test_dev: PASS (611.18 s)
(2/6) citest.py:DevTest.test_dev_apps: STARTED
(2/6) citest.py:DevTest.test_dev_apps: PASS (625.95 s)
(3/6) citest.py:DevTest.test_dev_rebuild: STARTED
(3/6) citest.py:DevTest.test_dev_rebuild: PASS (243.81 s)
(4/6) citest.py:DevTest.test_dev_run_amd64_bookworm: STARTED
(4/6) citest.py:DevTest.test_dev_run_amd64_bookworm: PASS (72.85 s)
(5/6) citest.py:DevTest.test_dev_run_arm64_bookworm: STARTED
(5/6) citest.py:DevTest.test_dev_run_arm64_bookworm: PASS (35.98 s)
(6/6) citest.py:DevTest.test_dev_run_arm_bookworm: STARTED
(6/6) citest.py:DevTest.test_dev_run_arm_bookworm: PASS (40.02 s)
RESULTS : PASS 6 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME : 1634.63 s
```

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 | 20 +++++++++++++++++++-
meta/classes/image.bbclass | 10 +++++++++-
meta/classes/rootfs.bbclass | 12 ++++++++++++
3 files changed, 40 insertions(+), 2 deletions(-)

--
2.39.5

alexander...@siemens.com

unread,
Oct 30, 2025, 7:33:41 AM (2 days ago) Oct 30
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, cedric.h...@siemens.com, w...@ilbers.de, 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 441ea936..08715647 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'}"

alexander...@siemens.com

unread,
Oct 30, 2025, 7:33:42 AM (2 days ago) Oct 30
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, cedric.h...@siemens.com, w...@ilbers.de, 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 | 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
Reply all
Reply to author
Forward
0 new messages