Make grubby to also update GRUB_CMDLINE_LINUX in /etc/default/grub

The grubby --update-kernel=ALL option is used to update the kernel command
line parameters for all the boot entries. But the updated cmdline is lost
if the grub2-mkconfig command is executed, since in that case the cmdline
is changed with the value set by GRUB_CMDLINE_LINUX in /etc/default/grub.

To prevent the cmdline set by users to be overridden by mistake, keep the
value of GRUB_CMDLINE_LINUX in sync with the current cmdline.

Related: rhbz#1287854

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
This commit is contained in:
Javier Martinez Canillas 2020-03-30 10:54:20 +02:00
parent 5f9558c222
commit 8c7d866907
No known key found for this signature in database
GPG Key ID: C751E590D63F3D69
2 changed files with 15 additions and 2 deletions

View File

@ -492,7 +492,12 @@ update_bls_fragment() {
fi
if [[ $param = "ALL" && $bootloader = grub2 ]] && [[ -n $remove_args || -n $add_args ]]; then
local old_args="$(grub2-editenv "${env}" list | grep kernelopts | sed -e "s/kernelopts=//")"
local old_args="$(source ${grub_etc_default}; echo ${GRUB_CMDLINE_LINUX})"
opts="$(update_args "${old_args}" "${remove_args}" "${add_args}")"
opts=$(echo $opts | sed -e 's/\//\\\//g')
sed -i -e "s/^GRUB_CMDLINE_LINUX.*/GRUB_CMDLINE_LINUX=\\\"${opts}\\\"/" "${grub_etc_default}"
old_args="$(grub2-editenv "${env}" list | grep kernelopts | sed -e "s/kernelopts=//")"
opts="$(update_args "${old_args}" "${remove_args}" "${add_args}")"
grub2-editenv "${env}" set kernelopts="${opts}"
elif [[ $bootloader = grub2 ]]; then
@ -754,6 +759,10 @@ if [[ -z $grub_config ]]; then
grub_config="/boot/grub2/grub.cfg"
fi
if [[ -z $grub_etc_default ]]; then
grub_etc_default="/etc/default/grub"
fi
get_bls_values
default_index="$(get_default_index)"

View File

@ -1,6 +1,6 @@
Name: grubby
Version: 8.40
Release: 40%{?dist}
Release: 41%{?dist}
Summary: Command line tool for updating bootloader configs
License: GPLv2+
URL: https://github.com/rhinstaller/grubby
@ -133,6 +133,10 @@ current boot environment.
%{_mandir}/man8/*.8*
%changelog
* Mon Mar 30 2020 Javier Martinez Canillas <javierm@redhat.com> - 8.40-41
- Make grubby to also update GRUB_CMDLINE_LINUX in /etc/default/grub
Related: rhbz#1287854
* Mon Feb 10 2020 Javier Martinez Canillas <javierm@redhat.com> - 8.40-40
- Fix FTBFS
Resolves: rhbz#1799496