Removing Older Kernels (SOLVED)
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
-
- Level 1
- Posts: 13
- Joined: Tue Sep 14, 2010 11:52 pm
- Location: Roseburg, Oregon
Removing Older Kernels (SOLVED)
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?
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.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Removing Older Kernels
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".
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
It also helps to run the following just to make sure before rebooting:
Code: Select all
sudo update-grub
Re: Removing Older Kernels
I use this approach, too. Then, the following before rebooting: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".
Beardedragon wrote:Code: Select all
sudo update-grub
- linuxviolin
- Level 8
- Posts: 2081
- Joined: Tue Feb 27, 2007 6:55 pm
- Location: France
Re: Removing Older Kernels
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...MALsPa wrote:I use this approach, too. Then, the following before rebooting: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".
Beardedragon wrote:Code: Select all
sudo update-grub
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)
"Simplicity is the ultimate sophistication." (Leonardo da Vinci)
"Everything should be made as simple as possible, but no simpler." (Albert Einstein)
Re: Removing Older Kernels
I think you're right, linuxviolin.
Re: Removing Older Kernels
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.MALsPa wrote:I think you're right, linuxviolin.
- linuxviolin
- Level 8
- Posts: 2081
- Joined: Tue Feb 27, 2007 6:55 pm
- Location: France
Re: Removing Older Kernels
Oh, because you have Windows 7... Sorry, I had not seen your signature.Beardedragon wrote:There have been cases where Windows 7 was not recognized just using Synaptic and the Command line for "update-grub" worked.
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)
"Simplicity is the ultimate sophistication." (Leonardo da Vinci)
"Everything should be made as simple as possible, but no simpler." (Albert Einstein)
-
- Level 1
- Posts: 13
- Joined: Tue Sep 14, 2010 11:52 pm
- Location: Roseburg, Oregon
Re: Removing Older Kernels
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.
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
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,linuxviolin wrote:Oh, because you have Windows 7... Sorry, I had not seen your signature.Beardedragon wrote:There have been cases where Windows 7 was not recognized just using Synaptic and the Command line for "update-grub" worked.
Re: Removing Older Kernels
@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)
-
- Level 1
- Posts: 13
- Joined: Tue Sep 14, 2010 11:52 pm
- Location: Roseburg, Oregon
Re: Removing Older Kernels (SOLVED)
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)
Welcome.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.
Re: Removing Older Kernels (SOLVED)
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!!
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
sudo apt-get --reinstall install grub2
then run: sudo update-grub
that's it!!
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