How to remove old unneeded kernels

How to remove old unneeded kernelsThe kernel of the system is periodically updated and is good. But the system eventually clogged the old kernels, and this is bad.Previously, for these purposes I used the excellent utility KERNELS in the update manager of Linux Mint, I decided to find other solutions.
As always in Linux there are several solutions to the same problem.
In this small article I will show you how you can remove old kernels in Linux Mint in various ways.
Way 1.
You can remove the old core system with a single command in the Terminal. You need to do the following:

sudo apt purge $(dpkg -l ‘linux-*’ | sed ‘/^ii/!d;/'”$(uname -r | sed “s/\\(.*\\)-\\([^0-9]\\+\\)/\\1/”)”‘/d;s/^[^ ]* [^ ]* \\([^ ]*\\).*/\\1/;/[0-9]/!d’ | head -n -1)
and then run:
sudo apt autoremove && sudo update-grub
Way 2.
You can use the excellent Synaptic package manager. Run the program, click the Search button and enter query – linux-image
How to remove old unneeded kernelsNow we need to sort the list by the first column. To do this, click on the first column, thus first appeared on the list of installed packages that will be highlighted in green.
I recommend to keep the latest and previous version of the kernel, and all the rest can be safely deleted. To do this select the old versions of packages linux-image-X. X. x-generic, linux-headers-X. X. x, linux-headers-X. X. x-generic, clicking with the right mouse button and selecting “Mark for complete removal”, and then click Apply.
The system grub will be updated automatically.
How to remove old unneeded kernelsMay the Force be with you,
Good Luck!!!

Share to friends
Rate author
( 1 assessment, average 1 from 5 )
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Phil Headford
Phil Headford
1 year ago

Fine, clear writing. And a great webpage.
I needed to back out of Mint 20, probably because of non-standard hardware, so that I could do some preparation and then try Mint 20 afresh.
The Synaptic method allowed me to remove kernel 5.x.x entries from the grub menu and save me key-presses into a safe boot.