Friday, 13 March 2015

Oracle Linux 6: Remove Obsolete Kernels

I have several Virtual Machines for our Virtual Course Environments. From time to time, I do an upgrade of the Oracle Linux version. But with every upgrade, Oracle Linux leaves the old kernel files. And in time the root disk is cluttered up. So I want to remove the old kernels. With a little googling, I came up with a discussion thread in Oracle Communities: Oracle Linux Remove Old Kernels (Archived by now).

To me this was quite helpfull. Let me sum up the steps here.

1. List the kernels in the boot menu

First list the kernels in the boot menu with:
#cd /boot/grub
#cat grub.conf
In my example VM this is:
[root@darlin-vce-db ~]# cd /boot/grub
[root@darlin-vce-db grub]# cat grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_darlinvce-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Oracle Linux Server Red Hat Compatible Kernel (2.6.32-431.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_darlinvce-lv_root rd_LVM_LV=vg_darlinvce/lv_root rd_LVM_LV=vg_darlinvce/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us-acentos nomodeset  rhgb quiet crashkernel=auto numa=off
 initrd /initramfs-2.6.32-431.el6.x86_64.img
title Oracle Linux Server (2.6.32-279.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/mapper/vg_darlinvce-lv_root rd_LVM_LV=vg_darlinvce/lv_root rd_LVM_LV=vg_darlinvce/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us-acentos nomodeset  rhgb quiet crashkernel=auto numa=off
 initrd /initramfs-2.6.32-279.el6.x86_64.img
title Oracle Linux Server-uek (2.6.32-100.34.1.el6uek.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-100.34.1.el6uek.x86_64 ro root=/dev/mapper/vg_darlinvce-lv_root rd_LVM_LV=vg_darlinvce/lv_root rd_LVM_LV=vg_darlinvce/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us-acentos nomodeset  rhgb quiet numa=off
 initrd /initramfs-2.6.32-100.34.1.el6uek.x86_64.img
title Oracle Linux Server (2.6.32-131.0.15.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/mapper/vg_darlinvce-lv_root rd_LVM_LV=vg_darlinvce/lv_root rd_LVM_LV=vg_darlinvce/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us-acentos nomodeset crashkernel=auto rhgb quiet numa=off
 initrd /initramfs-2.6.32-131.0.15.el6.x86_64.img
The newest kernel (Oracle Linux 6 Update 5) is at the top. Apparently in my case I have the following kernels:
  • 2.6.32-431
  • 2.6.32-279
  • 2.6.32-100.34.1
  • 2.6.32-131.0.15
Let's make sure I have booted using the latest kernel:
[root@darlin-vce-db grub]# uname -r
2.6.32-431.el6.x86_64
So indeed Linux is started using the 2.6.32-431 kernel.

2. Remove obsolete kernels

Let's remove the last 3 one by one.
But before you do so, make a backup of the grub.conf, because the removal of the kernels may update your grub.conf and remove the newest kernel. Then you end up starting up a dated kernel version.

To list the kernel packages of one version:
[root@darlin-vce-db grub]# rpm -qa | grep kernel|grep 100
kernel-uek-2.6.32-100.34.1.el6uek.x86_64
kernel-uek-headers-2.6.32-100.34.1.el6uek.x86_64
kernel-uek-devel-2.6.32-100.34.1.el6uek.x86_64
kernel-uek-firmware-2.6.32-100.34.1.el6uek.noarch

Now to remove these packages use yum remove:
[root@darlin-vce-db grub]# yum remove kernel-uek-2.6.32-100.34.1.el6uek.x86_64  kernel-uek-headers-2.6.32-100.34.1.el6uek.x86_64 kernel-uek-devel-2.6.32-100.34.1.el6uek.x86_64 kernel-uek-firmware-2.6.32-100.34.1.el6uek.noarch
Loaded plugins: refresh-packagekit
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
....
Dependencies Resolved

=====================================================================================================================================================================================================
 Package                                               Arch                    Version                                    Repository                                                            Size
=====================================================================================================================================================================================================
Removing:
 kernel-uek                                            x86_64                  2.6.32-100.34.1.el6uek                     @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                   86 M
 kernel-uek-devel                                      x86_64                  2.6.32-100.34.1.el6uek                     @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                   22 M
 kernel-uek-firmware                                   noarch                  2.6.32-100.34.1.el6uek                     @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                  3.9 M
 kernel-uek-headers                                    x86_64                  2.6.32-100.34.1.el6uek                     @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                  2.2 M
Removing for dependencies:
 audit-libs-devel                                      x86_64                  2.2-2.el6                                  @anaconda-OracleLinuxServer-201206261930.x86_64/6.3                   70 k
 compat-gcc-34                                         x86_64                  3.4.6-19.el6                               @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                   13 M
 compat-gcc-34-c++                                     x86_64                  3.4.6-19.el6                               @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                   84 M
 compat-gcc-34-g77                                     x86_64                  3.4.6-19.el6                               @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                  5.9 M
 compat-glibc                                          x86_64                  1:2.5-46.2.0.1                             @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                  6.4 M
 compat-glibc-headers                                  x86_64                  1:2.5-46.2.0.1                             @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                  1.9 M
 gcc                                                   x86_64                  4.4.7-4.el6                                @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   19 M
 gcc-c++                                               x86_64                  4.4.7-4.el6                                @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   11 M
 glibc-devel                                           x86_64                  2.12-1.132.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  966 k
 glibc-headers                                         x86_64                  2.12-1.132.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  2.0 M
 libcap-ng-devel                                       x86_64                  0.6.4-3.el6_0.1                            @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                   14 k
 libcgroup                                             x86_64                  0.40.rc1-5.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  321 k
 libcgroup-devel                                       x86_64                  0.40.rc1-5.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   89 k
 libtool                                               x86_64                  2.2.6-15.5.el6                             @anaconda-OracleLinuxServer-201105261616.x86_64/6.1                  1.9 M
 oracle-rdbms-server-11gR2-preinstall                  x86_64                  1.0-7.el6                                  @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   32 k
 perl-Archive-Extract                                  x86_64                  1:0.38-136.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   52 k
 perl-CPAN                                             x86_64                  1.9402-136.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  663 k
 perl-CPANPLUS                                         x86_64                  0.88-136.el6                               @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  767 k
 perl-ExtUtils-CBuilder                                x86_64                  1:0.27-136.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   59 k
 perl-ExtUtils-Embed                                   x86_64                  1.28-136.el6                               @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   17 k
 perl-ExtUtils-MakeMaker                               x86_64                  6.55-136.el6                               @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  608 k
 perl-ExtUtils-ParseXS                                 x86_64                  1:2.2003.0-136.el6                         @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   61 k
 perl-File-Fetch                                       x86_64                  0.26-136.el6                               @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   46 k
 perl-IPC-Cmd                                          x86_64                  1:0.56-136.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   57 k
 perl-Module-Build                                     x86_64                  1:0.3500-136.el6                           @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  460 k
 perl-Test-Harness                                     x86_64                  3.17-136.el6                               @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  399 k
 perl-Test-Simple                                      x86_64                  0.92-136.el6                               @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  184 k
 perl-core                                             x86_64                  5.10.1-136.el6                             @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  0.0  
 perl-devel                                            x86_64                  4:5.10.1-136.el6                           @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  1.8 M
 redhat-lsb                                            x86_64                  4.0-7.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  0.0  
 redhat-lsb-compat                                     x86_64                  4.0-7.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  0.0  
 redhat-lsb-core                                       x86_64                  4.0-7.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   22 k
 redhat-lsb-graphics                                   x86_64                  4.0-7.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  0.0  
 redhat-lsb-printing                                   x86_64                  4.0-7.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  0.0  
 systemtap                                             x86_64                  2.3-3.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                   46 k
 systemtap-devel                                       x86_64                  2.3-3.0.1.el6                              @anaconda-OracleLinuxServer-201311252058.x86_64/6.5                  4.9 M

Transaction Summary
=====================================================================================================================================================================================================
Remove       40 Package(s)

Installed size: 270 M
Is this ok [y/N]: y

Answer with 'y', and wait until the removal is complete.
Repeat this for the other kernels as well.

3. Edit the grub.conf and last refreshments

Edit the grub.conf and remove the entries all the removed kernels, leaving only the entry of the latest kernel:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_darlinvce-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Oracle Linux Server Red Hat Compatible Kernel (2.6.32-431.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_darlinvce-lv_root rd_LVM_LV=vg_darlinvce/lv_root rd_LVM_LV=vg_darlinvce/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us-acentos nomodeset  rhgb quiet crashkernel=auto numa=off
 initrd /initramfs-2.6.32-431.el6.x86_64.img 
For each entry the line starting with 'title Oracle Linux Server...' is the first line of the entry.
After editing the grub.conf, you can reboot the server. If you're running inside an VirtualBox image, update the Virtualbox Guest Additions. I find it convenient to backup the VBoxGuest additions disk to a folder on one of the disks. When you update the VM with a new Linux Version, the guestadditions aren't compiled with the latest kernel anymore. Then XServer might not come up again, and mounting the guestadditions disk might not work. Then it is convenient to have a copy within the VM available to do a recompile from the console.

4. Re-install kernel-dependent pacakges

I found that tools like gcc, gcc-c++, etc. are removed at removing my first kernel. You can use yum to re-install them, using yum install , eg. yum install gcc. Yum will figure out the depencencies for you. What I re-installed was:

yum install gcc gcc-c++ glibc-devel glibc-headers perl kernel-headers compat-gcc-34 compat-gcc-34-c++ compat-gcc-34-g77 compat-glibc-headers libcap-ng-devel libtool systemtap systemtap-devel
These packages were installed and needed because of Oracle Database and Fusion Middleware. Also the VirtalBox Guest Additions need some of those.

No comments:

Post a Comment