[v2] classes/image-postproc: Enable systemd units based on systemd presets

Message ID 20250917082426.48335-1-alexander.heinisch@siemens.com
State New
Headers show
Series [v2] classes/image-postproc: Enable systemd units based on systemd presets | expand

Commit Message

alexander.heinisch Sept. 17, 2025, 8:24 a.m. UTC
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_POSTPROCESS_COMMAND:remove = "image_postprocess_populate_systemd_preset"`

Signed-off-by: Alexander Heinisch <alexander.heinisch@siemens.com>
---
 RECIPE-API-CHANGELOG.md                       | 18 ++++++++++++++++++
 meta/classes/image-postproc-extension.bbclass |  5 +++++
 2 files changed, 23 insertions(+)

Comments

MOESSBAUER, Felix Sept. 17, 2025, 8:51 a.m. UTC | #1
On Wed, 2025-09-17 at 10:24 +0200, alexander.heinisch@siemens.com
wrote:
> 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_POSTPROCESS_COMMAND:remove = "image_postprocess_populate_systemd_preset"`

Hi,

please make it a rootfs feature (e.g. populate-systemd-preset) and
enable it in the image.bbclass. Apart from that, the change is fine.

Best regards,
Felix

> 
> Signed-off-by: Alexander Heinisch <alexander.heinisch@siemens.com>
> ---
>  RECIPE-API-CHANGELOG.md                       | 18 ++++++++++++++++++
>  meta/classes/image-postproc-extension.bbclass |  5 +++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
> index 92e7811c..6c48b823 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_POSTPROCESS_COMMAND:remove = "image_postprocess_populate_systemd_preset"`
> diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
> index 991bac4c..269b86c0 100644
> --- a/meta/classes/image-postproc-extension.bbclass
> +++ b/meta/classes/image-postproc-extension.bbclass
> @@ -95,3 +95,8 @@ image_posprocess_disable_systemd_firstboot() {
>          fi
>      fi
>  }
> +
> +ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_populate_systemd_preset"
> +image_postprocess_populate_systemd_preset() {
> +    sudo chroot '${ROOTFSDIR}' systemctl preset-all --preset-mode="enable-only"
> +}
> -- 
> 2.39.5

Patch

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 92e7811c..6c48b823 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_POSTPROCESS_COMMAND:remove = "image_postprocess_populate_systemd_preset"`
diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
index 991bac4c..269b86c0 100644
--- a/meta/classes/image-postproc-extension.bbclass
+++ b/meta/classes/image-postproc-extension.bbclass
@@ -95,3 +95,8 @@  image_posprocess_disable_systemd_firstboot() {
         fi
     fi
 }
+
+ROOTFS_POSTPROCESS_COMMAND =+ "image_postprocess_populate_systemd_preset"
+image_postprocess_populate_systemd_preset() {
+    sudo chroot '${ROOTFSDIR}' systemctl preset-all --preset-mode="enable-only"
+}