diff mbox series

systemd-firstboot not triggered on read/write /etc folder

Message ID vkHb.1708249394873752860.quep@lists.openembedded.org
State New
Headers show
Series systemd-firstboot not triggered on read/write /etc folder | expand

Commit Message

dave.elek.96@gmail.com Feb. 18, 2024, 9:43 a.m. UTC
Hi!

In the systemd-systemctl there is a *systemctl* script used for some configuration/settings for the systemd services (e.g. enabling services).

In this script if we call the *preset_all* command, it will create an empty /etc/machine-id file. This is required on read-only /etc folder, otherwise the systemd will fail to boot. However on read-write /etc folder this file is still created, which prevents systemd to satisfy the ConditionFirstBoot condition. This is used in systemd services, for example for systemd-firstboot, where you can configure the root password, localization, hostname, etc.

The preset_all command is triggered from the image.bbclass file. A quick solution in my case was to add a task in my own layer, which deletes the /etc/machine-id file, but I think it would be great, to prevent others from the headache it can cause to investigate/fix this.

I attached the patch file about my proposed solution.

Waiting for you reply soon,
David

Comments

patchtest@automation.yoctoproject.org Feb. 18, 2024, 10:03 a.m. UTC | #1
Thank you for your submission. Patchtest identified one
or more issues with the patch. Please see the log below for
more information:

---
Testing patch /home/patchtest/share/mboxes/systemd-firstboot-not-triggered-on-read-write-etc-folder.patch

FAIL: test Signed-off-by presence: Mbox is missing Signed-off-by. Add it manually or with "git commit --amend -s" (test_mbox.TestMbox.test_signed_off_by_presence)
FAIL: test shortlog format: Commit shortlog (first line of commit message) should follow the format "<target>: <summary>" (test_mbox.TestMbox.test_shortlog_format)

PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test max line length (test_metadata.TestMetadata.test_max_line_length)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test shortlog length (test_mbox.TestMbox.test_shortlog_length)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)

SKIP: pretest pylint: No python related patches, skipping test (test_python_pylint.PyLint.pretest_pylint)
SKIP: pretest src uri left files: Patch cannot be merged (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test CVE tag format: No new CVE patches introduced (test_patch.TestPatch.test_cve_tag_format)
SKIP: test Signed-off-by presence: No new CVE patches introduced (test_patch.TestPatch.test_signed_off_by_presence)
SKIP: test Upstream-Status presence: No new CVE patches introduced (test_patch.TestPatch.test_upstream_status_presence_format)
SKIP: test bugzilla entry format: No bug ID found (test_mbox.TestMbox.test_bugzilla_entry_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test pylint: No python related patches, skipping test (test_python_pylint.PyLint.test_pylint)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: Patch cannot be merged (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)

---

Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this
email with an explanation of why the patch should be accepted. If you
believe these results are due to an error in patchtest, please submit a
bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category
under 'Yocto Project Subprojects'). For more information on specific
failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank
you!
ChenQi Feb. 19, 2024, 2:45 a.m. UTC | #2
Does adding 'stateless-rootfs' to IMAGE_FEATURES work for you?

meta/classes-recipe/image.bbclass:IMAGE_PREPROCESS_COMMAND:append = " 
${@ 'systemd_preset_all systemd_disable_units' 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 "

Regards,
Qi

On 2/18/24 17:43, dave.elek.96@gmail.com wrote:
> Hi!
>
> In the systemd-systemctl there is a *systemctl* script used for some 
> configuration/settings for the systemd services (e.g. enabling services).
>
> In this script if we call the *preset_all* command, it will create an 
> empty //etc/machine-id/ file. This is required on read-only //etc/ 
> folder, otherwise the systemd will fail to boot. However on read-write 
> /etc folder this file is still created, which prevents systemd to 
> satisfy the ConditionFirstBoot condition. This is used in systemd 
> services, for example for systemd-firstboot, where you can configure 
> the root password, localization, hostname, etc.
>
> The preset_all command is triggered from the /image.bbclass/ file. A 
> quick solution in my case was to add a task in my own layer, which 
> deletes the //etc/machine-id/ file, but I think it would be great, to 
> prevent others from the headache it can cause to investigate/fix this.
>
> I attached the patch file about my proposed solution.
>
> Waiting for you reply soon,
> David
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#195823):https://lists.openembedded.org/g/openembedded-core/message/195823
> Mute This Topic:https://lists.openembedded.org/mt/104425254/7304865
> Group Owner:openembedded-core+owner@lists.openembedded.org
> Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub  [Qi.Chen@eng.windriver.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

From 137e3bab6ad5d228105e9936f020a49eaaa4c943 Mon Sep 17 00:00:00 2001
From: "Elek, David" <dave.elek.96@gmail.com>
Date: Sat, 17 Feb 2024 18:39:20 +0100
Subject: [PATCH] image.bbclass: add readonly parameter in systemd_preset_all

If IMAGE_FEATURES contains read-only-rootfs call the systemctl script
with --readonly argument.

systemd-systemctl/systemctl: check for readonly argument
if the script was called with this argument, it will prevent creating
the /etc/machine-id file when executing the preset_all command

If the system is read-write and the /etc/machine-id file exists, the
systemd-firstboot is not triggered (ConditionFirstBoot=yes condition is
not met). In readonly rootfs the empty machine-id file must be created,
because of the systemd.

Signed-off-by: Elek, David <dave.elek.96@gmail.com>
---
 meta/classes/image.bbclass                            | 2 +-
 meta/recipes-core/systemd/systemd-systemctl/systemctl | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 00413d56d1..e68cf780e6 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -669,7 +669,7 @@  reproducible_final_image_task () {
 
 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}" --preset-mode=enable-only preset-all ${@bb.utils.contains('IMAGE_FEATURES', 'read-only-rootfs', '--readonly', '', d)}
     fi
 }
 
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 0fd7e24085..0850a37575 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -273,7 +273,7 @@  def collect_services(root):
     return services
 
 
-def preset_all(root):
+def preset_all(root, readonly):
     presets = Presets('system-preset', root)
     services = collect_services(root)
 
@@ -293,7 +293,8 @@  def preset_all(root):
     # For the stateless configuration, where /etc is generated at runtime
     # (for example on a tmpfs), this script shouldn't run at all and we
     # allow systemd to completely populate /etc.
-    (root / SYSCONFDIR / "machine-id").touch()
+    if readonly:
+        (root / SYSCONFDIR / "machine-id").touch()
 
 
 def main():
@@ -308,6 +309,7 @@  def main():
     parser.add_argument('--preset-mode',
                         choices=['full', 'enable-only', 'disable-only'],
                         default='full')
+    parser.add_argument('--readonly', action='store_true')
 
     args = parser.parse_args()
 
@@ -341,7 +343,7 @@  def main():
             sys.exit("Too many arguments.")
         if args.preset_mode != "enable-only":
             sys.exit("Only enable-only is supported as preset-mode.")
-        preset_all(root)
+        preset_all(root, args.readonly)
     else:
         raise RuntimeError()
 
-- 
2.25.1