Skip to content

generator: Create /var/lib/systemd early instead of reordering tmpfiles - #8

Closed
jmarrero-bot wants to merge 2 commits into
mainfrom
bot/tmpfiles-ordering-cycle
Closed

jmarrero-bot wants to merge 2 commits into
mainfrom
bot/tmpfiles-ordering-cycle

Conversation

@jmarrero-bot

@jmarrero-bot jmarrero-bot commented Nov 5, 2026 •

Copy link
Copy Markdown

On native composefs boots, the generator's drop-in from 41049cc orders systemd-tmpfiles-setup.service (After=local-fs.target) before systemd-random-seed.service. With a crypttab swap keyed from /dev/urandom, local-fs.target needs random-seed:

local-fs.target -> tmp.mount (After=swap.target) -> dev-mapper-swap.swap
  -> [email protected] (After=systemd-random-seed.service)
  -> systemd-random-seed.service -> systemd-tmpfiles-setup.service (drop-in)
  -> local-fs.target

systemd breaks the cycle by deleting one of these jobs. On different boots that was random-seed (so it doesn't run at all), or tmp.mount (the report: tmpfiles runs before /tmp is mounted, GNOME can't start Xwayland). The reporter uses the native composefs backend (bootc-dev/bootc#2345), where the drop-in is written as intended; ostree boots never get it.

This replaces the drop-in with a generated bootc-early-tmpfiles.service, which runs systemd-tmpfiles --create --prefix=/var/lib/systemd. It is ordered after only what random-seed is ordered after itself (systemd-remount-fs.service and the mounts for /var/lib/systemd), so it can't add a cycle. The only tmpfiles.d lines under /var/lib/systemd in the CentOS Stream 9/10 and Fedora 45 base images are root-owned, so it doesn't need sysusers first. The PR also adds a tmt test that boots with a random-key encrypted swap (file-backed, in /var) and tmp.mount enabled, and checks that the journal has no ordering cycle and that tmp.mount was active before tmpfiles-setup started.

Testing, on a 16-core devspace (jmarrero-devspace-42012032986), all with CentOS Stream 10 images (systemd 257), composefs = BOOTC_variant=composefs, systemd-boot, ext4, BLS, unsealed:

  • Reproduction on main (1.17.4): the new tmt test fails. Its journal has local-fs.target: Found ordering cycle on tmp.mount/start; has dependency on swap.target/start, ... systemd-random-seed.service/start, systemd-tmpfiles-setup.service/start, local-fs.target/start and Job tmp.mount/start deleted to break ordering cycle. A manual bcvk VM from the same image deleted systemd-random-seed.service/start instead.
  • With this PR: just test-tmt-nobuild readonly encrypted-swap-ordering passes on composefs and on ostree (grub). On the composefs VM, bootc-early-tmpfiles.service ran before random-seed, the swap and /tmp came up, there were no AVC denials, and systemd-analyze verify default.target was clean.
  • The problem 41049cc fixed stays fixed. A control build of main without the drop-in fails readonly/014-test-no-failed-units with systemd-random-seed.service failed and avc: denied { add_name } for comm="systemd-random-" name="systemd" scontext=init_t tcontext=unlabeled_t. With this PR, 014 passes on composefs and on ostree.
  • just unit-tests (including the new generator::tests::test::test_early_tmpfiles_unit) and just validate pass. After review, a comment was added to the unit file; cargo test -p bootc-lib --lib generator passed again on that head, and systemd-analyze verify of the unit is clean in the CentOS Stream 9/10 and Fedora 45 images.

Not tested: Fedora images, UKI or sealed boots, and a TPM (systemd-tpm2-setup.service was skipped by its condition in these VMs).

Fixes bootc-dev#2624

Generated-by: https://github.com/jmarrero-bot#llms


Review draft in jmarrero-forge, not upstream yet. This section is removed when the PR is opened upstream.

  • Upstream: bootc-dev/bootc, base main
  • Board item: PVTI_lADOFBIZ7c4BlZPrzhGPYOA
  • Fork CI: off; the devspace testing described above is this PR's CI, and upstream CI runs once it is opened there

To review:

  • Approve, or comment /promote on a line of its own, to open it upstream, ready for review. Either covers only the commits pushed so far.
  • If upstream requires DCO, approving also signs off: promote adds Signed-off-by: Joseph Marrero Corchado <[email protected]> to the commits lacking it (the bot's and yours; anyone else's only if you ask), with you as committer.
  • Add a /draft line (in the same comment or before) to open it upstream as a draft (/ready undoes that).
  • Close to drop it.
  • Edit the title and description freely: they become the upstream PR's. Review comments are squashed into the commits they concern, with a reply here.

Bot run: session 77cad178, agent aefffdd1 · claude-opus-5-5 16.3M in (98% cached) / 74k out · ~$6.59 inference + ~$1.98 compute (est., list prices) · 49m wall · 12.5 core-h, Actions run 42012032986

@jmarrero-bot jmarrero-bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review guide for head a8943ed382: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.

Replaces the 1.17 generator drop-in that ordered all of systemd-tmpfiles-setup.service (After=local-fs.target) before systemd-random-seed.service on native composefs boots. That drop-in closes an ordering cycle whenever local-fs.target needs random-seed (random-key crypttab swap plus tmp.mount After=swap.target), and systemd breaks it by deleting tmp.mount or random-seed. The new generated bootc-early-tmpfiles.service runs systemd-tmpfiles --create --prefix=/var/lib/systemd with only random-seed's own After= set (systemd-remount-fs plus the mounts for /var/lib/systemd), which is also a subset of systemd-tpm2-setup's, so it cannot add a cycle those units do not already have. The reviewer checked the upstream unit files for systemd 252, 257 and main, and the SELinux policy in c9s, c10s and f45: systemd_tmpfiles_t may add_name/create in unlabeled_t dirs while init_t may not, which is why tmpfiles fixes the first-boot AVC that random-seed hit. The main risk is the unit file ordering itself; the second commit is a two-boot tmt test (file-backed plain dm-crypt swap in /var) that failed on main with the cycle and passed with the fix on composefs and ostree (c10s only; c9s and UKI/sealed untested until upstream CI).

Hotspots

  1. look-closely · logic — crates/lib/src/units/bootc-early-tmpfiles.service:4-12 (f1e9af0): The whole fix rests on this After= set staying a subset of systemd-random-seed's and systemd-tpm2-setup's (both After=systemd-remount-fs plus RequiresMountsFor under /var/lib/systemd on 252/257/main). Adding any later dependency here, e.g. sysusers or local-fs.target, would reintroduce a cycle.
  2. note · error-handling — crates/lib/src/units/bootc-early-tmpfiles.service:17-18 (f1e9af0): SuccessExitStatus copies systemd-tmpfiles-setup, but CANTCREAT also masks the one failure this unit exists to prevent (mkdir /var/lib/systemd denied). Such a failure would then only show up as systemd-random-seed failing; a short comment on why it is tolerated would help.
  3. note · logic — crates/lib/src/generator.rs:308-320 (f1e9af0): Relative sysinit.target.wants symlink, removed first so a re-run (daemon-reload) does not fail with EEXIST; the unit is only written for is_composefs && !is_ostree, same gate as the old drop-in.
  4. note · test-gap — tmt/tests/booted/test-encrypted-swap-ordering.nu:44-48 (a8943ed): Fails on any ordering cycle anywhere in the boot, not only the swap one, so an unrelated cycle in a future base image would fail this test. Strict on purpose, but it is the likely source of a false failure.
  5. note · test-gap — tmt/tests/booted/test-encrypted-swap-ordering.nu:61-64 (a8943ed): Monotonic timestamps of tmp.mount activation vs tmpfiles-setup start; both units are asserted active just above, so neither can be 0. This guards the symptom from the report even if the cycle message changes.

Safe to skim

  • tmt/plans/integration.fmf: generated from the test's # number/tmt header (just validate checks it)
  • tmt/tests/tests.fmf: generated from the test's # number/tmt header
  • tmt/tests/booted/readonly/014-test-no-failed-units.nu: comment-only update
  • crates/lib/src/generator.rs:644-694: unit test re-asserting the static unit file's keys

@jmarrero-bot
jmarrero-bot force-pushed the bot/tmpfiles-ordering-cycle branch from a8943ed to 74c6e1a Compare November 5, 2026 11:40

@jmarrero-bot jmarrero-bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review guide for head 74c6e1af76: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.

Replaces the 1.17 generator drop-in that ordered all of systemd-tmpfiles-setup.service (After=local-fs.target) before systemd-random-seed.service on native composefs boots. That drop-in closes an ordering cycle whenever local-fs.target needs random-seed (random-key crypttab swap plus tmp.mount After=swap.target), and systemd breaks it by deleting tmp.mount or random-seed. The new generated bootc-early-tmpfiles.service runs systemd-tmpfiles --create --prefix=/var/lib/systemd with only random-seed's own After= set (systemd-remount-fs plus the mounts for /var/lib/systemd), which is also a subset of systemd-tpm2-setup's, so it cannot add a cycle those units do not already have. The reviewer checked the upstream unit files for systemd 252, 257 and main, and the SELinux policy in c9s, c10s and f45: systemd_tmpfiles_t may add_name/create in unlabeled_t dirs while init_t may not, which is why tmpfiles fixes the first-boot AVC that random-seed hit. The main risk is the unit file ordering itself; the second commit is a two-boot tmt test (file-backed plain dm-crypt swap in /var) that failed on main with the cycle and passed with the fix on composefs and ostree (c10s only; c9s and UKI/sealed untested until upstream CI).

Hotspots

  1. look-closely · logic — crates/lib/src/units/bootc-early-tmpfiles.service:4-12 (955297f): The whole fix rests on this After= set staying a subset of systemd-random-seed's and systemd-tpm2-setup's (both After=systemd-remount-fs plus RequiresMountsFor under /var/lib/systemd on 252/257/main). Adding any later dependency here, e.g. sysusers or local-fs.target, would reintroduce a cycle.
  2. note · error-handling — crates/lib/src/units/bootc-early-tmpfiles.service:17-21 (955297f): SuccessExitStatus copies systemd-tmpfiles-setup, so CANTCREAT also hides a failure to create /var/lib/systemd itself; the new comment says that case shows up as systemd-random-seed.service failing instead (which readonly/014 checks).
  3. note · logic — crates/lib/src/generator.rs:308-320 (955297f): Relative sysinit.target.wants symlink, removed first so a re-run (daemon-reload) does not fail with EEXIST; the unit is only written for is_composefs && !is_ostree, same gate as the old drop-in.
  4. note · test-gap — tmt/tests/booted/test-encrypted-swap-ordering.nu:44-48 (74c6e1a): Fails on any ordering cycle anywhere in the boot, not only the swap one, so an unrelated cycle in a future base image would fail this test. Strict on purpose, but it is the likely source of a false failure.
  5. note · test-gap — tmt/tests/booted/test-encrypted-swap-ordering.nu:61-64 (74c6e1a): Monotonic timestamps of tmp.mount activation vs tmpfiles-setup start; both units are asserted active just above, so neither can be 0. This guards the symptom from the report even if the cycle message changes.

Safe to skim

  • tmt/plans/integration.fmf: generated from the test's # number/tmt header (just validate checks it)
  • tmt/tests/tests.fmf: generated from the test's # number/tmt header
  • tmt/tests/booted/readonly/014-test-no-failed-units.nu: comment-only update
  • crates/lib/src/generator.rs:644-694: unit test re-asserting the static unit file's keys

@jmarrero-bot jmarrero-bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ship as-is. No blocking findings at 74c6e1a.

The reported cycle is valid: local-fs → tmp.mount → swap.target/swap → cryptsetup → random-seed → tmpfiles-setup → local-fs. The replacement removes the final two-edge return path. DefaultDependencies=no avoids an implicit sysinit dependency; remount and mount prerequisites are already prerequisites of random-seed and TPM setup. Its Before=sysinit/shutdown edges add no return path in the standard graph. A custom mount arrangement already cyclic with random-seed is not made solvable by this change, but I found no newly introduced cycle.

The SELinux fix is retained: tmpfiles creates /var/lib/systemd with policy-aware labeling before either consumer, including when /var/lib is an existing unlabeled parent. It does not depend on relabeling the whole parent first. The prefix avoids the /tmp work that must wait for local-fs. Accepted DATAERR/CANTCREAT statuses match upstream tmpfiles-setup; failure of the required directory still surfaces through random-seed. The reported enforcing-SELinux control boot is valuable evidence here.

The unit test pins the ordering prerequisites, command, enablement and idempotence; the tmt test recreates the triggering configuration and checks cycle diagnostics, active units and mount-before-tmpfiles timing. Optional strengthening at tmt/tests/booted/test-encrypted-swap-ordering.nu:64-65: also assert early-tmpfiles completion precedes random-seed start. Actual TPM execution and Fedora VM coverage remain disclosed gaps.

Independently reran 14 generator tests, bootc-lib clippy with project gating lints, generated-file freshness and CentOS Stream 10 systemd unit verification (--man=no) on review devspace 42021467274; all passed. Local fmt, diff whitespace and bot-git identity/trailer checks passed. I did not repeat the reported booted tmt/control runs. The review devspace is stopped.

Contribution checks: both commits have appropriate subjects/rationale, bot author/committer identities and Generated-by: AI trailers, with no bot-added signoffs. Scope and unit/integration coverage fit bootc's review policy; human review/signoff remains for promotion.

@jmarrero-bot jmarrero-bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review guide for head 74c6e1af76: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.

Replaces the broad tmpfiles ordering override with a narrowly scoped early tmpfiles service. Focus review on the absence of local-fs/sysinit prerequisites, the mount requirements shared with random-seed, and labeled directory creation before random-seed and TPM setup. The integration test recreates the random-key swap and tmp.mount dependency chain; actual TPM execution and Fedora boot coverage remain outside the reported VM testing.

Hotspots

  1. look-closely · logic — crates/lib/src/units/bootc-early-tmpfiles.service:4-12 (955297f): A dependency on local-fs.target or sysinit.target would recreate the encrypted-swap cycle. Check that the remount and mount prerequisites are already prerequisites of random-seed and TPM setup.
  2. look-closely · security — crates/lib/src/units/bootc-early-tmpfiles.service:17-21 (955297f): The sparse-/var SELinux fix depends on tmpfiles creating the labeled directory before random-seed. Accepted tmpfiles error statuses can hide individual rule failures; random-seed failure and enforcing-SELinux VM coverage are important cross-checks.
  3. note · logic — tmt/tests/booted/test-encrypted-swap-ordering.nu:29-36 (74c6e1a): Both the random-key crypttab entry and tmp.mount are necessary to reproduce the reported cycle; the file-backed swap keeps the setup independent of VM disk layout.
  4. note · test-gap — tmt/tests/booted/test-encrypted-swap-ordering.nu:45-65 (74c6e1a): The test checks cycle diagnostics, active units and mount-before-tmpfiles timing. It does not directly assert early-tmpfiles completion before random-seed or recreate an unlabeled parent; those rely on the unit assertions and separately reported SELinux control boot.

Safe to skim

  • tmt/plans/integration.fmf: Generated integration-plan registration for the new test.
  • tmt/tests/tests.fmf: Generated test metadata matching the Nushell header.
  • tmt/tests/booted/readonly/014-test-no-failed-units.nu: Comment updated to name the replacement service; assertions are unchanged.

On native composefs boots, 41049cc ordered all of
systemd-tmpfiles-setup.service before systemd-random-seed.service so
that /var/lib/systemd exists when random-seed needs it. But
tmpfiles-setup runs after local-fs.target, while random-seed is an early
unit that local-fs.target may itself need: a crypttab swap keyed from
/dev/urandom orders its systemd-cryptsetup@ unit after random-seed, and
tmp.mount is After=swap.target. That closes an ordering cycle, which
systemd breaks by deleting one of its jobs: depending on the boot,
random-seed doesn't run at all, or (as in the report) tmpfiles runs
before /tmp is mounted and GNOME can't start Xwayland.

Instead, generate a small unit that runs systemd-tmpfiles for just
/var/lib/systemd, ordered after only what random-seed is ordered after
itself (systemd-remount-fs and the mounts for /var/lib/systemd), so it
can't add a cycle that random-seed doesn't already have. Every
tmpfiles.d line under /var/lib/systemd in Fedora and CentOS is
root-owned, so it doesn't need systemd-sysusers first.

Fixes: 41049cc ("generator: Order tmpfiles before random seed and TPM setup")
Closes: bootc-dev#2624
Generated-by: AI
Signed-off-by: Joseph Marrero Corchado <[email protected]>
Regression test for the ordering cycle in bootc-dev#2624: set up
a crypttab swap keyed from /dev/urandom with tmp.mount enabled, reboot,
and check that systemd found no ordering cycle and mounted /tmp before
systemd-tmpfiles-setup started.

Generated-by: AI
Signed-off-by: Joseph Marrero Corchado <[email protected]>
@jmarrero-bot

Copy link
Copy Markdown
Author

Signed off 2 commit(s) with Signed-off-by: Joseph Marrero Corchado <[email protected]> for bootc-dev/bootc's DCO check, on jmarrero's approval #8 (review) of 74c6e1af7601. Same trees; the head is now 7960a5d3fd10.

@jmarrero-bot
jmarrero-bot force-pushed the bot/tmpfiles-ordering-cycle branch from 74c6e1a to 7960a5d Compare November 6, 2026 08:31
@jmarrero-bot

Copy link
Copy Markdown
Author

Opened upstream as bootc-dev#2628. Closing this review draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Nasty Regression in 1.17. Ordering cycle preventing Gnome login with Encrypted Swap

3 participants