]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
classes-recipe: Consolidate machine-id handling
authorVyacheslav Yurkov <uvv.mail@gmail.com>
Sat, 1 Mar 2025 21:27:53 +0000 (22:27 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 9 Mar 2025 20:09:10 +0000 (20:09 +0000)
Whenever Systemd is used as an init manager, it requires a machine-id
file to be present / initialized / or have the RW rootfs. This change
does not introduce a new functionality, but rather merges everything we
do with machine-id in one place.

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/image.bbclass
meta/classes-recipe/rootfs-postcommands.bbclass

index f08818db031f29dcfffba30af3bc7156d03b6a4a..378d3bd0d4a421c2469d3bb2b6c58c529162d8f3 100644 (file)
@@ -699,13 +699,6 @@ reproducible_final_image_task () {
     find  ${IMAGE_ROOTFS} -print0 | xargs -0 touch -h  --date=@$REPRODUCIBLE_TIMESTAMP_ROOTFS
 }
 
-systemd_preset_all () {
-    if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then
-       systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all
-       systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only preset-all
-    fi
-}
-
-IMAGE_PREPROCESS_COMMAND:append = " ${@ 'systemd_preset_all' if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else ''} reproducible_final_image_task "
+IMAGE_PREPROCESS_COMMAND:append = " reproducible_final_image_task "
 
 CVE_PRODUCT = ""
index 70ad3670d7f28cfc25450a3a0fc596e9fd1f1046..8b5822a0b5c24c8fd31d0d79dfa2083c5450dea7 100644 (file)
@@ -43,7 +43,7 @@ ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest"
 POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log"
 # Set default target for systemd images
 SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains_any("IMAGE_FEATURES", [ "x11-base", "weston" ], "graphical.target", "multi-user.target", d)}'
-ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target systemd_sysusers_check", "", d)}'
+ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target systemd_sysusers_check systemd_handle_machine_id", "", d)}'
 
 ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile'
 
@@ -173,6 +173,23 @@ python systemd_sysusers_check() {
                     check_group_exists(d, sid)
 }
 
+systemd_handle_machine_id() {
+    if ${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false", d)}; then
+        # Create machine-id
+        # 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable
+        touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id
+    fi
+    # In order to be backward compatible with the previous OE-core specific (re)implementation of systemctl
+    # we need to touch machine-id when handling presets and when the rootfs is NOT stateless
+    if ${@ 'true' if not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else 'false'}; then
+        touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id
+        if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then
+            systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all
+            systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only preset-all
+        fi
+    fi
+}
+
 #
 # A hook function to support read-only-rootfs IMAGE_FEATURES
 #
@@ -224,12 +241,6 @@ read_only_rootfs_hook () {
                        ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
                fi
        fi
-
-       if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
-       # Create machine-id
-       # 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable
-               touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id
-       fi
 }
 
 #