The "How to Build External Modules" section of the kernel.org kbuild documentation ( https://www.kernel.org/doc/Documentation/kbuild/modules.txt ) says:

To build external modules, you must have a prebuilt kernel available that contains the configuration and header files used in the build. Also, the kernel must have been built with modules enabled. If you are using a distribution kernel, there will be a package for the kernel you are running provided by your distribution.

An alternative is to use the "make" target "modules_prepare."

My question is, alternative to what? Alternative to

"have a prebuilt kernel available that contains the configuration and header files"


"the kernel must have been built with modules enabled"

or something else?

1 Answer 1


It's an alternative to "using a distribution [...] package", which is synonymous with having "the configuration and header files" available.

You should include a .config before you do this. Most distro kernels have this available in /proc/config.gz; copy that into the top of the source tree and

gunzip -c config.gz > .config

This will only work if the source version is >= the running kernel. Note that if you intend to use the module with the running kernel, the source version number should be exactly the same.

  • Thank you for your answer. When you say "You should include a .config before you do this.", do you mean that I should also have the whole source tree of the kernel I want to build the module for? So If I understand correctly, I can either have the header and config files, or, the complete source tree and .config file where I need to do make modules_prepare?
    – Lavya
    Commented Jun 10, 2015 at 16:55
  • 1
    Yes. You can't build a module without a kernel source. The "make targets" referred to in that documentation are in that source. Ideally, you should use a distro package for that (they all have one). Alternately -- notice I am kind of repeating something here ;) -- you could download one from kernel.org and go the make modules_prepare route. But if you do that, make sure it is has the same version number (they are all archived if you descend into kernel.org/pub/linux/kernel).
    – goldilocks
    Commented Jun 10, 2015 at 17:11
  • 1
    Yes. On fedora it's the -devel package. Pretty sure you do have to do the make modules_prepare thing with it too, unless they've done so already -- in which case doing it again won't do any harm. The tree will be in /usr/src/kernels/[version] and will have an appropriate .config in it.
    – goldilocks
    Commented Jun 10, 2015 at 17:44
  • 1
    If that fails (I just tried w/ a fedora package and it did), just download 3.19.5 from kernel.org, pop in your .config, and use that.
    – goldilocks
    Commented Jun 10, 2015 at 17:51
  • 1
    If you use the config from /proc/config.gz that should work -- you'll end up with the exact same kernel sans Fedora patches. Those are not hugely significant, though. Fedora is my distro of choice and I've been rolling my own kernels from the vanilla source there for years and never had a problem. Pay attention to steps 4, 5, and 6 here: unix.stackexchange.com/a/115621/25985
    – goldilocks
    Commented Jun 11, 2015 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .