How to Remove Old Unused Kernels in Unix

Remove Old Unused Kernels in Unix


In this article, we are going to demonstrate How to Remove Old Unused Kernels in Unix. The kernel is part of an operating system that stores in a small partition of OS called /boot. Whenever we update/upgrade a system, it will install all required updates along with the kernel images but on the same side, it will not remove old unused kernels after update/upgrade.

It is required to clean old unused kernels to release space from /boot to avoid out of space. And also if it becomes out of space partition /boot then neither we can upgrade the system nor install available kernels. Let’s start removing old unused old kernels.

List out all installed kernels in the system.

[root@DBsGuruN3 ~]# rpm -qa | grep kernel
kernel-uek-5.4.17-2102.204.4.2.el8uek.x86_64
kernel-uek-devel-5.4.17-2011.7.4.el8uek.x86_64
kernel-uek-5.4.17-2011.7.4.el8uek.x86_64
kernel-tools-4.18.0-240.el8.x86_64
kernel-tools-libs-4.18.0-240.el8.x86_64
abrt-addon-kerneloops-2.10.9-20.0.1.el8.x86_64
kernel-headers-4.18.0-240.el8.x86_64
kernel-devel-4.18.0-240.el8.x86_64
[root@DBsGuruN3 ~]#
[root@DBsGuruN3 ~]# yum list kernel-uek
Last metadata expiration check: 0:41:50 ago on Mon 16 Aug 2021 05:53:24 PM IST.
Installed Packages
kernel-uek.x86_64                                                                            5.4.17-2011.7.4.el8uek                                                                                 @anaconda
kernel-uek.x86_64                                                                            5.4.17-2102.204.4.2.el8uek                                                                             @ol8_UEKR6
Available Packages
kernel-uek.src                                                                               5.4.17-2102.204.4.2.el8uek                                                                             ol8_UEKR6
[root@DBsGuruN3 ~]#


Validate the currently used kernel in the system.

[root@DBsGuruN3 ~]# uname -r
5.4.17-2011.7.4.el8uek.x86_64

or

[root@DBsGuruN3 ~]# uname -a
Linux DBsGuruN3.labdomain 5.4.17-2011.7.4.el8uek.x86_64 #2 SMP Fri Oct 2 14:39:04 PDT 2020 x86_64 x86_64 x86_64 GNU/Linux


Remove old unused kernels: We have available options to remove unused kernels manually as well as automatically.

Manually deletion: In this option, we can pass old unused kernels as many you want.

[root@DBsGuruN3 ~]# dnf remove kernel-headers-4.18.0-240.el8.x86_64 kernel-devel-4.18.0-240.el8.x86_64
Dependencies resolved.
==============================================================================================================================================================================================================
 Package                                       Architecture                       Version                                                                Repository                                      Size
==============================================================================================================================================================================================================
Removing:
 kernel-devel                                  x86_64                             4.18.0-240.el8                                                         @anaconda                                       47 M
 kernel-headers                                x86_64                             4.18.0-240.el8                                                         @anaconda                                      4.8 M
Removing dependent packages:
 annobin                                       x86_64                             9.23-1.el8                                                             @AppStream                                     132 k
 gcc-c++                                       x86_64                             8.3.1-5.1.0.2.el8                                                      @ol8_appstream                                  31 M
 gcc-gdb-plugin                                x86_64                             8.3.1-5.1.0.2.el8                                                      @ol8_appstream                                 334 k
 kernel-uek-devel                              x86_64                             5.4.17-2011.7.4.el8uek                                                 @ol8_UEKR6                                      74 M
 libtool                                       x86_64                             2.4.6-25.el8                                                           @AppStream                                     2.6 M
 mcelog                                        x86_64                             3:166-0.0.1.el8                                                        @anaconda                                      191 k
 pcp-pmda-bcc                                  x86_64                             5.1.1-3.0.1.el8                                                        @AppStream                                     282 k
 pcp-pmda-bpftrace                             x86_64                             5.1.1-3.0.1.el8                                                        @AppStream                                      62 k
 systemtap                                     x86_64                             4.3-4.0.1.el8                                                          @AppStream                                       0
Removing unused dependencies:
 bcc                                           x86_64                             0.14.0-4.el8                                                           @AppStream                                      41 M
 bcc-tools                                     x86_64                             0.14.0-4.el8                                                           @AppStream                                     1.7 M
 binutils-devel                                x86_64                             2.30-79.0.1.el8                                                        @ol8_appstream                                 6.4 M
 bpftrace                                      x86_64                             0.10.0-4.el8                                                           @AppStream                                     1.6 M
 clang                                         x86_64                             10.0.1-1.0.1.module+el8.3.0+7827+89335dbf                              @AppStream                                     177 k
 clang-devel                                   x86_64                             10.0.1-1.0.1.module+el8.3.0+7827+89335dbf                              @AppStream                                      13 M
 clang-libs                                    x86_64                             10.0.1-1.0.1.module+el8.3.0+7827+89335dbf                              @AppStream                                      96 M
 clang-tools-extra                             x86_64                             10.0.1-1.0.1.module+el8.3.0+7827+89335dbf                              @AppStream                                      47 M
 cmake-filesystem                              x86_64                             3.11.4-7.el8                                                           @AppStream                                       0
 compiler-rt                                   x86_64                             10.0.1-1.module+el8.3.0+7827+89335dbf                                  @AppStream                                      31 M
 cpp                                           x86_64                             8.3.1-5.1.0.2.el8                                                      @ol8_appstream                                  28 M
 gcc                                           x86_64                             8.3.1-5.1.0.2.el8                                                      @ol8_appstream                                  59 M
 glibc-devel                                   x86_64                             2.28-127.0.1.el8                                                       @anaconda                                      1.2 M
 glibc-headers                                 x86_64                             2.28-127.0.1.el8                                                       @anaconda                                      1.9 M
 isl                                           x86_64                             0.16.1-6.el8                                                           @AppStream                                     3.1 M
 libomp                                        x86_64                             10.0.1-1.module+el8.3.0+7827+89335dbf                                  @AppStream                                     965 k
 libomp-devel                                  x86_64                             10.0.1-1.module+el8.3.0+7827+89335dbf                                  @AppStream                                      89 k
 libstdc++-devel                               x86_64                             8.3.1-5.1.0.2.el8                                                      @ol8_appstream                                  11 M
 libxcrypt-devel                               x86_64                             4.1.1-4.el8                                                            @anaconda                                       24 k
 mokutil                                       x86_64                             1:0.3.0-10.el8                                                         @anaconda                                       87 k
 python3-bcc                                   x86_64                             0.14.0-4.el8                                                           @AppStream                                     309 k
 python3-netaddr                               noarch                             0.7.19-8.el8                                                           @AppStream                                     8.4 M
 systemtap-client                              x86_64                             4.3-4.0.1.el8                                                          @AppStream                                      11 M
 systemtap-devel                               x86_64                             4.3-4.0.1.el8                                                          @AppStream                                     8.5 M
 zlib-devel                                    x86_64                             1.2.11-16.el8_2                                                        @ol8_baseos_latest                             138 k

Transaction Summary
==============================================================================================================================================================================================================
Remove  36 Packages

Freed space: 532 M
Is this ok [y/N]: yes
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                      1/1
  Running scriptlet: systemtap-4.3-4.0.1.el8.x86_64                                                                                                                                                       1/1
  Running scriptlet: systemtap-4.3-4.0.1.el8.x86_64                                                                                                                                                      1/36
  Erasing          : systemtap-4.3-4.0.1.el8.x86_64                                                                                                                                                      1/36
  Erasing          : kernel-uek-devel-5.4.17-2011.7.4.el8uek.x86_64                                                                                                                                      2/36
  Erasing          : binutils-devel-2.30-79.0.1.el8.x86_64                                                                                                                                               3/36
  Running scriptlet: pcp-pmda-bpftrace-5.1.1-3.0.1.el8.x86_64                                                                                                                                            4/36
  Erasing          : pcp-pmda-bpftrace-5.1.1-3.0.1.el8.x86_64                                                                                                                                            4/36
  Running scriptlet: pcp-pmda-bcc-5.1.1-3.0.1.el8.x86_64                                                                                                                                                 5/36
  Erasing          : pcp-pmda-bcc-5.1.1-3.0.1.el8.x86_64                                                                                                                                                 5/36
  Running scriptlet: libtool-2.4.6-25.el8.x86_64                                                                                                                                                         6/36
  Erasing          : libtool-2.4.6-25.el8.x86_64                                                                                                                                                         6/36
  Erasing          : bpftrace-0.10.0-4.el8.x86_64                                                                                                                                                        7/36
  Erasing          : python3-bcc-0.14.0-4.el8.x86_64                                                                                                                                                     8/36
  Erasing          : bcc-0.14.0-4.el8.x86_64                                                                                                                                                             9/36
  Erasing          : bcc-tools-0.14.0-4.el8.x86_64                                                                                                                                                      10/36
  Erasing          : clang-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                             11/36
  Erasing          : clang-tools-extra-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                 12/36
  Erasing          : clang-devel-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                       13/36
  Erasing          : clang-libs-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                        14/36
  Erasing          : libomp-devel-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                          15/36
  Erasing          : gcc-c++-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                   16/36
  Erasing          : systemtap-devel-4.3-4.0.1.el8.x86_64                                                                                                                                               17/36
  Erasing          : systemtap-client-4.3-4.0.1.el8.x86_64                                                                                                                                              18/36
  Running scriptlet: mcelog-3:166-0.0.1.el8.x86_64                                                                                                                                                      19/36
  Erasing          : mcelog-3:166-0.0.1.el8.x86_64                                                                                                                                                      19/36
  Running scriptlet: mcelog-3:166-0.0.1.el8.x86_64                                                                                                                                                      19/36
  Erasing          : gcc-gdb-plugin-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                            20/36
  Running scriptlet: gcc-gdb-plugin-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                            20/36
  Erasing          : annobin-9.23-1.el8.x86_64                                                                                                                                                          21/36
  Erasing          : kernel-devel-4.18.0-240.el8.x86_64                                                                                                                                                 22/36
  Erasing          : libstdc++-devel-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                           23/36
  Erasing          : cmake-filesystem-3.11.4-7.el8.x86_64                                                                                                                                               24/36
  Erasing          : python3-netaddr-0.7.19-8.el8.noarch                                                                                                                                                25/36
  Erasing          : zlib-devel-1.2.11-16.el8_2.x86_64                                                                                                                                                  26/36
  Running scriptlet: gcc-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                       27/36
  Erasing          : gcc-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                       27/36
  Running scriptlet: glibc-devel-2.28-127.0.1.el8.x86_64                                                                                                                                                28/36
  Erasing          : glibc-devel-2.28-127.0.1.el8.x86_64                                                                                                                                                28/36
  Erasing          : libxcrypt-devel-4.1.1-4.el8.x86_64                                                                                                                                                 29/36
  Erasing          : glibc-headers-2.28-127.0.1.el8.x86_64                                                                                                                                              30/36
  Erasing          : kernel-headers-4.18.0-240.el8.x86_64                                                                                                                                               31/36
  Running scriptlet: cpp-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                       32/36
  Erasing          : cpp-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                       32/36
  Erasing          : isl-0.16.1-6.el8.x86_64                                                                                                                                                            33/36
  Running scriptlet: isl-0.16.1-6.el8.x86_64                                                                                                                                                            33/36
  Erasing          : mokutil-1:0.3.0-10.el8.x86_64                                                                                                                                                      34/36
  Erasing          : compiler-rt-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                           35/36
  Erasing          : libomp-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                                36/36
  Running scriptlet: libomp-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                                36/36
  Verifying        : annobin-9.23-1.el8.x86_64                                                                                                                                                           1/36
  Verifying        : bcc-0.14.0-4.el8.x86_64                                                                                                                                                             2/36
  Verifying        : bcc-tools-0.14.0-4.el8.x86_64                                                                                                                                                       3/36
  Verifying        : binutils-devel-2.30-79.0.1.el8.x86_64                                                                                                                                               4/36
  Verifying        : bpftrace-0.10.0-4.el8.x86_64                                                                                                                                                        5/36
  Verifying        : clang-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                              6/36
  Verifying        : clang-devel-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                        7/36
  Verifying        : clang-libs-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                         8/36
  Verifying        : clang-tools-extra-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                  9/36
  Verifying        : cmake-filesystem-3.11.4-7.el8.x86_64                                                                                                                                               10/36
  Verifying        : compiler-rt-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                           11/36
  Verifying        : cpp-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                       12/36
  Verifying        : gcc-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                       13/36
  Verifying        : gcc-c++-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                                   14/36
  Verifying        : gcc-gdb-plugin-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                            15/36
  Verifying        : glibc-devel-2.28-127.0.1.el8.x86_64                                                                                                                                                16/36
  Verifying        : glibc-headers-2.28-127.0.1.el8.x86_64                                                                                                                                              17/36
  Verifying        : isl-0.16.1-6.el8.x86_64                                                                                                                                                            18/36
  Verifying        : kernel-devel-4.18.0-240.el8.x86_64                                                                                                                                                 19/36
  Verifying        : kernel-headers-4.18.0-240.el8.x86_64                                                                                                                                               20/36
  Verifying        : kernel-uek-devel-5.4.17-2011.7.4.el8uek.x86_64                                                                                                                                     21/36
  Verifying        : libomp-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                                22/36
  Verifying        : libomp-devel-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64                                                                                                                          23/36
  Verifying        : libstdc++-devel-8.3.1-5.1.0.2.el8.x86_64                                                                                                                                           24/36
  Verifying        : libtool-2.4.6-25.el8.x86_64                                                                                                                                                        25/36
  Verifying        : libxcrypt-devel-4.1.1-4.el8.x86_64                                                                                                                                                 26/36
  Verifying        : mcelog-3:166-0.0.1.el8.x86_64                                                                                                                                                      27/36
  Verifying        : mokutil-1:0.3.0-10.el8.x86_64                                                                                                                                                      28/36
  Verifying        : pcp-pmda-bcc-5.1.1-3.0.1.el8.x86_64                                                                                                                                                29/36
  Verifying        : pcp-pmda-bpftrace-5.1.1-3.0.1.el8.x86_64                                                                                                                                           30/36
  Verifying        : python3-bcc-0.14.0-4.el8.x86_64                                                                                                                                                    31/36
  Verifying        : python3-netaddr-0.7.19-8.el8.noarch                                                                                                                                                32/36
  Verifying        : systemtap-4.3-4.0.1.el8.x86_64                                                                                                                                                     33/36
  Verifying        : systemtap-client-4.3-4.0.1.el8.x86_64                                                                                                                                              34/36
  Verifying        : systemtap-devel-4.3-4.0.1.el8.x86_64                                                                                                                                               35/36
  Verifying        : zlib-devel-1.2.11-16.el8_2.x86_64                                                                                                                                                  36/36

Removed:
  annobin-9.23-1.el8.x86_64                                         bcc-0.14.0-4.el8.x86_64                                          bcc-tools-0.14.0-4.el8.x86_64
  binutils-devel-2.30-79.0.1.el8.x86_64                             bpftrace-0.10.0-4.el8.x86_64                                     clang-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64
  clang-devel-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64      clang-libs-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64      clang-tools-extra-10.0.1-1.0.1.module+el8.3.0+7827+89335dbf.x86_64
  cmake-filesystem-3.11.4-7.el8.x86_64                              compiler-rt-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64         cpp-8.3.1-5.1.0.2.el8.x86_64
  gcc-8.3.1-5.1.0.2.el8.x86_64                                      gcc-c++-8.3.1-5.1.0.2.el8.x86_64                                 gcc-gdb-plugin-8.3.1-5.1.0.2.el8.x86_64
  glibc-devel-2.28-127.0.1.el8.x86_64                               glibc-headers-2.28-127.0.1.el8.x86_64                            isl-0.16.1-6.el8.x86_64
  kernel-devel-4.18.0-240.el8.x86_64                                kernel-headers-4.18.0-240.el8.x86_64                             kernel-uek-devel-5.4.17-2011.7.4.el8uek.x86_64
  libomp-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64               libomp-devel-10.0.1-1.module+el8.3.0+7827+89335dbf.x86_64        libstdc++-devel-8.3.1-5.1.0.2.el8.x86_64
  libtool-2.4.6-25.el8.x86_64                                       libxcrypt-devel-4.1.1-4.el8.x86_64                               mcelog-3:166-0.0.1.el8.x86_64
  mokutil-1:0.3.0-10.el8.x86_64                                     pcp-pmda-bcc-5.1.1-3.0.1.el8.x86_64                              pcp-pmda-bpftrace-5.1.1-3.0.1.el8.x86_64
  python3-bcc-0.14.0-4.el8.x86_64                                   python3-netaddr-0.7.19-8.el8.noarch                              systemtap-4.3-4.0.1.el8.x86_64
  systemtap-client-4.3-4.0.1.el8.x86_64                             systemtap-devel-4.3-4.0.1.el8.x86_64                             zlib-devel-1.2.11-16.el8_2.x86_64

Complete!


Note: Use the below command for Linux6/7.

# yum remove <old unused kernel>


Automatically deletion: Add or replace the value of parameter “installonly_limit” in file /etc/yum.conf which will take care of how many kernels keep after update/upgrade the system or install available kernels that depends on the value of the parameter “installonly_limit” i.e remove the old unused kernels automatically after update the system.

installonly_limit=2

[root@DBsGuruN3 ~]# cat /etc/yum.conf  
[main]
gpgcheck=1
installonly_limit=2
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False


List out all installed kernels in the system after removed old unused kernels.

[root@DBsGuruN3 ~]# rpm -qa | grep kernel
kernel-uek-5.4.17-2102.204.4.2.el8uek.x86_64
kernel-uek-5.4.17-2011.7.4.el8uek.x86_64
kernel-tools-4.18.0-240.el8.x86_64
kernel-tools-libs-4.18.0-240.el8.x86_64
abrt-addon-kerneloops-2.10.9-20.0.1.el8.x86_64


This document is only for learning purposes and always validate in the LAB environment first before applying in the LIVE environment.


Hope so you like this article
!
Please share your valuable feedback/comments/subscribe and follow us below and don’t forget to click on the bell icon to get the latest update. Click here to know more about our pursuit.

Related Articles

UNIX | UNIX:LINUX



 90 Total Views,  1 Views Today

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Spread the Knowledge!

Leave a Reply

Your email address will not be published. Required fields are marked *

2 + seven =

Open chat
1
Contact Us:
Hi,

Greetings of the day! How can we help you?

Thanks.
Team DBsGuru
Direct Call:+91-9310167776
Email: info@dbsguru.com

Share Learn Grow!


Click on the below technical group to join us to share expertise in PostgreSQL and MySQL on WhatsApp group. The purpose of this group is only help to the DBA community.

PostgreSQL Technical Group.

MySQL technical Group.

Technical Links Powered by DBsGuru.

Thanks.
Team DBsGuru.