Building kernel with custom module list (like with make localmodconfig)

TL;DR: How do I build a custom Linux kernel from the Fedora dist-git that only includes modules from a specified list?

I’m running Fedora 41 (Workstation) on my laptop and have built a kernel (version 6.12.13, if it matters) with a few configuration changes following the instructions here. I would now like to also change the configuration to only build kernel modules that are in a list I provide (which would come from modprobed-db, a tool that logs which modules have ever been loaded on my system, thus giving a list of only the modules I actually need), but I’m having trouble figuring out how to do this.

In particular, I’ve checked out the Fedora Linux kernel repository from https://src.fedoraproject.org/rpms/kernel.git, switched to the f41 branch, and applied the custom configuration settings in the kernel-local file; I then build the kernel using the following command:

fedpkg local --arch x86_64 --without configchecks --with baseonly

This works but involves building a huge number of kernel modules, the vast majority of which I’ll probably never need, and this makes the build pretty slow (typically over an hour). If this was a vanilla kernel, I think I could use make localmodconfig to disable all module options that aren’t in the list; however, with the above method using fedpkg, I don’t seem to have direct access to the makefile (I think it’s generated at an intermediate step?) and so I’m not sure how to customize the configuration in this way. Any help would be much appreciated.

I am not quite sure what your goal is here.

Fedora uses a vanilla kernel with few or no modules compiled in.
Modules are loaded during boot for the hardware installed so the kernel actually does not see any unnecessary modules/drivers. Those modules are selected based on what is preloaded by dracut and what is loaded by modprobe during boot.

This process seems to indicate that the only modules actually loaded at run time are those for the installed hardware and nothing else.

1 Like

Right, my main goal is to speed up compilation times by avoiding compiling a bunch of unnecessary modules/drivers every time I recompile the kernel—I haven’t done precise benchmarks but I would estimate well over half the time is spent compiling modules that will never be loaded (judging by the fact that there are over 13000 .ko files in /lib/modules, and under 200 modules that modprobed-db reports I actually use).

So the concern is compile time for a custom built kernel with the appropriate modules and not the actual runtime modules.

That is different than I understood.
Thanks for the clarification. :+1:

I don’t build custom kernels so have no expertise in that area.

It has been a long time since I built my own kernel.
But I think you can control what modules are built with the kernel config file. Given you build your own kernel I assume you know how to change the config.