Linux Mint leaves a lot of cruft

It doesn’t know to clean up behind itself. I had 7 kernels floating around, eating up over 1.5GB of disk space on a 92GB ssd (yes, old computer).

I had to do various things in order to get rid of the old kernels. And then there were some remnants of old kernels, which I needed to get rid of using sudo rm -rf.

Now, in general I know what I am doing, but using sudo rm -rf is not my idea of safe system administration. Why doesn’t Mint clean up the old kernel module trees accordingly with apt purge?

Void does the same, but it has a special command vkpurge to safely remove kernels.

If you remove a kernel, you need to rerun update-grub to ensure grub does not try to boot a kernel that is no longer there.

Gentoo keeps all its kernels too, as source code, , but its package management system will remove them if you tell it to. Gentoo downloads the source of new kernels, but leaves to to the user to say when to compile and install them.

I will have a look at Mint, as I hzve a copy running at the moment. They may have some
special utilities to deal with kernels. It is not like Mint to just neglect something.

It is a good idea to keep more than one kernel, in case the newone has a problem.

3 Likes

Red Hat family distros have a command you run after patching, to remove all but the last, but one, kernels from /boot… Can’t remember the exact syntax, I have it documented in a template I use to log change request tickets when patching…

Here it is :

package-cleanup --oldkernels --count=2

(but I think it set it at “1” - i.e. it keeps the current, and the previous 1)

I don’t usually need to bother doing anything like that with Ubuntu or Pop!_OS - cause most of my personal stuff is lucky to last 12 months before I’m reformatting and re-installing…

I guess I should do some housekeeping, 'cause I’ve got SBC Linux PCs (e.g. Pi) that I keep running for years…

Always useful - but it’s not a DR solution - I’ve witnessed some numpties who used manual intervention at the bootloader to select the previous kernel as the new one created kernel panics… I had no control over this - and none of them could explain why they didn’t just completely utterly backout the change to a rollback point (VMware snapshot). I suspect one of these numpties maybe missed that step??? Some genius also decided it was a good idea to patch the O/S, and upgrade some fairly low level software in the same change window…

3 Likes

Hi @xahodo,

I believe ‘sudo apt autoremove’ will purge old kernels. I also found this on the web;
“You can remove old kernels with a simple autoremove command in a terminal:
sudo apt-get autoremove --purge”
I will paste part of the last autoremove I ran. It also auto runs grub.


Removing libxrandr2:i386 (2:1.5.2-1build1) …
Removing libxrender1:i386 (1:0.9.10-1build4) …
Removing linux-headers-5.15.0-73-generic (5.15.0-73.80) …
Removing linux-headers-5.15.0-73 (5.15.0-73.80) …
Removing linux-modules-extra-5.15.0-73-generic (5.15.0-73.80) …
Removing xsltproc (1.1.34-4ubuntu0.22.04.1) …
Removing linux-image-5.15.0-73-generic (5.15.0-73.80) …
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.15.0-73-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file /etc/default/grub' Sourcing file /etc/default/grub.d/50_linuxmint.cfg’
Sourcing file `/etc/default/grub.d/init-select.cfg’
Generating grub configuration file …
Found linux image: /boot/vmlinuz-5.15.0-76-generic
Found initrd image: /boot/initrd.img-5.15.0-76-generic
Found linux image: /boot/vmlinuz-5.15.0-75-generic
Found initrd image: /boot/initrd.img-5.15.0-75-generic
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot
entries.
Found MX 21.3 Wildflower (21.3) on /dev/sda6
done
Removing linux-modules-5.15.0-73-generic (5.15.0-73.80) …


3 Likes

This is what I do each time I update except using apt instead of apt-get. There is a setting somewhere to manage how many old kernels are kept. Not sure where that is at the moment.

2 Likes

That would seem to be the perfect solution for Debian based systems.

2 Likes

In Linux Mint open update manager and click on view tab. Near the bottom of the list is Kernels, click on it a sign will come up warning you about installing or removing kernels. Click onto the ones that you do not need anymore, then left click uninstall, pop your password in and it’ll get rid of it, automatically updating your grub too.

4 Likes

Linux Mint 21.1 Cinnamon
As a newbie to writing Bash scripts, I wanted a single command that I could run and streamline all the updating and cleanup that I used to run ‘by hand’. Below is what I came up with. I prefixed all the little aliases with “J” because my first name is Jim and I wanted something easy to remember for my feeble mind. Now, I open a terminal and run “jall” which includes all of the commands that I used to run manually.
I’d be grateful for any corrections, comments or suggestions to my attempt. I inserted this code by copying and pasting directly into .bashrc rather than reading all about aliases and creating a seperate file - just lazy. There’s a lot of extra unnecessary code that adds color to the comments as jall runs.
Best, Jim
(Couldn’t figure out how to attach this as a text document so, here it is.)
#**************************************************************************

Jim’s custom aliases - edit with gedit ~/.bashrc (jma alias)

#**************************************************************************

alias jda=“cat ‘Jims Custom Aliases.txt’” # Jims Custom Aliases Display - jda

alias jch=“history -c && history -w” # Jims clear bash history - jch

Jims update/upgrade -y - juu

#alias juu="echo ‘*****************’ && echo ’ Updating and Upgrading…’
alias juu=“echo -e ‘$EINS \033[1;33m\033[40m *** Updating and Upgrading… \033[0m’ && sudo apt update && sudo apt upgrade -y”

Jims flatpak update -y - jfu

sudo flatpak update -y

alias jfu=“echo -e ‘$EINS \033[1;33m\033[40m *** Flatpak update… \033[0m’ && sudo flatpak update -y”

alias jju=“journalctl --disk-usage” # Jims journal usage - jju

Jims journal clean - jjc

alias jjc=“echo -e ‘$EINS \033[1;33m\033[40m *** Clean journal… \033[0m’ && sudo journalctl --vacuum-time=3d”

alias jcd=“du -sh ~/.cache/thumbnails” # Jims cache display - jcd

Jims cache cleanup - jcc

alias jcc=“echo -e ‘$EINS \033[1;33m\033[40m *** Clean cache… \033[0m’ && rm -rf ~/.cache/thumbnails/*”

Jims autoremove -y - jar

alias jar=“echo -e ‘$EINS \033[1;33m\033[40m *** autoremove \033[0m’ && sudo apt autoremove -y”

Jims autoclean - jac

alias jac=“echo -e ‘$EINS \033[1;33m\033[40m *** autoclean \033[0m’ && sudo apt autoclean”

Jims update db for mlocate - jud

alias jud=“echo -e ‘$EINS \033[1;33m\033[40m *** Update database… \033[0m’ && sudo updatedb”

Jims fix broken packages - jfb

alias jfb=“echo -e ‘$EINS \033[1;33m\033[40m *** Fix broken packages… \033[0m’ && sudo apt-get -f install”

Jims fix configuration - jfc

alias jfc=“echo -e ‘$EINS \033[1;33m\033[40m *** Fix configuration… \033[0m’ && sudo dpkg --configure -a”

Jims check rootkit -q - jroot

alias jroot="echo -e '$EINS \033[1;33m\033[40m ‘********************’ && echo -e ‘$EINS \033[1;33m\033[40m *** Check rootkit… \033[0m’ \

sudo chkrootkit -q"

alias jroot=“echo -e ‘$EINS \033[1;33m\033[40m *** Check rootkit… \033[0m’ && sudo chkrootkit -q”

Jims safe-upgrade - jsu

sudo aptitude safe-upgrade -y

alias jsu=“echo -e ‘$EINS \033[1;33m\033[40m *** Aptitude safe-upgrade… \033[0m’ && sudo aptitude safe-upgrade -y”

Jims save softs.list - jsl

sudo dpkg --get-selections | grep -v deinstall >softs.list

alias jsl=“echo -e ‘$EINS \033[1;33m\033[40m *** Save softs.list… \033[0m’ && sudo dpkg --get-selections | grep -v deinstall >softs.list”

alias jall=“juu && jfu && jsu && jjc && jcc && jfb && jfc && jar && jac && jroot && jud && jsl” # - jall

alias jma=“gedit ~/.bashrc” # Jims maintain aliases - jma
#**************************************************************************

3 Likes

Hi Jim,
It is impressive.
I am not a great fan of aliases, but I have to admit the way you have designed that
is both clever and very usable.
Regards
Neville

2 Likes

Thanks Neville!
I’m really new to writing any kind of commands but this has been working well for mine and my wife’s computers for awhile now. I have to do the maintenance type stuff on hers and it took quite awhile to convince her that she didn’t need Windoze anymore. She’s very satisfied with Linux Mint and, after buying herself a brand new laptop, had me step on Windoze and install Linux for her.
I’m certainly open to suggestions on improving or correcting the stuff I put together.
Appreciate you taking the time to look at it.
Best, Jim

2 Likes

Hi Jim,
I was trying to upload a text document too… could not get it to work.
I ended up copy/paste the document into the itsFOSS editor.
Is that what you did?
Did you use markdown for that document, or is it just literal text?

I like the color codes. You put a lt of effort into that

Regards
Neville

Hi Neville,
It’s just a text document that I edit with XED or Gedit.
I’m pretty sure that I saw the color coding on ITSFOSS. I use a black background on my terminal screen so I don’t know how it looks with other backgrounds.
Best,
Jim

I am curious, how did you get the bold headings in a text document?
It comes out really well formatted.

You are right, the only way to read it in is with copy/paste… there is no upload button for text.
I have been using markdown to do the same thing. The itsFOSS editor understands markdown.

2 Likes

Thanks Red Hat! NOT!

That worked on REL5, 6 and 7, but just for shits n giggles Red Hat decided to remove that and change the procedure format and command - it’s now :

yum remove $(yum repoquery --installonly --latest-limit=-2 -q)

And this is despite Red Hat trying to move everyone onto dnf instead of yum (that’s a pretty ominous acronym - nearly every where in the Anglosphere “dnf” stands for Did Not Finish).

3 Likes

Hi Neville,
Sorry I didn’t see this earlier…
I didn’t put the bold headings in with XED or Gedit. I don’t know how to do that either. I did them after I pasted the plain text into the ITSFOSS text box for posting using the “B” option on top. :slight_smile:

2 Likes

Thanks Jim,
Interesting.
Since then , I have been practising with markdown.
It can do headings and bold, and you can copy/paste a markdown file into the FOSS textbox.
There is always more than one way to do things
Cheers
Neville

Thank you Neville!
I had never heard of Markdown. Learn something new everyday - and especially with the help of ITSFOSS users/contributors. :wink:
As a computer dinosaur, it feels good to try the new things I hear about on this forum.
Best, Jim

Look up markdown…

It is useful. You can copy a markdown doc into the FOSS
edit screen

2 Likes

Hi Jim,
In this link, one of many, you can see the markdown syntax:
Markdown syntax

Jorge

1 Like

Thanks Jorge!

1 Like