@@ -109,10 +109,55 @@ def _extract_grubby_value(record):
109
109
return matches .group (2 )
110
110
111
111
112
+ def report_multple_entries_for_default_kernel ():
113
+ if use_cmdline_file ():
114
+ report_hint = (
115
+ 'After the system has been rebooted into the new version of RHEL,'
116
+ ' check that configured default kernel cmdline arguments in /etc/kernel/cmdline '
117
+ ' are correct. In case that different arguments are expected, update the file as needed.'
118
+ )
119
+ else :
120
+ report_hint = (
121
+ 'After the system has been rebooted into the new version of RHEL,'
122
+ ' check that configured default kernel cmdline arguments are set as expected, using'
123
+ ' the `grub2-editenv list` command. '
124
+ ' If different default arguments are expected, update them using grub2-editenv.\n '
125
+ ' For example, consider that current booted kernel has correct kernel cmdline'
126
+ ' arguments and /proc/cmdline contains:\n \n '
127
+ ' BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-425.3.1.el8.x86_64'
128
+ ' root=/dev/mapper/rhel_ibm--root ro console=tty0'
129
+ ' console=ttyS0,115200 rd_NO_PLYMOUTH\n \n '
130
+ ' then run the following grub2-editenv command:\n \n '
131
+ ' # grub2-editenv - set "kernelopts=root=/dev/mapper/rhel_ibm--root'
132
+ ' ro console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH"'
133
+ )
134
+
135
+ reporting .create_report ([
136
+ reporting .Title ('Ensure that expected default kernel cmdline arguments are set' ),
137
+ reporting .Summary (
138
+ 'During the upgrade we needed to modify the kernel command line arguments.'
139
+ ' However, multiple bootloader entries with different arguments were found for the default'
140
+ ' kernel (perhaps MAKEDEBUG=yes is set in /etc/sysconfig/kernel).'
141
+ ' Leapp used the arguments from the first found entry of the target kernel'
142
+ ' and set it as the new default kernel cmdline arguments for kernels installed in the future.'
143
+ ),
144
+ reporting .Remediation (hint = report_hint ),
145
+ reporting .Severity (reporting .Severity .HIGH ),
146
+ reporting .Groups ([
147
+ reporting .Groups .BOOT ,
148
+ reporting .Groups .KERNEL ,
149
+ reporting .Groups .POST ,
150
+ ]),
151
+ reporting .RelatedResource ('file' , '/etc/kernel/cmdline' ),
152
+ ])
153
+
154
+
112
155
def retrieve_args_for_default_kernel (kernel_info ):
113
156
# Copy the args for the default kernel to all kernels.
114
157
kernel_args = None
115
158
kernel_root = None
159
+ detected_multiple_entries = False
160
+
116
161
cmd = ['grubby' , '--info' , kernel_info .kernel_img_path ]
117
162
output = stdlib .run (cmd , split = False )
118
163
for record in output ['stdout' ].splitlines ():
@@ -122,26 +167,40 @@ def retrieve_args_for_default_kernel(kernel_info):
122
167
temp_kernel_args = _extract_grubby_value (record )
123
168
124
169
if kernel_args :
125
- api .current_logger ().warning ('Grubby output is malformed:'
126
- ' `args=` is listed more than once.' )
127
170
if kernel_args != temp_kernel_args :
128
- raise ReadOfKernelArgsError ('Grubby listed `args=` multiple'
129
- ' times with different values.' )
130
- kernel_args = _extract_grubby_value (record )
171
+ api .current_logger ().warning (
172
+ 'Grubby output listed `args=` multiple times with different values,'
173
+ ' continuing with the first result'
174
+ )
175
+ detected_multiple_entries = True
176
+ else :
177
+ api .current_logger ().warning ('Grubby output listed `args=` more than once' )
178
+ else :
179
+ kernel_args = temp_kernel_args
131
180
elif record .startswith ('root=' ):
132
- api . current_logger (). warning ( 'Grubby output is malformed:'
133
- ' `root=` is listed more than once.' )
181
+ temp_kernel_root = _extract_grubby_value ( record )
182
+
134
183
if kernel_root :
135
- raise ReadOfKernelArgsError ('Grubby listed `root=` multiple'
136
- ' times with different values' )
137
- kernel_root = _extract_grubby_value (record )
184
+ if kernel_root != temp_kernel_root :
185
+ api .current_logger ().warning (
186
+ 'Grubby output listed `root=` multiple times with different values,'
187
+ ' continuing with the first result'
188
+ )
189
+ detected_multiple_entries = True
190
+ else :
191
+ api .current_logger ().warning ('Grubby output listed `root=` more than once' )
192
+ else :
193
+ kernel_root = temp_kernel_root
138
194
139
195
if not kernel_args or not kernel_root :
140
196
raise ReadOfKernelArgsError (
141
197
'Failed to retrieve kernel command line to save for future installed'
142
198
' kernels: root={}, args={}' .format (kernel_root , kernel_args )
143
199
)
144
200
201
+ if detected_multiple_entries :
202
+ report_multple_entries_for_default_kernel ()
203
+
145
204
return kernel_root , kernel_args
146
205
147
206
0 commit comments