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

Message ID 20250627094756.151803-2-alexander.heinisch@siemens.com
State New
Headers show
Series classes/image-postproc: chroot before postprocessing /etc/machine-id | expand

Commit Message

alexander.heinisch June 27, 2025, 9:47 a.m. UTC
From: Alexander Heinisch <alexander.heinisch@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.heinisch@siemens.com>
---
 meta/classes/image-postproc-extension.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch

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'
 }