Old kernel-generic Folders & Files in usr/lib/modules/

Just had a look at Disk Analyser at old kernel content in /usr/lib/modules/
There seems to be files left-over after old kernels are removed, even by

sudo apt clean

sudo apt-get autoremove

e.g.

Each old kernel folder contains 1.3MB, not much you may say, but I have a small HDD and like to keep it clean and tidy.

Question: Can those defunct kernel folders be safely moved to the Rubbish Bin?

EDIT: I have done some websearches using searchterm: "old kernel files in usr/lib/modules/ ubuntu 20.04"

One result was: cleanup - Why does Ubuntu not clean out old kernel module files (in /lib/modules) when old kernels are removed? - Ask Ubuntu

...which offers solutions and points to a Bug Report for this feature: Bug #2007286 “Ubuntu does not clean out old kernel module files ...” : Bugs : linux package : Ubuntu

It is not possible to delete those files/folders using Disk Analyser or Nautilus as there is insufficient permission.

I am reasonably certain that Ubuntu Cleaner, Synaptic or Bleach Bit can remove this.

I am 100% certain about Ubuntu Cleaner - because I just tested it successfully.

2 Likes

I have bleachbit, but apt cleaning does not list purging of those redundant files/folders.
Also have Synaptic PM.

Are You use Zorin 17 or 16?

Im on Z16.3 Core, hence I included tag (zorin-os-16) with title.

But looking at other search results the bug affects current Ubuntu LTS, therefore Z17 as well.

There is a tool linux-purge in Launchpad that may do this job, but I have not attempted to install or use it.
Has anyone looked at that linux-purge tool or used it. feedback?

And is the 5.15 Kernel there still the default Kernel?

Yes. 5.15.0-130 (5.15.0-127 backup), others have been removed, but files for each have been left behind.

Hmm ... Maybe ... It is so: I'm on Zorin 17. And from Time to Time I get an Update with 5.15 Stuff. But this isn't really the Kernel. These are only some dev Files. Maybe this is the same in your Case?

On Z17, do you also see leftover folders and files from past kernel-generic's ?
(see my OP screenshot showing modules files that are left behind for each redundant kernel)
Normal apt cleaning wont get rid of them. Nor will Synaptic or Bleachbit.

Hi zab,
After looking at this thread, thought to look at my system.
I run 16.3 lite and there are leftover folders from past kernels.

I also run 17.2 lite and core as VM's and same there.

As you say, can't delete but Aravisians suggestion that Ubuntu Cleaner will get rid of them, it works.

I just tried it using the instructions from this site.

https://linuxcapable.com/install-ubuntu-cleaner-on-ubuntu-linux/

Edit: Ubuntu Cleaner wipes the backup kernel as well, just leaves the latest.
There was no option I saw to save the previous kernel.

1 Like

I actually have some Stuff, but not from the 5.15 Kernel but from the 6.8 Kernel. There are Folders with Files:

50 and 51 are installed. the other's not. Interesting might be the Content. In the Folders of the installed Kernels are more additional Files and Folders. To make a comparision:

6.8-0-49:

6.8.0-51:

Yes. I have 17 files in last 2 kernels, only 10 in old (removed) ones.

I would have an Idea - but I would be risky. You keep the folders of You installed Kernel. And You copy the other Folders on an USB Stick. Then prepare another USB Stick with Zorin on it. then delete the Folders from the old Kernels from Your System. Then reboot and look if all runs. If it shouldn't run, start the bootable USB Stick with Zorin on put the other USB Stick with the copied Folders in and copy the Folders in Live Mode back to the Place.

I decided to install Ubuntu Cleaner, using instructions in this post:

Then used that to clear out redundant ( )Package Configs that listed the defunct linux-kernel modules. All gone :slight_smile:

I have removed Bleachbit and Bleachbit root and will keep Ubuntu Cleaner instead.

I will mark this as solution.

1 Like

@Aravisian there are some other items listed by Ubuntu Cleaner ( )Package Configs
including fuse and evolution (I dont use evolution) and something for python 2.7.
I have not removed those for fear of corruption. Do you reckon Ubuntu Cleaner's reccomendations for cleaning those items is safe and trustworthy?

Yes, these are just APT package configuration remnants. The same that would be removed if you run sudo apt clean or sudo apt autoclean

These are not files you are currently using and are only used during that softwares initial install.

1 Like

@Aravisian

Have to ask, is there any problem you know of using Ubuntu Cleaner?
I don't see any option for it not to delete certain things.

From the right side window dropdowns, you can expand the list and select or deselect individual items.

1 Like

@zabadabadoo has answered your question, but I will address the nature of what you ask.

Unlike BleachBit, Ubuntu Cleaner does not have access to the files that may be dangerous to clean out (For the system, at least), It is intended to be simple and safe.
It only cleans out files that can go.
So you will see much shorter lists than you might with BleachBit, which can clean out Browser History and configurations and even personal settings.

1 Like

Thanks guys.

Appreciated.

1 Like