There are a lot of interesting kernel modules. Thanks to the Linux kernel, I now know there is such a thing as a “Lego Infrared Tower”.
I’m trying to slim down my Linux kernel beyond the point of things I obviously don't need.
To do this, I need a programmatic way to find the unused kernel modules currently in my system.
I know about lsmod
, but that’s very far away from what I’m looking for.
*** The reverse approach - by elimination ***
What I might need in order to achieve this result is a way to determine which statically compiled and loaded modules currently are in use. These are the ones selected by “*” in the menuconfig and not just “M”
I think I already might have a way to “cross out” each of those modules in the .config file of the current kernel, because it is possible to map module names to config names using a grep command as described here:
Binding lsmod module name with kernel configuration menu entry
... though I am not sure how consistently that will work.
So what I have already is the .config file and the kernel sources and that grep command from that link above. The bottleneck is the first list of statically-used and dynamically-loaded kernel modules.
This is perhaps a “best effort” question. It is as difficult to completely clean a kernel as it is to completely clean a bedroom. When my bedroom is clean, there is still some dust here and there. These are the same expectations I would expect for an answer to this question.
With any resulting list, more manual filtering will be needed, because I don't think I am constantly using things like DNS name resolutions, though I do need those intermittently (specifically, kernel DNS resolutions may actually be used for network boot only -- I am not sure.)
There has to be a faster way to clean a kernel than recompiling the kernel every few hours with fewer and fewer modules each time. Is there a more common strategy?
lsmod
list the modules used right now by the kernel? Most are auto-loaded when needed so there is your list? Of course, those parts of the kernel that are compiled in but could in theory be a module (if you configure them as "M" not "Y") are not modules and are therefore not listed bylsmod
. – Ned64 Mar 28 '21 at 21:34