[PATCH 0/1] classes/image-postproc: chroot before postprocessing /etc/machine-id

9 views
Skip to first unread message

alexander...@siemens.com

unread,
Jun 27, 2025, 5:48:02 AM6/27/25
to isar-...@googlegroups.com, Alexander Heinisch
From: Alexander Heinisch <alexander...@siemens.com>

We were experimenting with /etc-overlay removal
ending up with systemd detecting first-boot conditions due to
unitinitialized /etc/machine-id.
To circumvent this on ro etc, we put a link on /etc/machine-id to
a mutable location instead. Without chroot writing to /etc/machine-id
linked to e.g. /var/local/machine-id resolves to the hosts /var partition
instead of the file in ${IMAGE_ROOTFS}.
Apart from that overriding the machine-id-commit service was needed
to make this setup work properly. Not sure if a patch for that is
desired as well?

Alexander Heinisch (1):
classes/image-postproc: chroot before postprocessing /etc/machine-id

meta/classes/image-postproc-extension.bbclass | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--
2.39.5

alexander...@siemens.com

unread,
Jun 27, 2025, 5:48:11 AM6/27/25
to isar-...@googlegroups.com, Alexander Heinisch
From: Alexander Heinisch <alexander...@siemens.com>

If /etc/machine-id happens to be a link to e.g. /var/...
the postprocessing overrides build-hosts /var/... instead of
the desired file on the rootfs.

Signed-off-by: Alexander Heinisch <alexander...@siemens.com>
---
meta/classes/image-postproc-extension.bbclass | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/meta/classes/image-postproc-extension.bbclass b/meta/classes/image-postproc-extension.bbclass
index 991bac4c..4f2a3d00 100644
--- a/meta/classes/image-postproc-extension.bbclass
+++ b/meta/classes/image-postproc-extension.bbclass
@@ -58,12 +58,12 @@ image_postprocess_machine_id() {
# systemd(1) takes care of recreating the machine-id on first boot
# for systemd < v247, set to empty string, else set to uninitialized
# (required if initramfs with ro root is used)
- SYSTEMD_VERSION=$( sudo chroot ${IMAGE_ROOTFS} dpkg-query --showformat='${source:Upstream-Version}' --show systemd || echo "0" )
+ SYSTEMD_VERSION=$( sudo chroot '${IMAGE_ROOTFS}' dpkg-query --showformat='${source:Upstream-Version}' --show systemd || echo "0" )
MACHINE_ID="uninitialized"
if dpkg --compare-versions "$SYSTEMD_VERSION" "lt" "247"; then
MACHINE_ID=""
fi
- echo "$MACHINE_ID" | sudo tee '${IMAGE_ROOTFS}/etc/machine-id'
+ echo "$MACHINE_ID" | sudo chroot '${IMAGE_ROOTFS}' tee '/etc/machine-id'
sudo rm -f '${IMAGE_ROOTFS}/var/lib/dbus/machine-id'
}

--
2.39.5

MOESSBAUER, Felix

unread,
Jul 14, 2025, 7:02:36 AM7/14/25
to Heinisch, Alexander, isar-...@googlegroups.com
On Fri, 2025-06-27 at 11:47 +0200, alexander.heinisch via isar-users
wrote:
> From: Alexander Heinisch <alexander...@siemens.com>
>
> If /etc/machine-id happens to be a link to e.g. /var/...
> the postprocessing overrides build-hosts /var/... instead of
> the desired file on the rootfs.
>
> Signed-off-by: Alexander Heinisch <alexander...@siemens.com>
> ---
>  meta/classes/image-postproc-extension.bbclass | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/meta/classes/image-postproc-extension.bbclass
> b/meta/classes/image-postproc-extension.bbclass
> index 991bac4c..4f2a3d00 100644
> --- a/meta/classes/image-postproc-extension.bbclass
> +++ b/meta/classes/image-postproc-extension.bbclass
> @@ -58,12 +58,12 @@ image_postprocess_machine_id() {
>      # systemd(1) takes care of recreating the machine-id on first
> boot
>      # for systemd < v247, set to empty string, else set to
> uninitialized
>      # (required if initramfs with ro root is used)
> -    SYSTEMD_VERSION=$( sudo chroot ${IMAGE_ROOTFS} dpkg-query --
> showformat='${source:Upstream-Version}' --show systemd || echo "0" )
> +    SYSTEMD_VERSION=$( sudo chroot '${IMAGE_ROOTFS}' dpkg-query --
> showformat='${source:Upstream-Version}' --show systemd || echo "0"

Unrelated fix, please move to separate commit. Please also check if a
IMAGE_ROOTFS with special characters works at all (I doubt it).

> )
>      MACHINE_ID="uninitialized"
>      if dpkg --compare-versions "$SYSTEMD_VERSION" "lt" "247"; then
>          MACHINE_ID=""
>      fi
> -    echo "$MACHINE_ID" | sudo tee '${IMAGE_ROOTFS}/etc/machine-id'
> +    echo "$MACHINE_ID" | sudo chroot '${IMAGE_ROOTFS}' tee
> '/etc/machine-id'

Acked!

Felix

>      sudo rm -f '${IMAGE_ROOTFS}/var/lib/dbus/machine-id'
>  }
>  
> --
> 2.39.5

--
Siemens AG
Linux Expert Center
Friedrich-Ludwig-Bauer-Str. 3
85748 Garching, Germany

Reply all
Reply to author
Forward
0 new messages