Page 1 of 2

Clean old folders in /usr/lib/modules?

Posted: Thu Jul 25, 2024 8:56 pm
by RallyDarkstrike
Hi all - doing some cleaning on my little HP Stream laptop and found something I'm curious about.

My Stream is a cheap little laptop and only has 32BG eMMC storage. I do have a 256GB MicroSD card installed in it as well. How I have it set up is that my OS (MX Linux 23.3 XFCE) and apps are installed to the eMMC and my Home folder is set as the MicroSD card.

Currently I only have 9.94GB left of free space on the eMMC so I was looking to eek back a little bit more room. In my looking around with K4DirStat, I see under the /usr/lib/modules that I have folders going back for ages from a bunch of old Kernel versions that I no longer have (some say the 'last change' was 2022!).

Would it be safe to remove these older folders to get a little space back?

I would obviously not touch the folders for my current or last kernel.

Thanks so much! :)

Re: Clean old folders in /usr/lib/modules?

Posted: Thu Jul 25, 2024 9:00 pm
by dolphin_oracle
yes, probably.

using "apt purge" along with the kernel package name should also clear those out, assuming you haven't cleared out the cache files that point to those package info. but deleting manually should be safe as long as its not a kernel that is currently installed.

Re: Clean old folders in /usr/lib/modules?

Posted: Thu Jul 25, 2024 9:52 pm
by RallyDarkstrike
dolphin_oracle wrote: Thu Jul 25, 2024 9:00 pm yes, probably.

using "apt purge" along with the kernel package name should also clear those out, assuming you haven't cleared out the cache files that point to those package info. but deleting manually should be safe as long as its not a kernel that is currently installed.
Awesome, thanks for the quick reply! Unrelated...but also related in the 'getting-more-space-back-on-a-small-hard-drive' theme......I've noticed there are 1.3GB of space being taken up by /var/cache/apt/archives......some cursory research online suggests it's safe to delete most of these as well? (Most are dated as being from over 1 or 2 years ago!)

Re: Clean old folders in /usr/lib/modules?

Posted: Thu Jul 25, 2024 10:32 pm
by Buck Fankers
RallyDarkstrike wrote: Thu Jul 25, 2024 9:52 pm
Unrelated...but also related in the 'getting-more-space-back-on-a-small-hard-drive' theme......I've noticed there are 1.3GB of space being taken up by /var/cache/apt/archives......some cursory research online suggests it's safe to delete most of these as well? (Most are dated as being from over 1 or 2 years ago!)
I think, those may be APT cache files?
Old files that were used to update the system.

Anyway, I will suggest again ;) very nice MX tool called MX Cleanup.
With it, you can safely remove old APT cache files (Clear APT Cache) and some other stuff.

I had one Eee 32GB laptop and I hear your pain...

One more thing. Usually, I would not recommend bleach-bite, (hmm did I write name correctly?) this thing can sometimes go too deep and can potentially cause some problems. (I remember reading some on this topic) but there is one nice feature, wity this cleaning program, you can easily remove all locale files for all languages but the ones you are using. There are lots of those files (tens of thousands or hundreds of thousands?). While they are small, they do add up. Unfortunately it was few years ago, when I did this, so I can't give you detailed steps. Hope someone who knows, read this and post steps. Or see if you can find some YT video about it.

Re: Clean old folders in /usr/lib/modules?

Posted: Thu Jul 25, 2024 10:47 pm
by figueroa
You have 9.94GB remaining? You're never going to fill that up.

Re: Clean old folders in /usr/lib/modules?

Posted: Thu Jul 25, 2024 11:24 pm
by MXRobo
MX Cleanup set weekly or monthly.
Approx: 32 GB – 10 = 22
80% rule of 32 ~ 25.5, so only 3.5 GB useful?
90% ~ 7 GB useful.

Re: Clean old folders in /usr/lib/modules?

Posted: Fri Jul 26, 2024 6:15 am
by Stuart_M
RallyDarkstrike wrote: Thu Jul 25, 2024 9:52 pm ...
I've noticed there are 1.3GB of space being taken up by /var/cache/apt/archives......some cursory research online suggests it's safe to delete most of these as well?
...
It is completely safe to clear the cache created by apt. /var/cache/apt/archives/ can easily accumulate to well over a gigabyte of now "useless" (see below) files. I always check that location before making any Snapshots to ensure that it is empty. MX Cleanup can easily clean that location but I usually use the terminal with du -sh /var/cache/apt/archives/ to first see how large the "archives" directory is and then sudo apt clean to remove everything, except for two locked files that will remain (see below).

A little background. /var/cache/apt/archives/ contains the local repository of downloaded package files that are no longer needed. The command sudo apt clean will remove all the contents of the archives directory except for two files, a file named "lock" and a directory named "partial". They have special permissions that will not normally allow them to be deleted. Those two files need to be on the system for proper package updating.

When a package is installed using apt or apt-get, it downloads the package and dependencies in .deb format and keeps it in /var/cache/apt/archives/. The deb package is kept in /var/cache/apt/archives/partial/ by apt while downloading. When the deb package is completely downloaded, it is moved to /var/cache/apt/archives/.

Once the .deb files for the package and dependencies are downloaded, the system installs the package from those .deb files.

The system needs a place to keep the package files somewhere before installing them. After installation, the files will remain in the "archives" directory unless manually removed, e.g. MX Cleanup, sudo apt clean, and so forth. If a package is removed and then reinstalled, the system will look for the package in the cache ("archives" directory) first and get it there instead of downloading it again, as long as the package version in the cache is the same as the version in the remote repository.

Note that sudo apt autoclean is another command to clean the apt cache, but unlike "clean", autoclean only removes packages that are not possible to download from the repositories, such as old versions of packages.

Re: Clean old folders in /usr/lib/modules?

Posted: Sat Jul 27, 2024 12:51 pm
by MXRobo
Thank you @Stuart_M, this info was very "info-rmative" particularly as I don't know much about linux, like differences between cache and apt cache.

Therefore I use MX-Cleanup's defaults.

So, can I assume that:
MX-Cleanup's → Clear APT Cache
1- Old files - is equivalent to sudo apt autoclean
2- All files - is equivalent to sudo apt clean
3- Don't empty - is equivalent to :snooze:

Realizing that you didn't write the MX-Cleanup script.

Cheers!

Re: Clean old folders in /usr/lib/modules?

Posted: Sat Jul 27, 2024 1:10 pm
by MadMax
I suggested apt clean in your other thread. Guess I was on the right path ;)

9.9 GB free is plenty. But just to make things a little more tidy: Are you using ext4? ext4 reserves 5 % of space by default for the root user. Even in case of a full disk 2-3% is plenty on a 32 GB drive. You can set the percentage with tune2fs.

Code: Select all

sudo tune2fs -m 2.5 /dev/sdX
Replace sdX with your root partition. This will set it to 2.5 percent. That's the value I'm using on all my ext4 drives. Don't set it lower than 1%, though, to be sure.
Also keep in mind that this reserved space is actually free, so ext4 uses it to reduce fragmentation no matter how high it is set.

Re: Clean old folders in /usr/lib/modules?

Posted: Sat Jul 27, 2024 3:32 pm
by Stuart_M
MXRobo wrote: Sat Jul 27, 2024 12:51 pm ...
So, can I assume that:
MX-Cleanup's → Clear APT Cache
1- Old files - is equivalent to sudo apt autoclean
2- All files - is equivalent to sudo apt clean
3- Don't empty - is equivalent to :snooze:
...
Essentially correct although using age ("Old files") to describe packages to be deleted when using sudo apt autoclean is not correct because the age of a file is not the determining factor for sudo apt autoclean to delete a package.

A package (file) could be very old, for example 15 years old, yet it is still the latest version that is available from the repository. In that case, the package would NOT be deleted because the repository does not have a newer version available.

It would be clearer to say something along the lines that only packages that have a newer version available will be deleted.