When I update my system and a new kernel is installed it leaves behind module files in /lib/modules/. I'm somewhat OCD so on my main system I go there and 'rm -rf' them so I only have the kernel modules I need. Dumb really, in a way, because I'm using a 1TB drive, but still - why are these not cleaned up by the normal update? It's been reported as a bug - years ago - and Canonical seemingly doesn't care. Full disclosure - I use apt to update my system so I do not know if this is an issue when using one of the GUI package tools. The issue isn't really an apt bug because apt isn't responsible for cleaning up your system. The module files apparently fall under the category of config files, which means they are not removed with a normal apt remove or autoremove, unless you use the --purge option. Regardless, I'm tired of having to do this so went looking for solutions.
Here's an example from my guest bedroom PC, one that's not regularly updated or often used:
Wow, right? 60 modules folders but only 2 kernels installed. Almost a gig of wasted space on a 95GB partition.
Solutions:
If you always use '-purge' when you update, this won't happen. And of course, being Linux, some users have created ways to correct this problem since Ubuntu has not.
This command will remove the modules even after the kernel has been removed:
Or you can install this kernel management utility 'linux-purge' to purge these files:
To install this utility, do the following (as root). This installs the script, the manpage and bash autocompletions.
wget https://git.launchpad.net/linux-purge/plain/update-linux-purge
sudo chmod +x ./update-linux-purge && ./update-linux-purge
Now, you can use the utility with the command linux-purge, and its manual page is available with man linux-purge. For instance, to purge all old kernels (that are not present inside /boot), run:
linux-purge -b
https://git.launchpad.net/linux-purge
Note: The above part about linux-purge was copied from Stack Exchange and I have not tried it. I didn't like this solution since it requires and extra step when I update and and additional program to handle what should be done by the system.
I normally use a bash alias to upgrade:
so I could just add '-purge' to it and that fixes it.
I decided to try an custom apt configuration with info I stole from here.
File: /etc/apt/apt.conf.d/99autopurge
I put this on my guest computer and will see if it works.
Here's an example from my guest bedroom PC, one that's not regularly updated or often used:
Code:
stuart@asus-cn60:/lib/modules$ ls 4.15.0-20-generic 4.15.0-62-generic 5.15.0-60-generic 5.15.0-78-generic 5.15.0-88-generic 5.3.0-51-generic 5.4.0-120-generic 5.4.0-48-generic 5.4.0-89-generic 4.15.0-22-generic 4.15.0-64-generic 5.15.0-70-generic 5.15.0-79-generic 5.3.0-26-generic 5.3.0-53-generic 5.4.0-121-generic 5.4.0-77-generic 5.4.0-90-generic 4.15.0-29-generic 4.15.0-66-generic 5.15.0-71-generic 5.15.0-82-generic 5.3.0-28-generic 5.3.0-59-generic 5.4.0-122-generic 5.4.0-80-generic 5.4.0-91-generic 4.15.0-30-generic 5.0.0-29-generic 5.15.0-72-generic 5.15.0-83-generic 5.3.0-40-generic 5.3.0-61-generic 5.4.0-124-generic 5.4.0-81-generic 5.4.0-92-generic 4.15.0-32-generic 5.0.0-36-generic 5.15.0-73-generic 5.15.0-84-generic 5.3.0-42-generic 5.3.0-62-generic 5.4.0-131-generic 5.4.0-84-generic 4.15.0-33-generic 5.0.0-37-generic 5.15.0-75-generic 5.15.0-86-generic 5.3.0-45-generic 5.4.0-113-generic 5.4.0-42-generic 5.4.0-86-generic 4.15.0-34-generic 5.15.0-58-generic 5.15.0-76-generic 5.15.0-87-generic 5.3.0-46-generic 5.4.0-117-generic 5.4.0-45-generic 5.4.0-88-generic
Solutions:
If you always use '-purge' when you update, this won't happen. And of course, being Linux, some users have created ways to correct this problem since Ubuntu has not.
This command will remove the modules even after the kernel has been removed:
Code:
sudo apt purge linux-image-X.X.0-XX-generic
To install this utility, do the following (as root). This installs the script, the manpage and bash autocompletions.
wget https://git.launchpad.net/linux-purge/plain/update-linux-purge
sudo chmod +x ./update-linux-purge && ./update-linux-purge
Now, you can use the utility with the command linux-purge, and its manual page is available with man linux-purge. For instance, to purge all old kernels (that are not present inside /boot), run:
linux-purge -b
https://git.launchpad.net/linux-purge
Note: The above part about linux-purge was copied from Stack Exchange and I have not tried it. I didn't like this solution since it requires and extra step when I update and and additional program to handle what should be done by the system.
I normally use a bash alias to upgrade:
Code:
alias upgrade='sudo apt full-upgrade'
I decided to try an custom apt configuration with info I stole from here.
File: /etc/apt/apt.conf.d/99autopurge
Code:
APT::Get::Purge "true"; Binary::apt::Purge "true"; APT::Get::AutomaticRemove "true"; APT::Get::Purge-Unused "true"; Binary::apt::APT::Purge-Unused "true"; Binary::apt::APT::AutomaticRemove "true";
Comment