[clug] [anne.a.gunn at gmail.com: Ubuntu problem] -> removing older kernels

Scott Ferguson scott.ferguson.clug at gmail.com
Fri Aug 14 14:22:15 UTC 2015


Perhaps you are trying to solve a problem that does not exist?

What is the output of:-
dpkg --get-selections | grep 'linux-image\|linux-headers'


On 14/08/15 23:02, Bryan Kilgallin wrote:
> Scott:
> 
>>>> removed 8! older kernels and header packages ('that' trimmed
>>>> the GRUB menu)
>>> How do you do that safely?
>> Slight correction (I failed to scroll right in my notes). 21
>> kernels and header packages.
>> 
>> determined the kernel in use e.g.:- uname -r
> 
> That reported "3.13.0-61-generic".
> 
>> 3.16.0-0.bpo.4-686-pae
>> 
>> confirmed that the kernel functioned properly
>> 
>> listed all the kernels and kernel header that were installed,
>> except what was relevant to the kernel in use, and removed them:- 
>> apt-get -s remove `dpkg --get-selections|grep 
>> 'linux-image\|linux-headers'|grep -v 3.16` | more
> 
> So at a bash prompt, I entered the following line. sudo apt-get -s
> remove `dpkg --get-selections|grep 'linux-image\|linux-headers'|grep
> -v 3.13.0-61-generic` | more

should have been:-
sudo apt-get -s remove `dpkg --get-selections|grep
'linux-image\|linux-headers'|grep -v 3.13.0-61-generic` | cut -f1

note the cut
more importantly - you should only do that if you don't want the header
and image packages installed

e.g. you may have a later kernel than 3.16 installed and working, just
not in use. The solution I applied was to a specific problem - 21
kernels installed which used a lot of space on a small boot partition.
Removing them was part of a process to speed up the boot, reclaiming
disk space, and reducing updates.

If you have two kernels installed it makes sense to keep both until you
are certain that the earlier version is no longer needed. In the
specific case GRUB had a 10 second delay and there was only one OS
installed so the delay was set to 0 - that would not be always be a good
idea (you need to keep hitting the arrow down to enter the GRUB menu
when delay is set to 0).

tl:dr?
There was a compelling reason to remove the proven unnecessary packages
*and* there was a backup.

> 
> Which responded as follows.
> 
> Reading package lists... Building dependency tree... Reading state
> information... E: Unable to locate package install E: Unable to
> locate package install E: Unable to locate package install E: Unable
> to locate package install E: Unable to locate package install E:
> Unable to locate package install E: Unable to locate package install 
> E: Unable to locate package install E: Unable to locate package
> install E: Unable to locate package install E: Unable to locate
> package install
> 
>> If the projected results look fine, rerun the command but replace
>> "-s" with "--purge -y", and also remove the "| more".
> 
> That didn't look fine to me. What went wrong?

no "cut" on the output of dpkg --get-selections so you got (e.g.):-
linux-headers-3.16.0-0.bpo.4-686-pae            install
linux-headers-3.16.0-0.bpo.4-common             install

instead of:-
linux-headers-3.16.0-0.bpo.4-686-pae
linux-headers-3.16.0-0.bpo.4-common

If you only have a couple of packages to remove do them manually - no
need to take risks with my scripting (they won't save much time either).


Kind regards



More information about the linux mailing list