Page 1 of 1

Removing Older Kernels (SOLVED)

Posted: Wed Apr 13, 2011 1:04 pm
by NewDisciple
I checked Google for info on removing older kernels from Debian systems. Most of what I found was dated material. Two recent entries included:
http://stoilis.wordpress.com/2010/06/18 ... ributions/ which showcased the following script to remove old kernels.

#!/bin/bash -x
CURRENT_KERNEL=`uname -r | awk -F- ‘{print $1}’`
cd /boot
NUMBER_OF_INSTALLED_KERNELS=`ls vmlinuz* | grep -v $CURRENT_KERNEL | wc -l`
if [ "$NUMBER_OF_INSTALLED_KERNELS" -lt "2" ]
then
echo “Nothing to do. Exiting.”
exit
fi
INSTALLED_KERNELS=`ls vmlinuz* | grep -v $CURRENT_KERNEL | head -n $(($INSTALLED_KERNELS-1))`
echo $INSTALLED_KERNELS
for a in $INSTALLED_KERNELS
do
a=”`echo $a | awk -F- ‘{print $2″-”$3}’`”
if [ "$KERNELS_TO_REMOVE" == "" ]
then
KERNELS_TO_REMOVE=$a
else
KERNELS_TO_REMOVE=”$KERNELS_TO_REMOVE|$a”
fi
done
apt-get remove -y –purge `dpkg -l | awk ‘{print $2}’ | egrep “$KERNELS_TO_REMOVE”`

The second site: http://www.unixmen.com/linux-tutorials/ ... ed-systems
showcased this code:

sudo apt-get remove $(dpkg -l|egrep '^ii  linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)

Has anyone tried either of these methods and do they work? Are there other methods?

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 1:31 pm
by viking777
Congrats for searching before asking, but really the results you post there are mind bogglingly difficult.

To remove old kernels open Synaptic, search for "linux-image" right click on the one you no longer want and select "remove completely".

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 3:06 pm
by Beardedragon
It also helps to run the following just to make sure before rebooting:

Code: Select all

sudo update-grub

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 3:47 pm
by MALsPa
viking777 wrote:To remove old kernels open Synaptic, search for "linux-image" right click on the one you no longer want and select "remove completely".
I use this approach, too. Then, the following before rebooting:
Beardedragon wrote:

Code: Select all

sudo update-grub

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 4:42 pm
by linuxviolin
MALsPa wrote:
viking777 wrote:To remove old kernels open Synaptic, search for "linux-image" right click on the one you no longer want and select "remove completely".
I use this approach, too. Then, the following before rebooting:
Beardedragon wrote:

Code: Select all

sudo update-grub
I guess this is not really necessary because when you add or remove a kernel, with Synaptic or with the command line, Grub is automatically updated at the same time... :idea:

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 5:15 pm
by MALsPa
I think you're right, linuxviolin.

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 5:53 pm
by Beardedragon
MALsPa wrote:I think you're right, linuxviolin.
There have been cases where Windows 7 was not recognized just using Synaptic and the Command line for "update-grub" worked. Not arguing, it's only one small step.

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 6:37 pm
by linuxviolin
Beardedragon wrote:There have been cases where Windows 7 was not recognized just using Synaptic and the Command line for "update-grub" worked.
Oh, because you have Windows 7... :lol: Sorry, I had not seen your signature. :P

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 6:37 pm
by NewDisciple
Tried synaptic and got the following error msg: E: linux-image-2.6.32-5-amd64: subprocess installed pre-removal script returned error exit status 1.
According to http://us.generation-nt.com/bug-601962- ... 81891.html states:
Bug#601962: linux-image-2.6.32-5-amd64: removal fails in a clean chroot
October 31st, 2010 - 07:00 am ET by Lucas Nussbaum
Package: linux-image-2.6.32-5-amd64
Version: 2.6.32-26
Severity: serious

Hi,

Removing linux-image-2.6.32-5-amd64 in a clean chroot fails:
# apt-get remove --purge linux-image-2.6.32-5-amd64
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-image-2.6.32-5-amd64*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 99.0 MB disk space will be freed.
Do you want to continue [Y/n]?
(Reading database ... 9662 files and directories currently installed.)
Removing linux-image-2.6.32-5-amd64 ...
dpkg: error processing linux-image-2.6.32-5-amd64 (--purge):
subprocess installed pre-removal script returned error exit status 1
configured to not write apport reports
Errors were encountered while processing:
linux-image-2.6.32-5-amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

- Lucas

I haven't found any work arounds so I'm kind of stuck.

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 7:05 pm
by Beardedragon
linuxviolin wrote:
Beardedragon wrote:There have been cases where Windows 7 was not recognized just using Synaptic and the Command line for "update-grub" worked.
Oh, because you have Windows 7... :lol: Sorry, I had not seen your signature. :P
LOL yeah and I just got a new desktop with a big HD with plenty of room, so far. Windows will be the first thing to go, but while it's here might as well keep it up to date, gag, choke, :lol:

Re: Removing Older Kernels

Posted: Wed Apr 13, 2011 7:09 pm
by Beardedragon
@NewDisciple, what Kernel were you using when you tried to remove that one? You can't remove the one you are in, thus the (Error exit status 1)

Re: Removing Older Kernels (SOLVED)

Posted: Wed Apr 13, 2011 7:47 pm
by NewDisciple
Thanks for the tip, I had somehow logged into 2.6.32-5-amd64 instead of 2.6.38.2-amd64 2.6.38.3.

Re: Removing Older Kernels (SOLVED)

Posted: Wed Apr 13, 2011 9:01 pm
by Beardedragon
NewDisciple wrote:Thanks for the tip, I had somehow logged into 2.6.32-5-amd64 instead of 2.6.38.2-amd64 2.6.38.3.
:wink: Welcome.

Re: Removing Older Kernels (SOLVED)

Posted: Thu Nov 29, 2012 4:29 pm
by Brahim Salem
to remove old kernel entries in Grub on Linux Mint if you can't find the unwanted kernel in synaptic package manager simply run( to reinstall grub):


sudo apt-get --reinstall install grub2

then run: sudo update-grub

that's it!! :D

An easier and safer way to do this is to use ubuntu tweak. Install ubuntu tweak as follows:

sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak

Once you have installed ubuntu tweak use the following procedure to remove old kernels:

Step 1 -- Select "Package Cleaner" on the left and ""Clean Kernel" from the right panel.

Step 2 -- Press the "Unlock" button at the lower right, enter your password.

Step 3 -- Select from the displayed list the kernel images and headers you wish to remove. The kernel in use is not listed.

step 4 - Press the "Cleanup" button at the lower right to remove the selected kernel images and headers.


In ubuntu 12.04 and later versions go to "janitor" then chck "Old Kernel" then clean ur system