10.10: Delete old kernels

Asked by peter

Hi

How can I delete old kernels? Thanks in advance.
Peter

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu apt Edit question
Assignee:
No assignee Edit question
Solved by:
peter
Solved:
Last query:
Last reply:
Revision history for this message
Theodotos Andreou (theodotos) said :
#1

First find the package they are associated with. All kernels are stored under /boot. To see what you have (an example from my PC):

Look for installed packages starting with "linux-"

  dpkg --get-selections | grep ^linux- | awk '{print $1}'

The output on my PC is:

linux-firmware
linux-generic-pae
linux-headers-2.6.35-22
linux-headers-2.6.35-22-generic-pae
linux-headers-2.6.35-23
linux-headers-2.6.35-23-generic-pae
linux-headers-generic-pae
linux-image-2.6.35-22-generic-pae
linux-image-2.6.35-23-generic-pae
linux-image-generic-pae
linux-libc-dev
linux-sound-base

From here you can remove the older versions:

  sudo apt-get --purge remove linux-headers-2.6.35-22 linux-headers-2.6.35-22-generic-pae linux-image-2.6.35-22-generic-pae

Revision history for this message
peter (peter-neuweiler) said :
#2

Thanks Theodotos.
Peter

Revision history for this message
Mark Rijckenberg (markrijckenberg) said :
#3

Hi,

I created a Linux korn shell script called removekernel

You will need to install the ksh shell first using:

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.35-22

to delete the 2.6.35-22 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 :-)

Regards,

Mark

Revision history for this message
peter (peter-neuweiler) said :
#4

Thanks Mark
Peter

Revision history for this message
Mark Rijckenberg (markrijckenberg) said :
#5

If your question has been fully answered, please set the thread status to solved. Thanks.

Revision history for this message
peter (peter-neuweiler) said :
#6

solved