From: uvv.mail@gmail.com
To: Openembedded-core@lists.openembedded.org
Cc: Vyacheslav Yurkov <uvv.mail@gmail.com>
Subject: [PATCH v7 2/2] classes-recipe: Consolidate machine-id handling
Date: Sat, 1 Mar 2025 22:27:53 +0100 [thread overview]
Message-ID: <20250301212753.78302-2-uvv.mail@gmail.com> (raw)
In-Reply-To: <20250301212753.78302-1-uvv.mail@gmail.com>
From: Vyacheslav Yurkov <uvv.mail@gmail.com>
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>
---
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 f08818db03..378d3bd0d4 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 70ad3670d7..8b5822a0b5 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
}
#
prev parent reply other threads:[~2025-03-01 21:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 21:27 [PATCH v7 1/2] systemd: Build the systemctl executable uvv.mail
2025-03-01 21:27 ` uvv.mail [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250301212753.78302-2-uvv.mail@gmail.com \
--to=uvv.mail@gmail.com \
--cc=Openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox