База знань
How to Remove old kernels /boot is full. Роздрукувати цю статтю
This guide covers how to correctly remove old kernels to free up space on /boot partition. I do not take any responsibility for this article if you do not pay attention and you crash a system I am not responsible. If you are truly unsure of how to do this please get with a upper tier admin or myself to assist you. Please note that the versions below are only meant for reference please do not just copy and paste the commands please make sure to check your current kernel version and make sure that you do not remove the current installed kernel version.
First check for kernel updates:
[root@server1 logs]# yum check-update
kernel.i686 2.6.9-89.0.16.EL update
kernel-smp.i686 2.6.9-89.0.16.EL update
Now try and install the kernel updates:
[root@server1 logs]# yum update
Finished
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package kernel.i686 0:2.6.9-89.0.16.EL set to be installed
---> Package kernel-smp.i686 0:2.6.9-89.0.16.EL set to be installed
--> Running transaction check
Dependencies Resolved
=====================================================
Package Arch Version Repository Size
=====================================================
Installing:
kernel i686 2.6.9-89.0.16.EL update 13 M
kernel-smp i686 2.6.9-89.0.16.EL update 12 M
Transaction Summary
=====================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 26 M
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Check Error: installing package kernel-smp-2.6.9-89.0.16.EL needs 3MB on the /boot filesystem
Check the disk space:
[root@server1 logs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 122M 113M 2.9M 98% /boot
/boot is full so we need to remove some of the older kernels that are not being used, let's first check which kernel we are in so that we do not remove it by mistake.
[root@server1 logs]# uname -a
Linux server1.localhost.com 2.6.9-78.0.22.ELsmp #1 SMP Thu Apr 30 19:14:39 EDT 2009 i686 i686 i386 GNU/Linux
MAKE A NOTE OF THE CURRENT KERNEL VERSION WHEN YOU ARE REMOVING KERNELS.
Check to see which kernels are installed:
[root@server1 logs]# rpm -q kernel
kernel-2.6.9-67.EL
kernel-2.6.9-67.0.7.EL
kernel-2.6.9-67.0.4.EL
kernel-2.6.9-55.0.12.EL
kernel-2.6.9-42.EL
kernel-2.6.9-67.0.1.EL
kernel-2.6.9-67.0.15.EL
kernel-2.6.9-67.0.20.EL
kernel-2.6.9-67.0.22.EL
kernel-2.6.9-78.0.1.EL
kernel-2.6.9-78.0.5.EL
kernel-2.6.9-78.0.8.EL
kernel-2.6.9-78.0.13.EL
kernel-2.6.9-78.0.17.EL
kernel-2.6.9-78.0.22.EL
kernel-2.6.9-89.0.7.EL
kernel-2.6.9-89.0.9.EL
kernel-2.6.9-89.0.11.EL
Now remove the older kernels in the series like 2.6.9-42,55,67 but we can leave the 78 and 89's since they are newer. Be sure not to remove the current kernel.
[root@server1 logs]# rpm -e kernel-2.6.9-42.EL
[root@server1 logs]# rpm -e kernel-2.6.9-55.0.12.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.0.7.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.0.4.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.0.1.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.0.15.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.0.20.EL
[root@server1 logs]# rpm -e kernel-2.6.9-67.0.22.EL
Now make sure that we only have 2.6.9-78 and 2.6.9-89 kernels listed.
[root@server1 logs]# rpm -q kernel
kernel-2.6.9-78.0.1.EL
kernel-2.6.9-78.0.5.EL
kernel-2.6.9-78.0.8.EL
kernel-2.6.9-78.0.13.EL
kernel-2.6.9-78.0.17.EL
kernel-2.6.9-78.0.22.EL
kernel-2.6.9-89.0.7.EL
kernel-2.6.9-89.0.9.EL
kernel-2.6.9-89.0.11.EL
Good now check the free space:
[root@server1 logs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 122M 86M 30M 75% /boot
Now clean up some of the left over files on /boot
[root@server1 logs]# cd /boot/
Let's get a complete list of kernel files:
[root@server1 boot]# ll |grep config-
-rw-r--r-- 1 root root 49926 Aug 12 2006 config-2.6.9-42.ELsmp
-rw-r--r-- 1 root root 50058 Nov 2 2007 config-2.6.9-55.0.12.ELsmp
-rw-r--r-- 1 root root 50550 May 8 2008 config-2.6.9-67.0.15.ELsmp
-rw-r--r-- 1 root root 50549 Dec 19 2007 config-2.6.9-67.0.1.ELsmp
-rw-r--r-- 1 root root 50550 Jun 26 2008 config-2.6.9-67.0.20.ELsmp
-rw-r--r-- 1 root root 50550 Jul 24 2008 config-2.6.9-67.0.22.ELsmp
-rw-r--r-- 1 root root 50549 Feb 3 2008 config-2.6.9-67.0.4.ELsmp
-rw-r--r-- 1 root root 50549 Mar 15 2008 config-2.6.9-67.0.7.ELsmp
-rw-r--r-- 1 root root 50545 Nov 16 2007 config-2.6.9-67.ELsmp
-rw-r--r-- 1 root root 51502 Jan 14 2009 config-2.6.9-78.0.13.EL
-rw-r--r-- 1 root root 51127 Jan 14 2009 config-2.6.9-78.0.13.ELsmp
-rw-r--r-- 1 root root 51502 Mar 13 2009 config-2.6.9-78.0.17.EL
-rw-r--r-- 1 root root 51127 Mar 13 2009 config-2.6.9-78.0.17.ELsmp
-rw-r--r-- 1 root root 51501 Aug 5 2008 config-2.6.9-78.0.1.EL
-rw-r--r-- 1 root root 51126 Aug 5 2008 config-2.6.9-78.0.1.ELsmp
-rw-r--r-- 1 root root 51502 May 1 2009 config-2.6.9-78.0.22.EL
-rw-r--r-- 1 root root 51127 May 1 2009 config-2.6.9-78.0.22.ELsmp
-rw-r--r-- 1 root root 51501 Oct 8 2008 config-2.6.9-78.0.5.EL
-rw-r--r-- 1 root root 51126 Oct 8 2008 config-2.6.9-78.0.5.ELsmp
-rw-r--r-- 1 root root 51501 Nov 20 2008 config-2.6.9-78.0.8.EL
-rw-r--r-- 1 root root 51126 Nov 20 2008 config-2.6.9-78.0.8.ELsmp
-rw-r--r-- 1 root root 51614 Sep 15 14:12 config-2.6.9-89.0.11.EL
-rw-r--r-- 1 root root 51239 Sep 15 14:25 config-2.6.9-89.0.11.ELsmp
-rw-r--r-- 1 root root 51613 Aug 14 17:15 config-2.6.9-89.0.7.EL
-rw-r--r-- 1 root root 51238 Aug 14 17:27 config-2.6.9-89.0.7.ELsmp
-rw-r--r-- 1 root root 51613 Aug 24 14:53 config-2.6.9-89.0.9.EL
-rw-r--r-- 1 root root 51238 Aug 24 15:03 config-2.6.9-89.0.9.ELsmp
As we can see there are still some of the files from older kernels that were not removed when we removed kernels 2.6.9-42,55,67 so we are going to manually remove these.
[root@server1 boot]# rm -fv *2.6.9-4*
removed `config-2.6.9-42.ELsmp'
removed `initrd-2.6.9-42.ELsmp.img'
removed `System.map-2.6.9-42.ELsmp'
removed `vmlinuz-2.6.9-42.ELsmp'
[root@server1 boot]# rm -fv *2.6.9-5*
removed `config-2.6.9-55.0.12.ELsmp'
removed `initrd-2.6.9-55.0.12.ELsmp.img'
removed `System.map-2.6.9-55.0.12.ELsmp'
removed `vmlinuz-2.6.9-55.0.12.ELsmp'
[root@server1 boot]# rm -fv *2.6.9-6*
removed `config-2.6.9-67.0.15.ELsmp'
removed `config-2.6.9-67.0.1.ELsmp'
removed `config-2.6.9-67.0.20.ELsmp'
removed `config-2.6.9-67.0.22.ELsmp'
removed `config-2.6.9-67.0.4.ELsmp'
removed `config-2.6.9-67.0.7.ELsmp'
removed `config-2.6.9-67.ELsmp'
removed `initrd-2.6.9-67.0.15.ELsmp.img'
removed `initrd-2.6.9-67.0.1.ELsmp.img'
removed `initrd-2.6.9-67.0.20.ELsmp.img'
removed `initrd-2.6.9-67.0.22.ELsmp.img'
removed `initrd-2.6.9-67.0.4.ELsmp.img'
removed `initrd-2.6.9-67.0.7.ELsmp.img'
removed `initrd-2.6.9-67.ELsmp.img'
removed `symvers-2.6.9-67.0.15.ELsmp.gz'
removed `symvers-2.6.9-67.0.1.ELsmp.gz'
removed `symvers-2.6.9-67.0.20.ELsmp.gz'
removed `symvers-2.6.9-67.0.22.ELsmp.gz'
removed `symvers-2.6.9-67.0.4.ELsmp.gz'
removed `symvers-2.6.9-67.0.7.ELsmp.gz'
removed `symvers-2.6.9-67.ELsmp.gz'
removed `System.map-2.6.9-67.0.15.ELsmp'
removed `System.map-2.6.9-67.0.1.ELsmp'
removed `System.map-2.6.9-67.0.20.ELsmp'
removed `System.map-2.6.9-67.0.22.ELsmp'
removed `System.map-2.6.9-67.0.4.ELsmp'
removed `System.map-2.6.9-67.0.7.ELsmp'
removed `System.map-2.6.9-67.ELsmp'
removed `vmlinuz-2.6.9-67.0.15.ELsmp'
removed `vmlinuz-2.6.9-67.0.1.ELsmp'
removed `vmlinuz-2.6.9-67.0.20.ELsmp'
removed `vmlinuz-2.6.9-67.0.22.ELsmp'
removed `vmlinuz-2.6.9-67.0.4.ELsmp'
removed `vmlinuz-2.6.9-67.0.7.ELsmp'
removed `vmlinuz-2.6.9-67.ELsmp'
Now check and make sure that we only have 2.6.9-78 and 2.6.9-89 kernels left:
[root@server1 boot]# ll |grep config-
-rw-r--r-- 1 root root 51502 Jan 14 2009 config-2.6.9-78.0.13.EL
-rw-r--r-- 1 root root 51127 Jan 14 2009 config-2.6.9-78.0.13.ELsmp
-rw-r--r-- 1 root root 51502 Mar 13 2009 config-2.6.9-78.0.17.EL
-rw-r--r-- 1 root root 51127 Mar 13 2009 config-2.6.9-78.0.17.ELsmp
-rw-r--r-- 1 root root 51501 Aug 5 2008 config-2.6.9-78.0.1.EL
-rw-r--r-- 1 root root 51126 Aug 5 2008 config-2.6.9-78.0.1.ELsmp
-rw-r--r-- 1 root root 51502 May 1 2009 config-2.6.9-78.0.22.EL
-rw-r--r-- 1 root root 51127 May 1 2009 config-2.6.9-78.0.22.ELsmp
-rw-r--r-- 1 root root 51501 Oct 8 2008 config-2.6.9-78.0.5.EL
-rw-r--r-- 1 root root 51126 Oct 8 2008 config-2.6.9-78.0.5.ELsmp
-rw-r--r-- 1 root root 51501 Nov 20 2008 config-2.6.9-78.0.8.EL
-rw-r--r-- 1 root root 51126 Nov 20 2008 config-2.6.9-78.0.8.ELsmp
-rw-r--r-- 1 root root 51614 Sep 15 14:12 config-2.6.9-89.0.11.EL
-rw-r--r-- 1 root root 51239 Sep 15 14:25 config-2.6.9-89.0.11.ELsmp
-rw-r--r-- 1 root root 51613 Aug 14 17:15 config-2.6.9-89.0.7.EL
-rw-r--r-- 1 root root 51238 Aug 14 17:27 config-2.6.9-89.0.7.ELsmp
-rw-r--r-- 1 root root 51613 Aug 24 14:53 config-2.6.9-89.0.9.EL
-rw-r--r-- 1 root root 51238 Aug 24 15:03 config-2.6.9-89.0.9.ELsmp
Looks good now you need to edit the GRUB conf and remove the old kernels from the bottom of this config.
ONLY REMOVE OLD KERNELS THAT YOU HAVE REMOVED FROM THE SYSTEM.
[root@server1 boot]# vi /boot/grub/grub.conf
Scroll to the bottom and remove the ones that you have removed from the system:
title CentOS (2.6.9-67.0.22.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.0.22.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.0.22.ELsmp.img
title CentOS (2.6.9-67.0.20.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.0.20.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.0.20.ELsmp.img
title CentOS (2.6.9-67.0.15.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.0.15.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.0.15.ELsmp.img
title CentOS (2.6.9-67.0.7.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.0.7.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.0.7.ELsmp.img
title CentOS (2.6.9-67.0.4.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.0.4.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.0.4.ELsmp.img
title CentOS (2.6.9-67.0.1.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.0.1.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.0.1.ELsmp.img
title CentOS (2.6.9-67.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-67.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-67.ELsmp.img
title CentOS (2.6.9-55.0.12.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-55.0.12.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-55.0.12.ELsmp.img
title CentOS-4 i386 (2.6.9-42.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-42.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-42.ELsmp.img
Now check the free space:
[root@server1 boot]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 122M 60M 56M 52% /boot
This looks good now we can upgrade the kernel and reboot into the latest one:
[root@server1 boot]# yum update
Finished
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package kernel.i686 0:2.6.9-89.0.16.EL set to be installed
---> Package kernel-smp.i686 0:2.6.9-89.0.16.EL set to be installed
--> Running transaction check
Dependencies Resolved
=====================================================
Package Arch Version Repository Size
=====================================================
Installing:
kernel i686 2.6.9-89.0.16.EL update 13 M
kernel-smp i686 2.6.9-89.0.16.EL update 12 M
Transaction Summary
=====================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 26 M
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: kernel-smp ######################### [1/2]
Installing: kernel ######################### [2/2]
Installed: kernel.i686 0:2.6.9-89.0.16.EL kernel-smp.i686 0:2.6.9-89.0.16.EL
Complete!
I usually go ahead and check the GRUB conf to make sure that it sets the correct kernel as default, which it usually does but this is just habit.
You want this to be default of 1 since it's booting into the SMP kernel, if you are not running SMP kernel it should be default 0 to boot into the first kernel.
[root@server1 boot]# vi /boot/grub/grub.conf
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.9-89.0.16.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-89.0.16.EL ro root=LABEL=/
initrd /initrd-2.6.9-89.0.16.EL.img
title CentOS (2.6.9-89.0.16.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-89.0.16.ELsmp ro root=LABEL=/
initrd /initrd-2.6.9-89.0.16.ELsmp.img
Once this is completed completed go ahead and reboot the system.
[root@server1 boot]# reboot
When the system comes back online make sure it's in the latest kernel:
[root@server1 ~]# uname -a
Linux server1.localhost.com 2.6.9-89.0.16.ELsmp #1 SMP Tue Nov 3 17:34:21 EST 2009 i686 i686 i386 GNU/Linux