Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm trying to setup an environment for kernel module development in Linux. I've built the kernel in the home folder and would like to place the sources and binaries to the correct place so include correctly.

The example for building the kernel module has the following includes:

#include <linux/init.h>
#include <linux/module.h>

What are the absolute paths that the linker looks for these headers?

share|improve this question
What OS, please? – Faheem Mitha Apr 20 '14 at 11:45
@FaheemMitha Linux – Alan Apr 20 '14 at 11:46
What linux distribution, please? Including version. – Faheem Mitha Apr 20 '14 at 11:47
@FaheemMitha Xubunt 13.10, kernel 3.14. If you know how to answer, please mention why is this issue distribution specific. – Alan Apr 20 '14 at 11:53
If you keep it all in your home, there is no "correct place". You just give your chosen path to the build system. If you want to install them in /, then it's distro specific. – Leiaz Apr 20 '14 at 12:47

3 Answers 3

up vote 2 down vote accepted

I generally approach this question like this. I'm on a Fedora 19 system but this will work on any distro that provides locate services.

$ locate "linux/init.h" | grep include

Your paths will be different but the key take away is that you want to ask locate to find what's being included ("linux/init.h") and filter these results looking for the keyword include.

There are also distro specific ways to search for these locations using RPM (Redhat) or APT (Debian/Ubuntu).


Notice however that the paths within the C/C++ file are relative:

#include <linux/init.h>

This is so that when you call the compiler, gcc, you can override the location of the include files that you'd like to use. This is controlled through the switch -I <dir>.

excerpt from man gcc

   -I dir
        Add the directory dir to the list of directories to be searched for 
        header files.  Directories named by -I are searched before the 
        standard system include directories.  If the directory dir is a
        standard system include directory, the option is ignored to ensure 
        that the default search order for system directories and the special 
        treatment of system headers are not defeated .  If dir
        begins with "=", then the "=" will be replaced by the sysroot 
        prefix; see --sysroot and -isysroot.

External modules

There's this article which discusses how one would incorporate the development of their own kernel modules into the "build environment" that's included with the Linux kernel. The article is titled: Driver porting: compiling external modules. The organization of the Kernel's makefile is also covered in this article: makefiles.txt.

For Kernel newbies there's also this article: KernelHeaders from the website.

NOTE: The Kernel uses the KBuild system which is covered here as part of the documentation included with the Kernel.


share|improve this answer
I've listed the default include paths for gcc following this question but it doesn't include a path to the header files. I'm hoping to setup the things the default way to avoid the -I option in gcc. – Alan Apr 20 '14 at 18:18

Answers are often distribution specific, because they may have specific machinery to do this. In the case of Debian there is The Debian Linux Kernel Handbook. Since Ubuntu is essentially Debian, all of this should apply. If I understand correctly, you are asking about installing the kernel. One approach, a good one, is to build a binary package for the kernel and kernel headers, and install those, and this handbook shows you how. See also my answer to "How do I upgrade the Debian Wheezy kernel offline?". This answer really could do with some cleaning up.

Note that using the stock Debian/Ubuntu kernel and kernel header binary packages is an entirely reasonable thing to do, and does not require an compilation.

share|improve this answer

The kernel has a deb-pkg target. On debian, make deb-pkg and sudo dpkg -i'ing the two resulting packages (in ../) worked like a charm for me. I'd think it works the same on Ubuntu. On build and install, those includes wind up in the right places automagically.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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