SOLVED>How To Remove Old Kernels in Kubuntu 20.04 KDE

Alexzee

Well-Known Member
Joined
Jun 1, 2019
Messages
3,736
Reaction score
2,008
Credits
22,304
Hey guys-:)

My best mate is running Kubuntu 20.04 KDE on his custom built 64-bit desktop and has a lot of kernels that are old.

I did a few searches but I'm not convinced that "sudo apt --purge autoremove" is the cure all.

I looked here but I don't know how old this is?

Is there a prefered way to do this w/o removing the current kernel that's in use?
 


Then you can remove the old configuration files as well
Code:
dpkg --list |grep "^rc"
Code:
dpkg --list |grep "^rc" |cut -d " " -f3
Code:
dpkg --list |grep "^rc" |cut -d " " -f3 |xargs sudo dpkg --purge
forgot that bit earlier
 
Thanks guys!

I'll have my friend run those cmd's and let you know how it goes.
 
Tried sudo apt --purge autoremove on my Debian system.
It worked fine.
Ran the other cmd's too!

For some reason I still have some old kernel config's hanging around in /boot/:

config-4.19.0-14-amd64 initrd.img-4.19.0-16-amd64 vmlinuz-4.19.0-14-amd64
config-4.19.0-16-amd64 initrd.img-4.19.0-17-amd64 vmlinuz-4.19.0-16-amd64
config-4.19.0-17-amd64 System.map-4.19.0-14-amd64 vmlinuz-4.19.0-17-amd64
grub System.map-4.19.0-16-amd64
initrd.img-4.19.0-14-amd64 System.map-4.19.0-17-amd64

Any idea why?
 
Tried sudo apt --purge autoremove on my Debian system.
It worked fine.
Ran the other cmd's too!

For some reason I still have some old kernel config's hanging around in /boot/:

config-4.19.0-14-amd64 initrd.img-4.19.0-16-amd64 vmlinuz-4.19.0-14-amd64
config-4.19.0-16-amd64 initrd.img-4.19.0-17-amd64 vmlinuz-4.19.0-16-amd64
config-4.19.0-17-amd64 System.map-4.19.0-14-amd64 vmlinuz-4.19.0-17-amd64
grub System.map-4.19.0-16-amd64
initrd.img-4.19.0-14-amd64 System.map-4.19.0-17-amd64

Any idea why?
after you ran the code I posted in Post #4 did you run sudo update-grub afterwards
 
after you ran the code I posted in Post #4 did you run sudo update-grub afterwards
No I didn't update Grub afterwards....so I just ran it now and than ran your cmd's.

dpkg --list |grep "^rc"
@debian:~$ dpkg --list |grep "^rc" |cut -d " " -f3
@debian:~$ dpkg --list |grep "^rc" |cut -d " " -f3 |xargs sudo dpkg --purge
dpkg: error: --purge needs at least one package name argument

Type dpkg --help for help about installing and deinstalling packages [*];
Use 'apt' or 'aptitude' for user-friendly package management;
Type dpkg -Dhelp for a list of dpkg debug flag values;
Type dpkg --force-help for a list of forcing options;
Type dpkg-deb --help for help about manipulating *.deb files;

Options marked [*] produce a lot of output - pipe it through 'less' or 'more'
 
Last edited:
I think
Code:
dpkg --list | grep linux-image
to get a list of the kernel "rc" leftovers, and then using that list run
Code:
sudo apt --purge autoremove linux-image-version.arch
will do. I just went into this yesterday in KDE Neon Testing, and was able to get rid of those old kernels as well as any configuration files.
Hope this helps! :)
 
Do you get an output from the first line of code
Code:
dpkg --list |grep "^rc"
If you do not get any output the there are no left over files to purge
so the second and third commands won't do anything hence the error, the second command "cut" them the third purges them
 
Do you get an output from the first line of code
Code:
dpkg --list |grep "^rc"
If you do not get any output the there are no left over files to purge
so the second and third commands won't do anything hence the error, the second command "cut" them the third purges them
I'm not on that machine right now.

I'll run the first line of code and post it in a little while.
I'm waiting for the laptop to charge up before I fire up the desktop.

Is this how I would get rid of the old 4.19.0-14- kernel like this?
sudo apt --purge autoremove 4.19.0-14
 
Here is step-by-step easy way
1)
Code:
dpkg --list |grep linux-image
this will show all your installed kernels
2)
Code:
sudo dpkg --purge autoremove linux-image-4.19.0-14-generic
just change the 4.19.0-14 to the number of the kernel you want to remove - do this for each of the old kernels you want to get rid of - once you are finished removing all old kernels
3)
Code:
dpkg --list |grep "^rc"
this will check for any left over configuration files if it shows any you will need to run the following 2 commands
4)
Code:
dpkg --list |grep "^rc" |cut -d " " -f3
5)
Code:
dpkg --list |grep "^rc" |cut -d " " -f3 |xargs sudo dpkg --purge
once that is done run
6)
Code:
 sudo update-grub
and
Code:
sudo update-initramfs -u
reboot and when it boots back up run
step 1 again to verify kernels were removed and
Code:
uname -r
to see what is currently running
just do not remove the kernel you are currently using
 
Last edited by a moderator:
Is this how I would get rid of the old 4.19.0-14- kernel like this?
sudo apt --purge autoremove 4.19.0-14
No quite, the correct way would be
Code:
sudo apt --purge autoremove linux-image-4.19.0-14-amd64
EDIT: Ah, this is on Kubuntu, right? So you might need to change amd64 for generic
 
Here is step-by-step easy way
1)
Code:
dpkg --list |grep linux-image
this will show all your installed kernels
2)
Code:
sudo dpkg --purge autoremove linux-image-4.19.0-14-generic
just change the 4.19.0-14 to the number of the kernel you want to remove - do this for each of the old kernels you want to get rid of - once you are finished removing all old kernels
3)
Code:
dpkg --list |grep "^rc"
this will check for any left over configuration files if it shows any you will need to run the following 2 commands
4)
Code:
dpkg --list |grep "^rc" |cut -d " " -f3
5)
Code:
dpkg --list |grep "^rc" |cut -d " " -f3 |xargs sudo dpkg --purge
once that is done run
6)
Code:
 sudo update-grub
and
Code:
sudo update-initramfs -u
reboot and when it boots back up run
step 1 again to verify kernels were removed and
Code:
uname -r
to see what is currently running
just do not remove the kernel you are currently using

Got it thanks man!
 
No quite, the correct way would be
Code:
sudo apt --purge autoremove linux-image-4.19.0-14-amd64
EDIT: Ah, this is on Kubuntu, right? So you might need to change amd64 for generic
Yeah, it's Kubuntu KDE.
I'll look in ls /boot/ to see if the kernel is listed as amd64 or generic
Thank you.
 
Yeah, it's Kubuntu KDE.
I'll look in ls /boot/ to see if the kernel is listed as amd64 or generic
Thank you.
the 1) command in my list will tell you here is mine below
----------------------------------------------------------------------
@expirion:~$ dpkg --list |grep linux-image
ii linux-image-5.11.0-27-generic 5.11.0-27.29~20.04.1 amd64 Signed kernel image generic
-------------------------------------------------------------
As you can see I only have the one kernel you do not need to look in boot
 
the 1) command in my list will tell you here is mine below
----------------------------------------------------------------------
@expirion:~$ dpkg --list |grep linux-image
ii linux-image-5.11.0-27-generic 5.11.0-27.29~20.04.1 amd64 Signed kernel image generic
-------------------------------------------------------------
As you can see I only have the one kernel you do not need to look in boot

Ok, got it.
Headed to my friends computer now to follow the steps in post # 13.
 
Those instructions served my best mate well.
He says: thanks!

The only kernels in the list now are the current one and the new one.
 


Top