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.