diff options
author | Vyacheslav Yurkov <uvv.mail@gmail.com> | 2025-03-01 22:27:53 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-03-09 20:10:06 +0000 |
commit | 2fe7f46e1779fb391512ae1832508c0baed96f41 (patch) | |
tree | e98888c500b30677c71ed031544253ad4838a831 /meta | |
parent | 03b8e2ec1e43c2ff69bfdb3339b329a6c95cc71c (diff) | |
download | poky-2fe7f46e1779fb391512ae1832508c0baed96f41.tar.gz |
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.
(From OE-Core rev: 890b81cdfadc427189eff4bbd2c24e32eb286126)
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes-recipe/image.bbclass | 9 | ||||
-rw-r--r-- | meta/classes-recipe/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 () { | |||
699 | find ${IMAGE_ROOTFS} -print0 | xargs -0 touch -h --date=@$REPRODUCIBLE_TIMESTAMP_ROOTFS | 699 | find ${IMAGE_ROOTFS} -print0 | xargs -0 touch -h --date=@$REPRODUCIBLE_TIMESTAMP_ROOTFS |
700 | } | 700 | } |
701 | 701 | ||
702 | systemd_preset_all () { | 702 | IMAGE_PREPROCESS_COMMAND:append = " reproducible_final_image_task " |
703 | if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then | ||
704 | systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all | ||
705 | systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only preset-all | ||
706 | fi | ||
707 | } | ||
708 | |||
709 | 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 " | ||
710 | 703 | ||
711 | CVE_PRODUCT = "" | 704 | 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" | |||
43 | POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log" | 43 | POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log" |
44 | # Set default target for systemd images | 44 | # Set default target for systemd images |
45 | SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains_any("IMAGE_FEATURES", [ "x11-base", "weston" ], "graphical.target", "multi-user.target", d)}' | 45 | SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains_any("IMAGE_FEATURES", [ "x11-base", "weston" ], "graphical.target", "multi-user.target", d)}' |
46 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target systemd_sysusers_check", "", d)}' | 46 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target systemd_sysusers_check systemd_handle_machine_id", "", d)}' |
47 | 47 | ||
48 | ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile' | 48 | ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile' |
49 | 49 | ||
@@ -173,6 +173,23 @@ python systemd_sysusers_check() { | |||
173 | check_group_exists(d, sid) | 173 | check_group_exists(d, sid) |
174 | } | 174 | } |
175 | 175 | ||
176 | systemd_handle_machine_id() { | ||
177 | if ${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false", d)}; then | ||
178 | # Create machine-id | ||
179 | # 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 | ||
180 | touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id | ||
181 | fi | ||
182 | # In order to be backward compatible with the previous OE-core specific (re)implementation of systemctl | ||
183 | # we need to touch machine-id when handling presets and when the rootfs is NOT stateless | ||
184 | if ${@ 'true' if not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else 'false'}; then | ||
185 | touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id | ||
186 | if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then | ||
187 | systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all | ||
188 | systemctl --root="${IMAGE_ROOTFS}" --global --preset-mode=enable-only preset-all | ||
189 | fi | ||
190 | fi | ||
191 | } | ||
192 | |||
176 | # | 193 | # |
177 | # A hook function to support read-only-rootfs IMAGE_FEATURES | 194 | # A hook function to support read-only-rootfs IMAGE_FEATURES |
178 | # | 195 | # |
@@ -224,12 +241,6 @@ read_only_rootfs_hook () { | |||
224 | ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh | 241 | ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh |
225 | fi | 242 | fi |
226 | fi | 243 | fi |
227 | |||
228 | if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then | ||
229 | # Create machine-id | ||
230 | # 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 | ||
231 | touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id | ||
232 | fi | ||
233 | } | 244 | } |
234 | 245 | ||
235 | # | 246 | # |