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 please read this

Removing Older Kernels (SOLVED)

Postby NewDisciple on Wed Apr 13, 2011 1:04 pm

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/automatically-remove-old-kernels-from-debian-based-distributions/ 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/1357-remove-all-unused-kernels-with-1-command-in-debian-based-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 NewDisciple on Wed Apr 13, 2011 7:48 pm, edited 1 time in total.
NewDisciple
Level 1
Level 1
 
Posts: 9
Joined: Tue Sep 14, 2010 11:52 pm
Location: Roseburg, Oregon

Linux Mint is funded by ads and donations.
 

Re: Removing Older Kernels

Postby viking777 on Wed Apr 13, 2011 1:31 pm

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".
Fujitsu Lifebook AH532. Intel i5 processor, 6Gb ram, Intel HD3000 graphics, Intel Audio/wifi. Realtek RTL8111/8168B Ethernet.Lubuntu 13.10,Ubuntu12.10 (Unity), Mint16 (Cinnamon), Manjaro (Xfce).
Image
User avatar
viking777
Level 14
Level 14
 
Posts: 5153
Joined: Mon Dec 01, 2008 11:21 am

Re: Removing Older Kernels

Postby Beardedragon on Wed Apr 13, 2011 3:06 pm

It also helps to run the following just to make sure before rebooting:
Code: Select all
sudo update-grub
Robert Collard, Madison, WI
HP s5710f, 2x AMD Athlon II 260@3.2Ghz, 3GB RAM, 640GB HD
Debian 7.1 Wheezy 3,2,0-4 Xfce 4.10 AMD-64
LMDE 3.10.5-1 Xfce 4.10 AMD-64
SalineOS 2.0 3.2.0-4 Xfce 4.8 AMD64
User avatar
Beardedragon
Level 4
Level 4
 
Posts: 346
Joined: Sat Jan 29, 2011 3:37 am

Re: Removing Older Kernels

Postby MALsPa on Wed Apr 13, 2011 3:47 pm

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
MALsPa
Level 8
Level 8
 
Posts: 2030
Joined: Mon Nov 19, 2007 10:17 pm
Location: albuquerque

Re: Removing Older Kernels

Postby linuxviolin on Wed Apr 13, 2011 4:42 pm

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

Re: Removing Older Kernels

Postby MALsPa on Wed Apr 13, 2011 5:15 pm

I think you're right, linuxviolin.
User avatar
MALsPa
Level 8
Level 8
 
Posts: 2030
Joined: Mon Nov 19, 2007 10:17 pm
Location: albuquerque

Re: Removing Older Kernels

Postby Beardedragon on Wed Apr 13, 2011 5:53 pm

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.
Robert Collard, Madison, WI
HP s5710f, 2x AMD Athlon II 260@3.2Ghz, 3GB RAM, 640GB HD
Debian 7.1 Wheezy 3,2,0-4 Xfce 4.10 AMD-64
LMDE 3.10.5-1 Xfce 4.10 AMD-64
SalineOS 2.0 3.2.0-4 Xfce 4.8 AMD64
User avatar
Beardedragon
Level 4
Level 4
 
Posts: 346
Joined: Sat Jan 29, 2011 3:37 am

Re: Removing Older Kernels

Postby linuxviolin on Wed Apr 13, 2011 6:37 pm

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

Re: Removing Older Kernels

Postby NewDisciple on Wed Apr 13, 2011 6:37 pm

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-linux-image-2-6-32-5-amd64-removal-fails-clean-chroot-help-200881891.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.
NewDisciple
Level 1
Level 1
 
Posts: 9
Joined: Tue Sep 14, 2010 11:52 pm
Location: Roseburg, Oregon

Re: Removing Older Kernels

Postby Beardedragon on Wed Apr 13, 2011 7:05 pm

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:
Robert Collard, Madison, WI
HP s5710f, 2x AMD Athlon II 260@3.2Ghz, 3GB RAM, 640GB HD
Debian 7.1 Wheezy 3,2,0-4 Xfce 4.10 AMD-64
LMDE 3.10.5-1 Xfce 4.10 AMD-64
SalineOS 2.0 3.2.0-4 Xfce 4.8 AMD64
User avatar
Beardedragon
Level 4
Level 4
 
Posts: 346
Joined: Sat Jan 29, 2011 3:37 am

Re: Removing Older Kernels

Postby Beardedragon on Wed Apr 13, 2011 7:09 pm

@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)
Robert Collard, Madison, WI
HP s5710f, 2x AMD Athlon II 260@3.2Ghz, 3GB RAM, 640GB HD
Debian 7.1 Wheezy 3,2,0-4 Xfce 4.10 AMD-64
LMDE 3.10.5-1 Xfce 4.10 AMD-64
SalineOS 2.0 3.2.0-4 Xfce 4.8 AMD64
User avatar
Beardedragon
Level 4
Level 4
 
Posts: 346
Joined: Sat Jan 29, 2011 3:37 am

Re: Removing Older Kernels (SOLVED)

Postby NewDisciple on Wed Apr 13, 2011 7:47 pm

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

Re: Removing Older Kernels (SOLVED)

Postby Beardedragon on Wed Apr 13, 2011 9:01 pm

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.
Robert Collard, Madison, WI
HP s5710f, 2x AMD Athlon II 260@3.2Ghz, 3GB RAM, 640GB HD
Debian 7.1 Wheezy 3,2,0-4 Xfce 4.10 AMD-64
LMDE 3.10.5-1 Xfce 4.10 AMD-64
SalineOS 2.0 3.2.0-4 Xfce 4.8 AMD64
User avatar
Beardedragon
Level 4
Level 4
 
Posts: 346
Joined: Sat Jan 29, 2011 3:37 am

Re: Removing Older Kernels (SOLVED)

Postby Zorba on Thu Nov 29, 2012 4:29 pm

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
Image
User avatar
Zorba
Level 8
Level 8
 
Posts: 2308
Joined: Tue May 29, 2012 10:12 pm
Location: Tunisia

Linux Mint is funded by ads and donations.
 

Return to Other topics

Who is online

Users browsing this forum: No registered users and 5 guests