1
0
Fork 0

bootloader: fixed cmdline duplication with BLS and grub2-mkconfig

After application of this patch in order to get rid of the duplicated
kernel command line options (which was duplicated due to the usage of
the grub2-mkconfig), the grub2-mkconfig needs to be run again.
We do not run it automatically in the spec file %post not to break
users not using grub2-mkconfig.

This fix expects that user has not modified the line containing the
GRUB_CMDLINE_LINUX_DEFAULT option and the $tuned_params in the
/etc/default/grub file. If user modified this line, the option
duplication may still occure. In such case, please remove the
$tuned_params from the /etc/default/grub by hand.

Resolves: rhbz#1777874

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2020-11-29 21:34:15 +01:00
parent 8558162549
commit a0fd433e87
No known key found for this signature in database
GPG key ID: D8E1C00E076E840B

View file

@ -35,6 +35,7 @@ class BootloaderPlugin(base.Plugin):
self._cmdline_val = ""
self._initrd_val = ""
self._grub2_cfg_file_names = self._get_grub2_cfg_files()
self._bls = self._bls_enabled()
def _instance_cleanup(self, instance):
pass
@ -88,6 +89,15 @@ class BootloaderPlugin(base.Plugin):
cfg_files.append(f)
return cfg_files
def _bls_enabled(self):
grub2_default_env = self._cmd.read_file(consts.GRUB2_DEFAULT_ENV_FILE)
if len(grub2_default_env) <= 0:
log.info("cannot read '%s'" % consts.GRUB2_DEFAULT_ENV_FILE)
return False
return re.search(r"^\s*GRUB_ENABLE_BLSCFG\s*=\s*\"?\s*[tT][rR][uU][eE]\s*\"?\s*$", grub2_default_env,
flags = re.MULTILINE) is not None
def _patch_bootcmdline(self, d):
return self._cmd.add_modify_option_in_file(consts.BOOT_CMDLINE_FILE, d)
@ -154,6 +164,25 @@ class BootloaderPlugin(base.Plugin):
self._cmd.write_to_file(consts.GRUB2_DEFAULT_ENV_FILE, grub2_default_env)
return True
def _grub2_default_env_unpatch(self):
grub2_default_env = self._cmd.read_file(consts.GRUB2_DEFAULT_ENV_FILE)
if len(grub2_default_env) <= 0:
log.info("cannot read '%s'" % consts.GRUB2_DEFAULT_ENV_FILE)
return False
write = False
if re.search(r"^GRUB_CMDLINE_LINUX_DEFAULT=\"\$\{GRUB_CMDLINE_LINUX_DEFAULT:\+\$GRUB_CMDLINE_LINUX_DEFAULT \}\\\$" +
consts.GRUB2_TUNED_VAR + "\"$", grub2_default_env, flags = re.MULTILINE):
write = True
cfg = re.sub(r"^GRUB_CMDLINE_LINUX_DEFAULT=\"\$\{GRUB_CMDLINE_LINUX_DEFAULT:\+\$GRUB_CMDLINE_LINUX_DEFAULT \}\\\$" +
consts.GRUB2_TUNED_VAR + "\"$\n", "", grub2_default_env, flags = re.MULTILINE)
if cfg[-1] != "\n":
cfg += "\n"
if write:
log.debug("unpatching '%s'" % consts.GRUB2_DEFAULT_ENV_FILE)
self._cmd.write_to_file(consts.GRUB2_DEFAULT_ENV_FILE, cfg)
return True
def _grub2_cfg_patch(self, d):
log.debug("patching grub.cfg")
if not self._grub2_cfg_file_names:
@ -180,7 +209,10 @@ class BootloaderPlugin(base.Plugin):
if patch_initial:
grub2_cfg_new = self._grub2_cfg_patch_initial(self._grub2_cfg_unpatch(grub2_cfg), d)
self._cmd.write_to_file(f, grub2_cfg_new)
self._grub2_default_env_patch()
if self._bls:
self._grub2_default_env_unpatch()
else:
self._grub2_default_env_patch()
return True
def _grub2_update(self):