From 890b81cdfadc427189eff4bbd2c24e32eb286126 Mon Sep 17 00:00:00 2001 From: Vyacheslav Yurkov Date: Sat, 1 Mar 2025 22:27:53 +0100 Subject: [PATCH] classes-recipe: Consolidate machine-id handling 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 Signed-off-by: Richard Purdie --- meta/classes-recipe/image.bbclass | 9 +------ .../rootfs-postcommands.bbclass | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass index f08818db031..378d3bd0d4a 100644 --- a/meta/classes-recipe/image.bbclass +++ b/meta/classes-recipe/image.bbclass @@ -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 = "" diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass b/meta/classes-recipe/rootfs-postcommands.bbclass index 70ad3670d7f..8b5822a0b5c 100644 --- a/meta/classes-recipe/rootfs-postcommands.bbclass +++ b/meta/classes-recipe/rootfs-postcommands.bbclass @@ -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 } # -- 2.47.3