Skip to content

Commit 9ab9652

Browse files
committed
Warn about incompatible kernel
And update grub settings so that convert2rhel can call grub2-mkconfig.
1 parent 3776829 commit 9ab9652

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

convert2rhel/actions/post_conversion/update_grub.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,44 @@
1818
from convert2rhel import actions, backup, grub, utils
1919
from convert2rhel.backup.files import RestorableFile
2020
from convert2rhel.logger import root_logger
21-
21+
from convert2rhel.systeminfo import system_info
2222

2323
logger = root_logger.getChild(__name__)
2424

2525

26+
class FixGrubSettingsOnAL2(actions.Action):
27+
id = "FIX_GRUB_SETTINGS_ON_AL2"
28+
29+
def run(self):
30+
"""On Amazon Linux 2 the GRUB_TERMINAL setting in /etc/default/grub is set to "ec2-console". Leaving it there
31+
prevents us from successfully executing grub2-mkconfig - we need to change that to "console".
32+
"""
33+
super(FixGrubSettingsOnAL2, self).run()
34+
35+
logger.task("Fix GRUB2 settings on Amazon Linux 2")
36+
if system_info.version.major != 2:
37+
logger.info("Not running Amazon Linux 2, skipping.")
38+
return
39+
40+
file_path = "/etc/default/grub"
41+
old_value = 'GRUB_TERMINAL="ec2-console"'
42+
new_value = 'GRUB_TERMINAL="console"'
43+
44+
content = utils.get_file_content(file_path)
45+
if old_value in content:
46+
updated_content = content.replace(old_value, new_value)
47+
48+
with open("/etc/default/grub", "w") as file:
49+
file.write(updated_content)
50+
logger.debug("Replaced {} with {} in {}.".format(old_value, new_value, file_path))
51+
logger.info("Successfully updated /etc/default/grub.")
52+
else:
53+
logger.info("{} not found in {}. Nothing to do.".format(old_value, file_path))
54+
55+
2656
class UpdateGrub(actions.Action):
2757
id = "UPDATE_GRUB"
58+
dependencies = ("FIX_GRUB_SETTINGS_ON_AL2",)
2859

2960
def run(self):
3061
"""Update GRUB2 images and config after conversion.

convert2rhel/actions/pre_ponr_changes/yum_variables.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def _back_up_var_files(self, paths):
8585
for filepath in paths:
8686
restorable_file = RestorableFile(filepath)
8787
backup.backup_control.push(restorable_file)
88+
logger.info("Yum variables successfully backed up.")
8889

8990

9091
class RestoreYumVarFiles(actions.Action):

convert2rhel/actions/system_checks/rhel_compatible_kernel.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# The kernel version stays the same throughout a RHEL major version
2929
COMPATIBLE_KERNELS_VERS = {
30-
2: "4.14.355", # Amazon Linux 2
30+
2: "4.18.0", # In Amazon Linux 2 there's no kernel of the same version as in RHEL (there's 4.14 and 5.10)
3131
7: "3.10.0",
3232
8: "4.18.0",
3333
9: "5.14.0",
@@ -68,7 +68,19 @@ def run(self):
6868
logger.warning(bad_kernel_message)
6969

7070
if system_info.version.major == 2:
71-
# Temp exception for Amazon Linux 2
71+
logger.warning(
72+
"Ignoring the check result on Amazon Linux 2 as there's no kernel of the same"
73+
" version as in RHEL available."
74+
)
75+
self.add_message(
76+
level="WARNING",
77+
id="INCOMPATIBLE_KERNEL_ON_AL2",
78+
title="Incompatible booted kernel version",
79+
description="On Amazon Linux 2 there's no kernel of the same version as in RHEL available."
80+
" The kernel downgrade during the conversion may cause issues, proceed at your"
81+
" own risk.",
82+
diagnosis=bad_kernel_message,
83+
)
7284
return
7385
self.set_result(
7486
level="ERROR",
@@ -111,11 +123,10 @@ def _bad_kernel_version(kernel_release):
111123
raise KernelIncompatibleError(
112124
"INCOMPATIBLE_VERSION",
113125
"Booted kernel version '{kernel_version}' does not correspond to the version "
114-
"'{compatible_version}' available in RHEL {rhel_major_version}",
126+
"'{compatible_version}' available in RHEL",
115127
{
116128
"kernel_version": kernel_version,
117129
"compatible_version": COMPATIBLE_KERNELS_VERS[system_info.version.major],
118-
"rhel_major_version": system_info.version.major,
119130
},
120131
)
121132

convert2rhel/data/7/x86_64/configs/amazon-2-x86_64.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ excluded_pkgs =
1717
gnome-documents-libs
1818
git-core*
1919
grub2-tools-efi
20+
grub2-efi-x64-ec2
2021
python3*
2122
libsanitizer
2223
update-motd
@@ -30,6 +31,7 @@ excluded_pkgs =
3031
libfdisk
3132
awscli
3233
aws-cfn-bootstrap
34+
amazon-linux-extras-yum-plugin
3335

3436
# Mapping of packages that need to be swapped during the transaction
3537
swap_pkgs =

convert2rhel/unit_tests/actions/system_checks/rhel_compatible_kernel_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_bad_kernel_version_success(kernel_release, major_ver, exp_return, monke
161161
8,
162162
"INCOMPATIBLE_VERSION",
163163
"Booted kernel version '{kernel_version}' does not correspond to the version "
164-
"'{compatible_version}' available in RHEL {rhel_major_version}",
164+
"'{compatible_version}' available in RHEL",
165165
{"kernel_version": "5.4.17", "compatible_version": COMPATIBLE_KERNELS_VERS[8], "rhel_major_version": 8},
166166
),
167167
),

0 commit comments

Comments
 (0)