Remove old unused kernels on CentOS LInux

In this step we will list all currently installed kernels:

# rpm -q kernel

Using package-cleanup command which is a part of yum-utils package we can uninstall any number of old kernels automatically. As an example using –oldkernels –count=2 option with package-cleanup command the command will remove all unused kernel while keeping last three most recent kernel versions installed.

Let’s remove all kernels expect the latest currently loaded kernel:

package-cleanup --oldkernels --count=1
Loaded plugins: fastestmirror
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-327.36.3.el7 will be erased
---> Package kernel.x86_64 0:3.10.0-514.2.2.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================================
 Package                                         Arch                                            Version                                                      Repository                                          Size
=======================================================================================================================================================================================================================
Removing:
 kernel                                          x86_64                                          3.10.0-327.36.3.el7                                          @anaconda                                          136 M
 kernel                                          x86_64                                          3.10.0-514.2.2.el7                                           @updates                                           148 M

 

Configure yum to auto-remove old kernels

By default CentOS will keep last 5 kernels installed on your system. This behavior is defined by installonly_limit=5 line within /etc/yum.conf file. Update the /etc/yum.conf configuration file appropriately to keep desired number of old kernels on your system after update. The minimum value to be set is 2. Example of /etc/yum.conf configuration file to keep only last two kernel versions:

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=2
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

 

./ :https://linuxconfig.org/how-to-remove-old-unused-kernels-on-centos-linux

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.