Ubuntu does not clean out old kernel module files (in /lib/modules) when old kernels are removed

Hello

Some time ago I posted this question on Ask Ubuntu.

The main point is, that even after old kernels are removed, the following files are left back inside /lib/modules for each previous kernel: (for AMD64)

$ 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

For Raspberry Pi, the files are 2-4 times larger, amounting to 3-4 MB per old kernel.

Recently, @ian-weisser encouraged me to bring this issue here.

Is this working as intended, or is it a bug that all files are not cleaned out of /lib/modules for old kernels? I have a hard time seeing the point of these files being left back.

I use Ubuntu 22.04 Server, but the problem was also present on Ubuntu 20.04 Server. And both for AMD64 and RasPi 4.

2 Likes

I see same problem on my Ubuntu Kinetic, so I opened a bug:

3 Likes

Did you add --purge option when you removed the kernel? If not, execute dpkg -l | grep 'rc ' to find the packages and sudo dpkg -P to remove them.
If you do removed the kernel completely, and dpkg shows no such packages, just rm these files, it doesn’t matter.

I think everyone agree that you can remove those files manually. The point is that it shouldn’t be necessary to use manual cleanup or removal of those files that are not used, and that should be removed as part of the automatic kernel cleanup.

2 Likes