Removing Older Kernels (SOLVED)

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
NewDisciple
Level 1
Level 1
Posts: 13
Joined: Tue Sep 14, 2010 11:52 pm
Location: Roseburg, Oregon

Removing Older Kernels (SOLVED)

Post 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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
viking777

Re: Removing Older Kernels

Post 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".
Beardedragon

Re: Removing Older Kernels

Post by Beardedragon »

It also helps to run the following just to make sure before rebooting:

Code: Select all

sudo update-grub
User avatar
MALsPa
Level 8
Level 8
Posts: 2040
Joined: Mon Nov 19, 2007 10:17 pm
Location: albuquerque

Re: Removing Older Kernels

Post 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
User avatar
linuxviolin
Level 8
Level 8
Posts: 2081
Joined: Tue Feb 27, 2007 6:55 pm
Location: France

Re: Removing Older Kernels

Post 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:
K.I.S.S. ===> "Keep It Simple, Stupid"
"Simplicity is the ultimate sophistication." (Leonardo da Vinci)
"Everything should be made as simple as possible, but no simpler." (Albert Einstein)
User avatar
MALsPa
Level 8
Level 8
Posts: 2040
Joined: Mon Nov 19, 2007 10:17 pm
Location: albuquerque

Re: Removing Older Kernels

Post by MALsPa »

I think you're right, linuxviolin.
Beardedragon

Re: Removing Older Kernels

Post 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.
User avatar
linuxviolin
Level 8
Level 8
Posts: 2081
Joined: Tue Feb 27, 2007 6:55 pm
Location: France

Re: Removing Older Kernels

Post 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
K.I.S.S. ===> "Keep It Simple, Stupid"
"Simplicity is the ultimate sophistication." (Leonardo da Vinci)
"Everything should be made as simple as possible, but no simpler." (Albert Einstein)
NewDisciple
Level 1
Level 1
Posts: 13
Joined: Tue Sep 14, 2010 11:52 pm
Location: Roseburg, Oregon

Re: Removing Older Kernels

Post 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.
Beardedragon

Re: Removing Older Kernels

Post 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:
Beardedragon

Re: Removing Older Kernels

Post 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)
NewDisciple
Level 1
Level 1
Posts: 13
Joined: Tue Sep 14, 2010 11:52 pm
Location: Roseburg, Oregon

Re: Removing Older Kernels (SOLVED)

Post 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.
Beardedragon

Re: Removing Older Kernels (SOLVED)

Post 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.
Brahim Salem

Re: Removing Older Kernels (SOLVED)

Post 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
Locked

Return to “Other topics”