Skip to content

Use grubby to update kernel command line arguments - #511

Open
mihaelabalutoiu wants to merge 3 commits into
cloudbase:mainfrom
mihaelabalutoiu:add-grubby-kernel-opts
Open

Use grubby to update kernel command line arguments#511
mihaelabalutoiu wants to merge 3 commits into
cloudbase:mainfrom
mihaelabalutoiu:add-grubby-kernel-opts

Conversation

@mihaelabalutoiu

@mihaelabalutoiu mihaelabalutoiu commented Aug 28, 2026

Copy link
Copy Markdown
Member

Failing to update the kernel console options breaks text console functionality on affected platforms.

The issue is caused by BLS being enabled by default in /etc/default/grub. On RHEL 10, kernel arguments are managed through /boot/loader/entries, and grub2-mkconfig does not propagate the updated options there.

This PR implements the following:

  • Adds Grub2ConfigEditor.remove_from_option, with grubby --remove-args semantics: a bare name drops the argument whichever value it holds, a name/value pair drops it only on an exact match.
  • Adds _update_kernel_cmdline_args to the base OSMorphing tools, editing both GRUB2 cmdline options through Grub2ConfigEditor. Debian and SUSE each had their own copy of these edits and now share this one.
  • Overrides it on redhat to use grubby --update-kernel=ALL, which reaches the BLS boot entries.

"sed -i '/cloud-init=disabled/d' %s" % grub_conf_disabler
)
self._schedule_grub2_update()
self._update_kernel_cmdline_args(args_to_remove=["cloud-init=disabled"])

@Dany9966 Dany9966 Aug 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like that both grub update and grubby are being called. It should be the one or the other, not both.

An ideal implementation would be to call for _update_kernel_cmdline_args indeed, but you only implemented it for redhat based. There should also be a debian implementation which does the former (reads /etc/default/grub, removes/adds/edits the cmdline, schedules grub2 update).

I propose the following:

  1. Use Grub2ConfigEditor whenever possible instead of sed-ing the file directly.
    This implies implementing a new method to remove cmdline entries, call it remove_from_option
    This method should pretty much emulate what grubby does on redhat, and that is if you pass a single option
    (--remove-args=cloud-init), then it will be removed even if it's a key_val, no matter what value cloud-init has
    in cmdline. If you pass a key_val, then only remove the key if the value matches
    (--remove-args=cloud-init=disabled only remove cloud-init from cmdline if it's disabled, but won't
    remove cloud-init=enabled).

  2. We should somehow abstractize this for redhat. On base, when calling for _update_kernel_cmdline_args,
    it should instantiate a Grub2ConfigEditor, append or remove from GRUB_CMDLINE_LINUX and
    GRUB_CMDLINE_LINUX_DEFAULT options (depending on what args_to_add or args_to_remove are being
    passed).
    If it's redhat, then simply use grubby to handle args_to_add/args_to_remove

  3. (only if grubby commands take too long, otherwise treat this as optional) I think the final grubby command should also be run once at the end, so add some schedule_grubby
    methods as well when adding args to remove/add. (similar to _schedule_grub2_update)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for that! I updated the code, please take a look now.

@mihaelabalutoiu
mihaelabalutoiu marked this pull request as draft September 4, 2026 07:08
Removes cmdline entries with `grubby --remove-args` semantics: a bare
name drops the argument whichever value it holds, a name/value pair
drops it only on an exact match.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Use `grubby --update-kernel=ALL` to update kernel arguments on
BLS-based systems such as RHEL 10, where `grub2-mkconfig` does not
propagate them to `/boot/loader/entries`.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
@mihaelabalutoiu
mihaelabalutoiu marked this pull request as ready for review September 9, 2026 09:47
@@ -69,33 +69,7 @@ def check_os_supported(cls, detected_os_info):
return False

def disable_predictable_nic_names(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth taking into account to modify custom implementations of disable_predictable_nic_names in the other providers as well.
Besides that LGTM

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.

3 participants