[SOLVED] purge-old-kernels removed in 19, autoremove not working

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Kudalufi
Level 2
Level 2
Posts: 67
Joined: Mon Nov 30, 2015 12:03 pm
Location: Halifax

[SOLVED] purge-old-kernels removed in 19, autoremove not working

Post by Kudalufi »

In Mint 19 the purge-old-kernels script, which was a fantastic way of pruning old kernels, was replaced and is basically just an alias now for apt-get autoremove. However, I am finding on my Mint 19 installation, that apt-get autoremove still completely fails to remove old kernels.

The purge-old-kernels script suggests reporting ongoing issues with apt-get autoremove not removing kernels to Ubuntu's apt bug list, but the bug associated with that was marked fixed and closed back in April.

Is this a left over artifact of my installation being one that was upgraded from 18, a mint-ism, or something that truly is wrong with apt? Are other mint users having this issue?

[edit] As noted in my final post, apt-get autoremove DOES work to remove old kernels. If you are upgrading from a previous mint version, though, it won't automatically remove any kernels which were installed prior to the upgrade. Once enough kernel upgrades (and manual removals of the old kernel) are performed that those are gone, apt-get autoremove will act to keep your current and one backup kernel installed.
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.
DAMIEN1307

Re: purge-old-kernels removed in 19, autoremove not working

Post by DAMIEN1307 »

i had to read this three or four times to figure out just what you were asking...first off, apt-get autoremove AKA sudo apt autoremove is not a kernel remover it removes the odd leftovers from things that have been removed from the system...kernels are manually removed from mint using the update manager, then click the "view" tab, then click on "linux kernels"...once that is showing, just click on the button marked as "remove" to remove any older unused kernel in the system...the kernel in use, of course, cannot be removed and always leave at least one kernel in there so in case you have a kernel failure in the one that is in use, you will have an older kernel to retreat back to...you can, of course, then use sudo apt autoremove to clean up any other residuals left over...im hoping a read and interpreted correctly what you were trying to say...the scripts listed below will also clean up things from old kernel removal as well as other odd bits of fluff...DAMIEN

Kernel and other Cleanups after Deletions/Removals/Purges

do these one at a time, dont worry if the first dpkg -l says error etc...just means nothing is there is all...

sudo apt autoremove

dpkg -l | grep '^rc' | awk '{print $2}' | sudo xargs dpkg --purge

dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo apt-get purge
User avatar
JOPETA
Level 17
Level 17
Posts: 7762
Joined: Thu Nov 20, 2014 6:10 am
Location: En un lugar de cuyo nombre no quiero acordarme

Re: purge-old-kernels removed in 19, autoremove not working

Post by JOPETA »

Maybe Kudalufi is talking about scripts (like this one) out there. I always unisntall old kernel as DAMIEN1307 said (i.e. in the graphical way) but Pjotr shows you what to do in his web.

In other hand Ubuntu's bugs reported you've linked are for a separated /boot partition and using unattended-upgrades .The problem is when filling that partition because of default /boot partition size. Autoremove do not uninstall old kernels in Mint (or Ubuntu, I think). Only a couple of packages are replaced and proposed to be auto-removed when installing a new kernel not the kernel itself. There is no purge-old-kernels included in any packages pre-installed in Mint. Any way such tools (as BleachBit) are not recommended.

(edited)
Last edited by JOPETA on Thu Sep 13, 2018 5:11 am, edited 3 times in total.
Ni cola de león ni cabeza de ratón, prefiero ser diente de ajo.(Javier Krahe)
User avatar
Pjotr
Level 24
Level 24
Posts: 20129
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: purge-old-kernels removed in 19, autoremove not working

Post by Pjotr »

JOPETA wrote: Thu Sep 13, 2018 4:15 am Pjotr shows you what to do on his website.
Yes, that kernel removal script still works fine. :)
JOPETA wrote: Thu Sep 13, 2018 4:15 am Any way such tools (as BleachBit) are not recommended.
I can't stress that fact enough.... Don't use software wrecking balls like BleachBit.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
gm10

Re: purge-old-kernels removed in 19, autoremove not working

Post by gm10 »

Kudalufi wrote: Wed Sep 12, 2018 8:10 pm In Mint 19 the purge-old-kernels script, which was a fantastic way of pruning old kernels, was replaced and is basically just an alias now for apt-get autoremove. However, I am finding on my Mint 19 installation, that apt-get autoremove still completely fails to remove old kernels.

The purge-old-kernels script suggests reporting ongoing issues with apt-get autoremove not removing kernels to Ubuntu's apt bug list, but the bug associated with that was marked fixed and closed back in April.

Is this a left over artifact of my installation being one that was upgraded from 18, a mint-ism, or something that truly is wrong with apt? Are other mint users having this issue?
Yes, it's an artifact. autoremove is specifically being blocked in Ubuntu from removing kernels. Ubuntu's apt version installs the script /etc/kernel/postinst.d/apt-auto-removal that ensures that you can never auto-remove them, even if you have them flagged as automatically installed (something that the Mint Update Manager does not necessarily do, anyway).

This "beautiful" one-liner will remove all your old kernels if you answer y when you run it:

Code: Select all

dpkg-query -W -f '${Version}\n' 'linux-image-[^g]*'|sort -u|sed -e '/^$/d' -e 's/\~[^~]*$//' -e 's/\.[^.]*$//' -e "/$(uname -r|sed 's/-generic//')/d" -e 's/.*/linux-*-&*/'|tr '\n' ' '|xargs -pr sudo apt-get remove --purge -y
I had posted a version that runs automatically every week here: viewtopic.php?f=47&t=275659&p=1514402#p1514402
User avatar
Pierre
Level 21
Level 21
Posts: 13224
Joined: Fri Sep 05, 2008 5:33 am
Location: Perth, AU.

Re: purge-old-kernels removed in 19, autoremove not working

Post by Pierre »

if don't have that script handy,
& you are still using an UN-modified version of the Boot Menu:
- you can select the Advanced Rescue option, from that Boot Menu
there is one for each Kernel . .
then select the Clean Option, from the GUI that then becomes available:
- this will remove some of those older kernels for you.

finally, just re-start your machine, as normal.
- this option is also good when you get that "Disk Full" or that "Disk is Nearly Full" error.
8)
Image
Please edit your original post title to include [SOLVED] - when your problem is solved!
and DO LOOK at those Unanswered Topics - - you may be able to answer some!.
User avatar
Kudalufi
Level 2
Level 2
Posts: 67
Joined: Mon Nov 30, 2015 12:03 pm
Location: Halifax

Re: purge-old-kernels removed in 19, autoremove not working

Post by Kudalufi »

DAMIEN1307 wrote: Wed Sep 12, 2018 8:41 pm i had to read this three or four times to figure out just what you were asking...first off, apt-get autoremove AKA sudo apt autoremove is not a kernel remover
I'm not an apt guru. What I know is this. There is a purge-old-kernels script as part of the byobu package. It worked fantastic - it would always remove all but the last N kernels, where N you could set. If you google removing old kernels, it is mentioned in several threads and blog entries. Unfortunately it was "updated" as part of Ubuntu 18.04 to remove all its functionality, and now just calls apt-get autoremove. Here are the comments now in the purge-old-kernels script:

# apt autoremove supposedly works correctly now.
#
# Thus, we're deprecating the functionality previously found
# in purge-old-kernels.
#
# If you still have old kernels lying around after this, please
# file a bug against apt: https://bugs.launchpad.net/ubuntu/+source/apt/+filebug

And it then proceeds to simply call apt-get autoremove.

If, as people suggest, apt-get autoremove isn't the way forward for removing old kernels, then perhaps Mint can bring back the old purge-old-kernels script, because it was fantastic one-stop-shopping. Getting into the weeds with:

Code: Select all

dpkg-query -W -f '${Version}\n' 'linux-image-[^g]*'|sort -u|sed -e '/^$/d' -e 's/\~[^~]*$//' -e 's/\.[^.]*$//' -e "/$(uname -r|sed 's/-generic//')/d" -e 's/.*/linux-*-&*/'|tr '\n' ' '|xargs -pr sudo apt-get remove --purge -y
Just to make room in /boot is ludicrous. Ten years ago I'd have loved it, and patted myself on the back for my ingenuity. But 10 years ago I got into the weeds for a living. Today I really just want it to work - as in if it's as complex as above, then it should be in a script that should be an apt-get away, like it was with purge-old-kernels before.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: purge-old-kernels removed in 19, autoremove not working

Post by MrEen »

I believe that when byobu dropped this feature, that's when Pjotr picked up this one piece of it.

I've used it. It works. Go get it! Link is up there somewhere ^^^^^^ (And here as well)
RR245

Re: purge-old-kernels removed in 19, autoremove not working

Post by RR245 »

Kudalufi wrote: Wed Sep 12, 2018 8:10 pm The purge-old-kernels script suggests reporting ongoing issues with apt-get autoremove not removing kernels to Ubuntu's apt bug list, but the bug associated with that was marked fixed and closed back in April.
But this bugreport is about the package unattended-upgrades :shock: That's something completely different. And furthermore the very special case »when /boot partition gets full«. :roll:

I prefer a script (found in a german forum; but it is also in english) which let me select the kernels I want to purge
https://www.linuxmintusers.de/index.php?topic=46778
sleeper12
Level 21
Level 21
Posts: 14607
Joined: Thu May 25, 2017 3:22 pm

Re: purge-old-kernels removed in 19, autoremove not working

Post by sleeper12 »

I use ucaresystem-core on Mint 18 and it works well. Not sure about Mint 19, but might be worth a try:
https://www.linux.com/learn/intro-to-li ... ystem-core
User avatar
Kudalufi
Level 2
Level 2
Posts: 67
Joined: Mon Nov 30, 2015 12:03 pm
Location: Halifax

Re: purge-old-kernels removed in 19, autoremove not working

Post by Kudalufi »

Actually, apt-get autoremove does work to remove old kernels. The problem was that it wouldn't automatically remove any kernels which had been installed prior to the Mint 19 upgrade. Once enough kernel upgrades were performed post upgrade that all the pre-upgrade kernels were gone (manually removed), then apt-get autoremove began to work automatically to remove old kernels. It's actually quite nice, seeing as my /boot folder is quite limited in size.
gm10

Re: purge-old-kernels removed in 19, autoremove not working

Post by gm10 »

Kudalufi wrote: Sun Dec 09, 2018 9:22 pm Actually, apt-get autoremove does work to remove old kernels. The problem was that it wouldn't automatically remove any kernels which had been installed prior to the Mint 19 upgrade. Once enough kernel upgrades were performed post upgrade that all the pre-upgrade kernels were gone (manually removed), then apt-get autoremove began to work automatically to remove old kernels. It's actually quite nice, seeing as my /boot folder is quite limited in size.
Depends how you install them, it will only remove those that were automatically updated via the kernel meta package. I patched up Update Manager for LM 19.1 to make that the default procedure now. That also means that you won't automatically get upgraded to HWE kernels anymore without asking for it. Kernels you manually installed via Update Manager > View > Linux kernels (or any other way) still won't get autoremoved.
Locked

Return to “Installation & Boot”