Skip to content

bootloader: Fix kargs stacking with bootc transient /etc - #821

Closed
jmarrero wants to merge 1 commit into
redhat-performance:masterfrom
jmarrero:rpm-ostree-transient-etc
Closed

jmarrero wants to merge 1 commit into
redhat-performance:masterfrom
jmarrero:rpm-ostree-transient-etc

Conversation

@jmarrero

Copy link
Copy Markdown
Contributor

On systems using bootc with transient /etc, the state file /etc/tuned/bootcmdline is lost after each reboot. This causes TuneD to lose track of which kernel arguments it previously added, resulting in kargs stacking up indefinitely.

This commit makes two changes:

  1. Use idempotent rpm-ostree flags:

    • --delete-if-present instead of --delete
    • --append-if-missing instead of --append This prevents errors when state is inconsistent and avoids duplicate kargs.
  2. Before modifying kargs, check if the profile's kargs are already present in rpm-ostree. If so, just restore the state file instead of attempting to add them again. This handles the post-reboot case where kargs persist in rpm-ostree but the state file was wiped.

Resolves: RHEL-135363

Assisted-by: OpenCode (Claude Opus 4.5)

--

I have not tested this e2e and this was mostly written by Claude Opus 4.5 via Open Code but the idea here is to reconcile with rpm-ostree kargs output before trying to add or delete kargs.

On systems using bootc with transient /etc, the state file
/etc/tuned/bootcmdline is lost after each reboot. This causes
TuneD to lose track of which kernel arguments it previously
added, resulting in kargs stacking up indefinitely.

This commit makes two changes:

1. Use idempotent rpm-ostree flags:
   - --delete-if-present instead of --delete
   - --append-if-missing instead of --append
   This prevents errors when state is inconsistent and avoids
   duplicate kargs.

2. Before modifying kargs, check if the profile's kargs are
   already present in rpm-ostree. If so, just restore the state
   file instead of attempting to add them again. This handles
   the post-reboot case where kargs persist in rpm-ostree but
   the state file was wiped.

Resolves: RHEL-135363

Assisted-by: OpenCode (Claude Opus 4.5)
@cgwalters

Copy link
Copy Markdown
Contributor

The root problem is we don't have a clean "kargs.d" that operates locally: bootc-dev/bootc#899

All that we have is the merged BLS config file - but "ownership" is lost in that in the merged options file.

Now one clear model with UKIs is where these materialize as drop-ins https://www.freedesktop.org/software/systemd/man/latest/systemd-stub.html

That's a .d style approach.

@cgwalters

Copy link
Copy Markdown
Contributor

Strawman: Extend rpm-ostree kargs --source=tuned --append=foo=bar and then we'd store the split set of kargs as a comment (not the cleanest but would work) in the BLS file

# options-tuned: nohz=full isolcpu=abcd
options=<base options like console> <tuned options> etc..

Then if we rerun e.g. rpm-ostree kargs --source=tuned --append=bar=baz

That would automatically handle dropping out any kargs that are no long referenced from the old commented options-tuned: section.

And it'd need a return value to say if anything changed.


Of course we don't actually need to implement this in rpm-ostree, tuned could do this on its own directly editing the BLS files (this just loses out on the rollback-by-default).

@jmarrero

Copy link
Copy Markdown
Contributor Author

It looks like this would be better addressed then in rpm-ostree. Closing here and I will start investigating the rpm-ostree changes for this.

@jmarrero jmarrero closed this Jan 30, 2026
jmarrero added a commit to jmarrero/rpm-ostree that referenced this pull request Feb 27, 2026
On bootc systems with transient /etc, TuneD loses track of which kernel
arguments it previously added because its state file (/etc/tuned/bootcmdline)
is wiped on each reboot. This causes kargs to stack indefinitely - each time
TuneD runs, it adds the same kargs again without knowing they already exist.

This implements Colin's suggestion from the tuned PR discussion: add a
--source flag that tracks kargs ownership in the BLS config file itself.
When used, the source's previous kargs are removed and replaced with the
new set.

The implementation:

1. Adds --source=NAME option to 'rpm-ostree kargs'. When specified, all
   kargs from that source are replaced with the new set provided via
   --append.

2. Stores source ownership using a custom key in the BLS config:
     ostree-source-<name>=<kargs>
   Since BLS lives on /boot (not /etc), it persists across reboots even
   with transient /etc.

3. On subsequent runs with the same --source, computes a diff between
   old and new source kargs, removes the old ones, and adds the new ones.

4. Multiple sources can coexist independently (tuned, dracut, user, etc.)

5. For staged deployments, the source metadata is written to the staged
   deployment GVariant ("bootconfig-extra" key) so custom BLS keys
   survive the finalization roundtrip at shutdown. For direct deployments,
   the BLS file is written directly.

6. Source names are validated to contain only alphanumeric characters,
   dashes, and underscores to prevent malformed BLS keys.

Example workflow for TuneD:
  # First run sets tuned's kargs
  rpm-ostree kargs --source=tuned --append=nohz=full --append=isolcpus=1-3

  # After reboot (with transient /etc), running again replaces, not stacks
  rpm-ostree kargs --source=tuned --append=nohz=on --append=rcu_nocbs=2-7

  # Old kargs (nohz=full, isolcpus=1-3) are removed
  # New kargs (nohz=on, rcu_nocbs=2-7) are added

Restrictions:
- --source cannot be combined with --editor (use append-based workflow)
- --source cannot be combined with --delete or --replace (replacement
  semantics are automatic)

Requires: ostree with "bootconfig-extra" staged serialization support
Resolves: RHEL-135363
See: bootc-dev/bootc#899
See: redhat-performance/tuned#821

Assisted-by: OpenCode (Claude Opus 4.6)
Signed-off-by: Joseph Marrero <[email protected]>
jmarrero added a commit to jmarrero/rpm-ostree that referenced this pull request Mar 18, 2026
On bootc systems with transient /etc, TuneD loses track of which kernel
arguments it previously added because its state file (/etc/tuned/bootcmdline)
is wiped on each reboot. This causes kargs to stack indefinitely - each time
TuneD runs, it adds the same kargs again without knowing they already exist.

This implements Colin's suggestion from the tuned PR discussion: add a
--source flag that tracks kargs ownership in the BLS config file itself.
When used, the source's previous kargs are removed and replaced with the
new set.

The implementation:

1. Adds --source=NAME option to 'rpm-ostree kargs'. When specified, all
   kargs from that source are replaced with the new set provided via
   --append.

2. Stores source ownership using a custom key in the BLS config:
     ostree-source-<name>=<kargs>
   Since BLS lives on /boot (not /etc), it persists across reboots even
   with transient /etc.

3. On subsequent runs with the same --source, computes a diff between
   old and new source kargs, removes the old ones, and adds the new ones.

4. Multiple sources can coexist independently (tuned, dracut, user, etc.)

5. For staged deployments, the source metadata is written to the staged
   deployment GVariant ("bootconfig-extra" key) so custom BLS keys
   survive the finalization roundtrip at shutdown. For direct deployments,
   the BLS file is written directly.

6. Source names are validated to contain only alphanumeric characters,
   dashes, and underscores to prevent malformed BLS keys.

Example workflow for TuneD:
  # First run sets tuned's kargs
  rpm-ostree kargs --source=tuned --append=nohz=full --append=isolcpus=1-3

  # After reboot (with transient /etc), running again replaces, not stacks
  rpm-ostree kargs --source=tuned --append=nohz=on --append=rcu_nocbs=2-7

  # Old kargs (nohz=full, isolcpus=1-3) are removed
  # New kargs (nohz=on, rcu_nocbs=2-7) are added

Restrictions:
- --source cannot be combined with --editor (use append-based workflow)
- --source cannot be combined with --delete or --replace (replacement
  semantics are automatic)

Requires: ostree with "bootconfig-extra" staged serialization support
Resolves: RHEL-135363
See: bootc-dev/bootc#899
See: redhat-performance/tuned#821

Assisted-by: OpenCode (Claude Opus 4.6)
Signed-off-by: Joseph Marrero <[email protected]>
jmarrero added a commit to jmarrero/rpm-ostree that referenced this pull request Mar 18, 2026
On bootc systems with transient /etc, TuneD loses track of which kernel
arguments it previously added because its state file (/etc/tuned/bootcmdline)
is wiped on each reboot. This causes kargs to stack indefinitely - each time
TuneD runs, it adds the same kargs again without knowing they already exist.

This implements Colin's suggestion from the tuned PR discussion: add a
--source flag that tracks kargs ownership in the BLS config file itself.
When used, the source's previous kargs are removed and replaced with the
new set.

The implementation:

1. Adds --source=NAME option to 'rpm-ostree kargs'. When specified, all
   kargs from that source are replaced with the new set provided via
   --append.

2. Stores source ownership using a custom key in the BLS config:
     ostree-source-<name>=<kargs>
   Since BLS lives on /boot (not /etc), it persists across reboots even
   with transient /etc.

3. On subsequent runs with the same --source, computes a diff between
   old and new source kargs, removes the old ones, and adds the new ones.

4. Multiple sources can coexist independently (tuned, dracut, user, etc.)

5. For staged deployments, the source metadata is written to the staged
   deployment GVariant ("bootconfig-extra" key) so custom BLS keys
   survive the finalization roundtrip at shutdown. For direct deployments,
   the BLS file is written directly.

6. Source names are validated to contain only alphanumeric characters,
   dashes, and underscores to prevent malformed BLS keys.

Example workflow for TuneD:
  # First run sets tuned's kargs
  rpm-ostree kargs --source=tuned --append=nohz=full --append=isolcpus=1-3

  # After reboot (with transient /etc), running again replaces, not stacks
  rpm-ostree kargs --source=tuned --append=nohz=on --append=rcu_nocbs=2-7

  # Old kargs (nohz=full, isolcpus=1-3) are removed
  # New kargs (nohz=on, rcu_nocbs=2-7) are added

Restrictions:
- --source cannot be combined with --editor (use append-based workflow)
- --source cannot be combined with --delete or --replace (replacement
  semantics are automatic)

Requires: ostree with "bootconfig-extra" staged serialization support
Resolves: RHEL-135363
See: bootc-dev/bootc#899
See: redhat-performance/tuned#821

Assisted-by: OpenCode (Claude Opus 4.6)
Signed-off-by: Joseph Marrero Corchado <[email protected]>
jmarrero added a commit to jmarrero/rpm-ostree that referenced this pull request Mar 19, 2026
On bootc systems with transient /etc, TuneD loses track of which kernel
arguments it previously added because its state file (/etc/tuned/bootcmdline)
is wiped on each reboot. This causes kargs to stack indefinitely - each time
TuneD runs, it adds the same kargs again without knowing they already exist.

This implements Colin's suggestion from the tuned PR discussion: add a
--source flag that tracks kargs ownership in the BLS config file itself.
When used, the source's previous kargs are removed and replaced with the
new set.

The implementation:

1. Adds --source=NAME option to 'rpm-ostree kargs'. When specified, all
   kargs from that source are replaced with the new set provided via
   --append.

2. Stores source ownership using a custom key in the BLS config:
     ostree-source-<name>=<kargs>
   Since BLS lives on /boot (not /etc), it persists across reboots even
   with transient /etc.

3. On subsequent runs with the same --source, computes a diff between
   old and new source kargs, removes the old ones, and adds the new ones.

4. Multiple sources can coexist independently (tuned, dracut, user, etc.)

5. For staged deployments, the source metadata is written to the staged
   deployment GVariant ("bootconfig-extra" key) so custom BLS keys
   survive the finalization roundtrip at shutdown. For direct deployments,
   the BLS file is written directly.

6. Source names are validated to contain only alphanumeric characters,
   dashes, and underscores to prevent malformed BLS keys.

Example workflow for TuneD:
  # First run sets tuned's kargs
  rpm-ostree kargs --source=tuned --append=nohz=full --append=isolcpus=1-3

  # After reboot (with transient /etc), running again replaces, not stacks
  rpm-ostree kargs --source=tuned --append=nohz=on --append=rcu_nocbs=2-7

  # Old kargs (nohz=full, isolcpus=1-3) are removed
  # New kargs (nohz=on, rcu_nocbs=2-7) are added

Restrictions:
- --source cannot be combined with --editor (use append-based workflow)
- --source cannot be combined with --delete or --replace (replacement
  semantics are automatic)

Requires: ostree with "bootconfig-extra" staged serialization support
Resolves: RHEL-135363
See: bootc-dev/bootc#899
See: redhat-performance/tuned#821

Assisted-by: OpenCode (Claude Opus 4.6)
Signed-off-by: Joseph Marrero Corchado <[email protected]>
jmarrero added a commit to jmarrero/rpm-ostree that referenced this pull request Mar 23, 2026
On bootc systems with transient /etc, TuneD loses track of which kernel
arguments it previously added because its state file (/etc/tuned/bootcmdline)
is wiped on each reboot. This causes kargs to stack indefinitely - each time
TuneD runs, it adds the same kargs again without knowing they already exist.

This implements Colin's suggestion from the tuned PR discussion: add a
--source flag that tracks kargs ownership in the BLS config file itself.
When used, the source's previous kargs are removed and replaced with the
new set.

The implementation:

1. Adds --source=NAME option to 'rpm-ostree kargs'. When specified, all
   kargs from that source are replaced with the new set provided via
   --append. When specified with no --append, all kargs from that source
   are cleared.

2. Stores source ownership using a magic comment in the BLS config:
     # x-ostree-options-source-<name> <kargs>
   Since BLS lives on /boot (not /etc), it persists across reboots even
   with transient /etc. Using comments (rather than custom keys) avoids
   the risk of other tools choking on unknown BLS entries.

3. On subsequent runs with the same --source, computes a diff between
   old and new source kargs, removes the old ones, and adds the new ones.

4. Multiple sources can coexist independently (tuned, dracut, user, etc.)

5. For staged deployments, the source metadata is serialized by ostree's
   "bootconfig-comments" mechanism so magic comments survive the
   finalization roundtrip at shutdown. For direct deployments, the BLS
   file is written directly.

6. Source names are validated to be non-empty and contain only alphanumeric
   characters, dashes, and underscores to prevent malformed entries.

Requires: ostree with magic comment preservation support
Resolves: RHEL-135363
See: bootc-dev/bootc#899
See: redhat-performance/tuned#821

Assisted-by: OpenCode (Claude Opus 4.6)
Signed-off-by: Joseph Marrero Corchado <[email protected]>
jmarrero added a commit to jmarrero/rpm-ostree that referenced this pull request Mar 23, 2026
On bootc systems with transient /etc, TuneD loses track of which kernel
arguments it previously added because its state file (/etc/tuned/bootcmdline)
is wiped on each reboot. This causes kargs to stack indefinitely - each time
TuneD runs, it adds the same kargs again without knowing they already exist.

This implements Colin's suggestion from the tuned PR discussion: add a
--source flag that tracks kargs ownership in the BLS config file itself.
When used, the source's previous kargs are removed and replaced with the
new set.

The implementation:

1. Adds --source=NAME option to 'rpm-ostree kargs'. When specified, all
   kargs from that source are replaced with the new set provided via
   --append. When specified with no --append, all kargs from that source
   are cleared.

2. Stores source ownership using a magic comment in the BLS config:
     # x-ostree-options-source-<name> <kargs>
   Since BLS lives on /boot (not /etc), it persists across reboots even
   with transient /etc. Using comments (rather than custom keys) avoids
   the risk of other tools choking on unknown BLS entries.

3. On subsequent runs with the same --source, computes a diff between
   old and new source kargs, removes the old ones, and adds the new ones.

4. Multiple sources can coexist independently (tuned, dracut, user, etc.)

5. For staged deployments, the source metadata is serialized by ostree's
   "bootconfig-comments" mechanism so magic comments survive the
   finalization roundtrip at shutdown. For direct deployments, the BLS
   file is written directly.

6. Source names are validated to be non-empty and contain only alphanumeric
   characters, dashes, and underscores to prevent malformed entries.

Requires: ostree with magic comment preservation support
Resolves: RHEL-135363
See: bootc-dev/bootc#899
See: redhat-performance/tuned#821

Assisted-by: OpenCode (Claude Opus 4.6)
Signed-off-by: Joseph Marrero Corchado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants