Too many old kernels -> how can I delete the old Linux kernels?

Asked by Xpatnat on 2011-01-17

1/ I have too many kernels listed in Grub and I wish to remove old ones. I'm not sure how to do it safely.

2/ I've noticed that some are not even listed in Grub but appear when I type dpkg --list | grep linux-image in the terminal (list below).
On the other hand when I type rastanat@rastanat-laptop:/boot$ ls vmlinuz* this is what I get :
vmlinuz-2.6.32-24-generic vmlinuz-2.6.35-23-generic vmlinuz-2.6.35-24-generic
It's confusing :-0 (yeah I'm not so technical as you must have guessed it).

I'm using 2.6.35-24-generic (uname -r result) and I also wish to keep the 2.6.35-23 (just in case of a disaster).
Can some one explain to me how to do so and why the kernels lists are different?

Thanks in advance :-)

dpkg --list | grep linux-image gives me the following :

rastanat@rastanat-laptop:~$ dpkg --list | grep linux-image
rc linux-image-2.6.32-23-generic 2.6.32-23.37 Linux kernel image for version 2.6.32 on x86/x86_64
ii linux-image-2.6.32-24-generic 2.6.32-24.43 Linux kernel image for version 2.6.32 on x86/x86_64
rc linux-image-2.6.32-25-generic 2.6.32-25.44 Linux kernel image for version 2.6.32 on x86/x86_64
rc linux-image-2.6.32-25-generic-pae 2.6.32-25.44 Linux kernel image for version 2.6.32 on x86
rc linux-image-2.6.33-02063303-generic 2.6.33-02063303 Linux kernel image for version 2.6.33 on x86/x86_64
rc linux-image-2.6.35-22-generic 2.6.35-22.35 Linux kernel image for version 2.6.35 on x86/x86_64
ii linux-image-2.6.35-23-generic 2.6.35-23.41 Linux kernel image for version 2.6.35 on x86/x86_64
ii linux-image-2.6.35-24-generic Linux kernel image for version 2.6.35 on x86/x86_64
ii linux-image-generic 2.6.35.24.28 Generic Linux kernel image

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu linux Edit question
Assignee:
No assignee Edit question
Solved by:
Mark Rijckenberg
Solved:
2011-01-17
Last query:
2011-01-17
Last reply:
2011-01-17

Hi,

I created a Linux korn shell script called removekernel

You will need to install the ksh shell first using the following Terminal command:

sudo apt-get install ksh

Here are the contents of the removekernel script:

#!/bin/ksh

if [[ $1 == "" ]]; then
echo "No argument added after removekernel command"
echo "Please enter kernelversion to remove from your pc (for example: 2.6.35-22) "
read KERNELVERSION

echo "Removing kernelversion $KERNELVERSION"
apt-cache search $KERNELVERSION|cut -d" " -f1|xargs sudo apt-get remove -y

else
echo "Removing kernelversion $1"
apt-cache search $1|cut -d" " -f1|xargs sudo apt-get remove -y
fi

The script above will allow you to remove previous kernel versions with ease.

After making the script removekernel executable, you can use it like this in the Terminal:

removekernel 2.6.32-24

to delete the 2.6.32-24 kernel.

Watch out though: if you use the following command and you do not have any 2.6.32 kernels installed, then you wipe out ALL available Linux kernels:

removekernel 2.6.35

is VERY dangerous as it wipes out all 2.6.35 kernels :-)

Regards,

Mark

Concerning the second question:

"Can some one explain to me how to do so and why the kernels lists are different?"

please create a separate thread for that separate question using the following link:

https://answers.launchpad.net/ubuntu/+addquestion

Xpatnat (xpatnat) said : #3

Thanks Mark for answering question 1.
Kernels clean successfully done :-)

Xpatnat (xpatnat) said : #4

Will post the question 2 in a different thread as suggested.
Thanx

Xpatnat (xpatnat) said : #5

Thanks Mark Rijckenberg, that solved my question.