From 285de0bea2e7d7ada7b938a44639b3ad0ee6d393 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Mon, 16 Sep 2019 17:15:40 +0200 Subject: [grub2] call grub2-config with --no-grubenv-update when appropriate On some newer grub2 versions, grub2-config removes extra args in $kernel_opts until --no-grubenv-update option is used. Test if the option is present in "grub2-config --help" and if so, use it. Resolves: #1682 Signed-off-by: Pavel Moravec Signed-off-by: Jake Hunsaker --- sos/plugins/__init__.py | 2 +- sos/plugins/grub2.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 8084dbfb..e75ec82e 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -208,7 +208,7 @@ class SoSPredicate(object): '''Does 'cmd' output contain string 'output'?''' if 'cmd' not in cmd_output or 'output' not in cmd_output: return False - result = self._owner.get_command_output(cmd_output['cmd']) + result = sos_get_command_output(cmd_output['cmd']) if result['status'] != 0: return False for line in result['output'].splitlines(): diff --git a/sos/plugins/grub2.py b/sos/plugins/grub2.py index 9786de44..0ca6fe09 100644 --- a/sos/plugins/grub2.py +++ b/sos/plugins/grub2.py @@ -6,7 +6,8 @@ # # See the LICENSE file in the source distribution for further information. -from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin +from sos.plugins import (Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin, + SoSPredicate) class Grub2(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): @@ -32,9 +33,16 @@ class Grub2(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): self.add_cmd_output("ls -lanR /boot") # call grub2-mkconfig with GRUB_DISABLE_OS_PROBER=true to prevent # possible unwanted loading of some kernel modules + # further, check if the command supports --no-grubenv-update option + # to prevent removing of extra args in $kernel_opts, and (only) if so, + # call the command with this argument env = {} env['GRUB_DISABLE_OS_PROBER'] = 'true' - self.add_cmd_output("grub2-mkconfig", env=env) + grub_cmd = 'grub2-mkconfig' + co = {'cmd': 'grub2-mkconfig --help', 'output': '--no-grubenv-update'} + if self.test_predicate(self, pred=SoSPredicate(self, cmd_outputs=co)): + grub_cmd += ' --no-grubenv-update' + self.add_cmd_output(grub_cmd, env=env) def postproc(self): # the trailing space is required; python treats '_' as whitespace -- cgit