Skip to content

Commit

Permalink
Fix kernel cmdline args we add not being propogated to newly installe…
Browse files Browse the repository at this point in the history
…d kernels.

On some upgrades, any kernel commandline args that we were adding were added to the default kernel
but once the user installed a new kernel, those args were not propogated to the new kernel.  This
was happening on S390x and on RHEL7=>8 upgrades.

To fix this, we add the kernel commandline args to both the default kernel and to the defaults for
all kernels.

On S390x and upgrades to RHEL9 or greater, this is done by placing the kernel cmdline arguments into
the /etc/kernel/cmdline file.

On upgrades to RHEL <= 8 for all architectures other than S390x, this is done by having
grub2-editenv modify the /boot/grub2/grubenv file.
  • Loading branch information
abadger committed Mar 26, 2024
1 parent 050620e commit 9520cc6
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

from leapp.exceptions import StopActorExecutionError
from leapp.libraries import stdlib
from leapp.libraries.common.config import architecture
from leapp.libraries.common.config import architecture, version
from leapp.libraries.stdlib import api
from leapp.models import InstalledTargetKernelInfo, KernelCmdlineArg, TargetKernelCmdlineArgTasks

Expand Down Expand Up @@ -31,12 +33,24 @@ def format_kernelarg_msgs_for_grubby_cmd(kernelarg_msgs):
return ' '.join(kernel_args)


def set_default_kernel_args(kernel_args):
if (architecture.matches_architecture(architecture.ARCH_S390X) or
version.matches_target_version((">= 9",))):
# Put kernel_args into /etc/kernel/cmdline
with open(KERNEL_CMDLINE_FILE, 'w') as f:
f.write(kernel_args)
else:
# Use grub2-editenv to put the kernel args into /boot/grub2/grubenv
stdlib.run(['grub2-editenv', '-', 'set', 'kernelopts={}'.format(kernel_args)])


def modify_kernel_args_in_boot_cfg(configs_to_modify_explicitly=None):
kernel_info = next(api.consume(InstalledTargetKernelInfo), None)
if not kernel_info:
return

# Collect desired kernelopt modifications

kernelargs_msgs_to_add = list(api.consume(KernelCmdlineArg))
kernelargs_msgs_to_remove = []
for target_kernel_arg_task in api.consume(TargetKernelCmdlineArgTasks):
Expand All @@ -46,6 +60,8 @@ def modify_kernel_args_in_boot_cfg(configs_to_modify_explicitly=None):
if not kernelargs_msgs_to_add and not kernelargs_msgs_to_remove:
return # There is no work to do

# Modify the kernel cmdline for the default kernel

grubby_modify_kernelargs_cmd = ['grubby', '--update-kernel={0}'.format(kernel_info.kernel_img_path)]

if kernelargs_msgs_to_add:
Expand All @@ -64,3 +80,17 @@ def modify_kernel_args_in_boot_cfg(configs_to_modify_explicitly=None):
run_grubby_cmd(cmd)
else:
run_grubby_cmd(grubby_modify_kernelargs_cmd)

# Copy the args for the default kernel to be for all kernels.

cmd = ['grubby', '--info', kernel_info.kernel_img_path]
output = stdlib.run(cmd, split=True)
for record in output.stdout:
# This could be done with one regex but it's cleaner to parse it as
# structured data.
if record.startswith('args='):
data = record.split("=", 1)[1]
matches = re.match(r'^([\'"]?)(.*)\1$')
kernel_args = matches.group(2)

set_default_kernel_args(kernel_args)

0 comments on commit 9520cc6

Please sign in to comment.