Linux Kernel – How to Recompile Without Unused Modules

kernel-moduleslinux-kernel

Is there a neat way of stripping the Linux kernel to only support the devices that are currently in use. After NVIDIA complaining about GCC version mismatch, I decided to recompile the kernel with the current version of GCC. Now, since it is known which modules the current kernel actually uses, can I automatically generate a .config file which is customized for this machine. That would booth save some space and time. Something like

lsmod [options] | sed [a good regexp] > .config

Best Answer

That's what make localmodconfig is for.

Excerpt from /usr/src/linux/README:

"make localmodconfig" Create a config based on current config and
                      loaded modules (lsmod). Disables any module
                      option that is not needed for the loaded modules.
Related Question