I've built a kernel with loadable module support for various reasons, one of them the possibility to compile modules and load them without rebooting. This is supposed to be useful when I need a module that I had not enabled in the kernel config.

Now, with drivers like nouveau, it's as easy as going to the source directory, and running make M=drivers/gpu/drm/nouveau. How can I build an updated iptables module without compiling a whole kernel and rebooting? Is it even possible?


Just go to your kernel source directory, make the changes you want, and make, then make modules_install.

That's all it takes.

If you want to build only one specific module, use:

make M=path/to/module/directory

For instance (from the kernel toplevel directory):

make M=fs/ext4
make M=fs/ext4 modules_install

To activate the changed modules, you must unload then re-insert them. If the module was not previously loaded, nothing special needs to be done.

Note that you cannot change something from built-in to module this way (that requires a reboot), and some modules may have dependencies that require changes in built-in configuration - you'll need to reboot for that too.

  • I build my kernel in tmpfs, so modules_install has to recompile everything. Isn't there a smarter way as done with nouveau?
    – Lekensteyn
    May 13 '12 at 8:09
  • Added some info. You'll need your config file though, I hope you kept that around or configured /proc/config.gz.
    – Mat
    May 13 '12 at 8:17
  • Yep, all my config files are backed up. I managed to build iptables like this: 1. copy .config and Module.symvers 2. make prepare&&make tools 3. make M=net/ipv4/netfilter 4. make M=net/ipv4/netfilter modules_install. Now I have to find out how to modprobe -r ip_tables so I can use the newly built modules.
    – Lekensteyn
    May 13 '12 at 8:59
  • Oh, I also had to make M=net/netfilter for generic changes.
    – Lekensteyn
    May 13 '12 at 9:14

Mat's answer sums it up, but I'd like to add one more thing.

It's best to make sure you're compiling your external modules with the same GCC version that was used to build your kernel image. You can determine this by reading the '/proc/version' file.

Many out-of-tree and proprietary driver modules will refuse to build at all with mismatched compiler versions.

  • Thanks for your answer, but I'm already building with the same gcc version.
    – Lekensteyn
    May 13 '12 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.