The cart is empty

CentOS 7, like most Linux distributions, regularly receives kernel updates that bring new features, performance improvements, and security fixes. However, with each new kernel update, the old version gets stored on the disk, which can eventually lead to a shortage of free space. This article provides a detailed guide on how to remove old kernel versions in CentOS 7 to free up disk space.

Prerequisites

Before proceeding, it's important to ensure that you have a system backup. Removing the kernel can cause boot issues if not done correctly. Also, make sure you have the latest kernel installed and the system is running smoothly on it.

Step 1: Determine Installed Kernel Versions

To find out which kernel versions are installed on your system, open a terminal and enter the following command:

rpm -q kernel

This command will list all installed kernel versions. It's recommended to keep the latest version and at least one previous version as a backup.

Step 2: Removing Old Kernel Versions

CentOS 7 includes the package-cleanup tool, which is part of the yum-utils package. If yum-utils is not already installed, you can install it using the following command:

sudo yum install yum-utils

Then, you can easily remove old kernel versions using the package-cleanup tool. To remove all old kernel versions except the last two, you can use the following command:

sudo package-cleanup --oldkernels --count=2

The --count=2 parameter specifies that you want to keep the last two kernel versions, including the currently used one. You can adjust the value according to your needs.

Step 3: Check Disk Space

After removing old kernel versions, it's good to check how much disk space has been freed. Use the command:

df -h

This command will display disk usage information in a readable format.

Step 4: Restart the System

To apply the changes and ensure that the system uses only the current kernel version, it's recommended to reboot the system:

sudo reboot

After rebooting, you can use the rpm -q kernel command again to verify that the old kernel versions have been successfully removed.

 

Removing old kernel versions is a straightforward way to free up disk space on CentOS 7. However, it's important to proceed with caution, ensure you have a functional kernel version, and keep at least one backup version in case of any issues.