Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 5095  / 3 Years ago, sun, june 20, 2021, 4:00:08

Today, I noticed that the directory /lib/modules still have all the directories from previously installed kernels, thus:


$ ls /lib/modules
5.4.0-29-generic 5.4.0-31-generic 5.4.0-33-generic 5.4.0-37-generic 5.4.0-39-generic
5.4.0-40-generic 5.4.0-42-generic 5.4.0-45-generic 5.4.0-47-generic 5.4.0-48-generic
... etc.

In each of these directories, the following files are left (Intel/AMD system):


$ ls -l
-rw-r--r-- 1 root 143K 2022-04-28 18:36 modules.alias
-rw-r--r-- 1 root 154K 2022-04-28 18:36 modules.alias.bin
-rw-r--r-- 1 root 8.0K 2022-04-08 10:44 modules.builtin
-rw-r--r-- 1 root 25K 2022-04-28 18:36 modules.builtin.alias.bin
-rw-r--r-- 1 root 11K 2022-04-28 18:36 modules.builtin.bin
-rw-r--r-- 1 root 63K 2022-04-08 10:44 modules.builtin.modinfo
-rw-r--r-- 1 root 85K 2022-04-28 18:36 modules.dep
-rw-r--r-- 1 root 123K 2022-04-28 18:36 modules.dep.bin
-rw-r--r-- 1 root 268 2022-04-28 18:36 modules.devname
-rw-r--r-- 1 root 215K 2022-04-08 10:44 modules.order
-rw-r--r-- 1 root 489 2022-04-28 18:36 modules.softdep
-rw-r--r-- 1 root 279K 2022-04-28 18:36 modules.symbols
-rw-r--r-- 1 root 326K 2022-04-28 18:36 modules.symbols.bin

And for a Raspberry Pi (notice the size differences):


-rw-r--r--  1 root 859K 2022-04-25 17:31 modules.alias
-rw-r--r-- 1 root 893K 2022-04-25 17:31 modules.alias.bin
-rw-r--r-- 1 root 11K 2022-04-04 13:33 modules.builtin
-rw-r--r-- 1 root 27K 2022-04-25 17:31 modules.builtin.alias.bin
-rw-r--r-- 1 root 14K 2022-04-25 17:31 modules.builtin.bin
-rw-r--r-- 1 root 84K 2022-04-04 13:33 modules.builtin.modinfo
-rw-r--r-- 1 root 399K 2022-04-25 17:31 modules.dep
-rw-r--r-- 1 root 548K 2022-04-25 17:31 modules.dep.bin
-rw-r--r-- 1 root 250 2022-04-25 17:31 modules.devname
-rw-r--r-- 1 root 209K 2022-04-04 13:33 modules.order
-rw-r--r-- 1 root 950 2022-04-25 17:31 modules.softdep
-rw-r--r-- 1 root 354K 2022-04-25 17:31 modules.symbols
-rw-r--r-- 1 root 425K 2022-04-25 17:31 modules.symbols.bin

For a system that's been running for 2 years with all kernel upgrades, this amounts to ~50 old directories. For a normal Intel/AMD system, it's around 100 Megabytes, and for a Raspberry Pi it's over 300 Megabytes in total - it will amount to something over time.


So I wonder why these old module directories and files for removed kernels aren't removed as part of the cleanup process?


I recently upgraded from Ubuntu 20.04 to 22.04 (which is why I'm doing some cleanup stuff anyway).


As things currently stand, I wonder if I should make my own cleanup script for these leftover directories. Still, I'm curious why it isn't done automatically.


More From » kernel

 Answers
0

I don't know why


I don't think you will get a good answer to why Ubuntu does something the way it does something.


History


Up until some years ago Ubuntu didn't clean up any kernel and kernel header packages at all. Now Software Updates removes old and unused kernels. I think it runs something like:


sudo apt autoremove

Unfortunately it leaves those module files behind.


Moving forward


You don't have to write a script to get rid of them. The following command will do the job:


sudo apt --purge autoremove

Note, you have to run this command before Software Updates does its cleaning up.


Cleaning Up


As for the existing modules left behind, you will have to delete them manually, making sure you don't delete any module folders that are currently being used.


Use this command to find the list of installed kernels:


apt list --installed linux-image*

If Ubuntu has been removing old kernels then you should see two or three entries, including linux-image meta package linux-image-generic. Write down the kernel version numbers of the install kernels and make sure you don't delete the /lib/modules/ sub-folders for the installed kernels.
Hope this helps


[#555] Monday, June 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
panshow

Total Points: 454
Total Questions: 98
Total Answers: 122

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
panshow questions
;