Skip to content

Commit bf971b3

Browse files
Use command from RedHat guide to clean up old kernels
The commands prior to this PR do not work with RHEL9. Therefore, we change the logic to use the command from the verified guide. I discussed the change with Giordano. We didn't have any concern. Signed-off-by: Hanwen <hanwenli@amazon.com>
1 parent 7043fc0 commit bf971b3

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

cli/src/pcluster/resources/imagebuilder/update_and_reboot.yaml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,8 @@ phases:
243243
yum -y update
244244
245245
if [[ ${!OS} == "rhel8" ]] || [[ ${!OS} == "rocky8" ]] || [[ ${!OS} == "rhel9" ]] || [[ ${!OS} == "rocky9" ]] ; then
246-
# package-cleanup has changed in RHEL8 and it works differently
247-
# RHEL8 keeps at least 2 kernel for fallback reason https://access.redhat.com/solutions/1227
248-
# The kernel cleanup should be performed manually
249-
250-
# get the default kernel for the next boot
251-
LAST_KERNEL_VERSION=$(grubby --default-kernel | sed -e "s/.*-\(4.18.0-.*\).$(uname -m)/\1/g")
252-
253-
# get all the installed kernel versions except the one for the next boot
254-
KERNEL_VERSIONS_CLEANUP=$(rpm -q --qf "%{VERSION}-%{RELEASE}\n" kernel | grep -v "$LAST_KERNEL_VERSION")
255-
for VERSION in $KERNEL_VERSIONS_CLEANUP; do
256-
echo "Removing kernel-$VERSION kernel-core-$VERSION kernel-modules-$VERSION"
257-
rpm -e kernel-$VERSION kernel-core-$VERSION kernel-modules-$VERSION;
258-
done
246+
# package-cleanup has changed in RHEL8 and it works differently https://access.redhat.com/solutions/1227
247+
yum remove $(yum repoquery --installonly --latest-limit=-2 -q)
259248
else
260249
package-cleanup -y --oldkernels --count=1
261250
fi

0 commit comments

Comments
 (0)