Recently I received a question via email:

How do I build Linux kernel module against installed or running Linux kernel? Do I need to install new kernel source tree from

To be frank you do not need a new full source tree in order to just compile or build module against the running kernel i.e an exploded source tree is not required to build kernel driver or module. The instruction outlined below will benefit immensely to a developer and power user.

Linux Kernel headers

This is essential because if you just want to compile and install driver for new hardware such as Wireless card or SCSI device etc. With following method, you will save the time, as you are not going to compile entire Linux kernel.

Please note that to work with this hack you just need the Linux kernel headers and not the full kernel source tree. Install the linux-kernel-headers package which provides headers from the Linux kernel. These headers are used by the installed headers for GNU glibc and other system libraries as well as compiling modules. Use following command to install kernel headers:
# apt-get install kernel-headers-2.6.xx.xx.xx

Replace xx.xx with your actual running kernel version (e.g. 2.6.8.-2) and architecture name (e.g. 686/em64t/amd64). Use uname -r command to get actual kernel version name. Please note that above command will only install kernel headers and not the entire kernel source-code tree.

A more generic (recommend) and accurate way is as follows:
# apt-get install kernel-headers-$(uname -r)

All you need to do is change Makefile to use current kernel build directory. You can obtain this directory name by typing following command:
$ ls -d /lib/modules/$(uname -r)/build
Sample output:


Let, say you have .c source code file called hello.c. Now create a Makefile as follows in the directory containing hello.c program / file:
$ vi Makefile
Append following text:

obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Save and close the file. Type the following command to build the hello.ko module:
$ make

To load Linux kernel module type the command:
# modprobe hello

A complete example

Create test directory (you can download following Makefile and .c file here):
$ mkdir ~/test
$ cd ~/test

Create hello.c kernel module file:

#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
	printk(KERN_INFO "init_module() called\n");
	return 0;
void cleanup_module(void)
	printk(KERN_INFO "cleanup_module() called\n");

Create a Makefile:

obj-m += hello.o
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

To build kernel module enter:
$ make
Sample output:

make -C /lib/modules/2.6.27-7-generic/build M=/tmp/test2 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'
  CC [M]  /tmp/test2/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /tmp/test2/hello.mod.o
  LD [M]  /tmp/test2/hello.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'

Run ls command to see newly build kernel module:
$ ls
Sample output:

hello.c  hello.ko  hello.mod.c	hello.mod.o  hello.o  Makefile	Module.markers	modules.order  Module.symvers

hello.ko is kernel module file. To see information about module, enter:
$ modinfo hello.ko
Sample output:

filename:       hello.ko
srcversion:     4F856ABA1F3290D5F81D961
vermagic:       2.6.27-7-generic SMP mod_unload modversions 586 

To load kernel module, enter:
$ sudo insmod hello.ko
$ sudo modprobe hello
To list installed Linux kernel module, enter:
$ lsmod
$ lsmod | grep hello

To remove hello Linux kernel module, enter:
$ rmmod hello
This module just logs message to a log file called /var/log/messages (/var/log/syslog), enter:
$ tail -f /var/log/messages
Sample output:

Nov  5 00:36:36 vivek-desktop kernel: [52488.923000] init_module() called
Nov  5 00:36:50 vivek-desktop kernel: [52503.065252] cleanup_module() called

Download above examples in zip format

See a detailed and completeexample with C source code about Compiling Linux kernel module for more information.

๐Ÿง Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

๐Ÿง 72 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
72 comments… add one
  • chesss Sep 3, 2006 @ 21:12

    would this work with suspend2 patching as well?

  • Anonymous Sep 4, 2006 @ 1:09

    This is untrue, /lib/modules/$(shell uname -r)/build is a symlink to the source tree. Title is misleading, you always need the at least the headers to build kernel modules.

  • zhangmaike Sep 4, 2006 @ 2:28

    on my system, /lib/modules/KERNELVERSION/build is a symlink to the corresponding full source tree.

  • ๐Ÿง nixCraft Sep 7, 2006 @ 12:22

    Yes you need kernel headers but not source code from (45+ MB tar ball). So title and post is correct.

  • ๐Ÿง nixCraft Sep 7, 2006 @ 12:23

    You should have mentioned your distro name. I have tested this on Red Hat, Cent OS, FC and Debian and it works perfectly.

    On some distro it makes a soft link to kernel header to /usr/src/version but you don’t need source code. Just delete rest of linux kernel source code (except for headers). And try out this hack

  • s.kartikeyan Sep 8, 2006 @ 2:14

    probably kernel-devel*.rpm is required in addition to makefile
    using /lib/modules.

  • Jon Eastwood Jan 30, 2007 @ 12:12

    You are 100% correct – you require the kernel headers
    whereas the source code from is not required.

  • Frank Jun 4, 2007 @ 21:58

    Here’s one for you… I have a network interface that I need to re-compile every time the kernel is updated. This is for the realtek 8169 NIC.
    Any way to automate this task on a yum update of a kernel?

    If you are running the target kernel, then you should be able to do :

    # make clean modules (as root or with sudo)
    # make install
    # depmod -a
    # insmod ./src/r8169.ko

    You can check whether the driver is loaded by using following commands.

    # lsmod | grep r8169
    # ifconfig -a

    If there is a device name, ethX, shown on the monitor, the linux
    driver is loaded. Then, you can use the following command to activate
    the ethX.

    # ifconfig ethX

    ,where X=0,1,2,…

    If I go though this process on the local box after a kernel upgrade, I’m good to go, but it sucks that I have to do this..


  • Alexander Mestiashvili Jun 20, 2007 @ 12:48

    this Makefile did not work for me .
    i used this one

    obj-m += hello-1.o

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

  • Daniel Oct 26, 2007 @ 22:06

    This is not clear enough for linux beginners. I am so sad that google placed this page so high in rankings.

    Maybe you should try to make it a bit easier to understand (give more details or explain why you do that ‘hello.c’ thing).


  • ๐Ÿง nixCraft Oct 26, 2007 @ 22:16


    You need to see hello.c (module) example here.


  • almassian Feb 18, 2008 @ 11:19

    I don’t know how can I built a makefile?!
    where should I define the PWD??!
    please help me, I’m a beginner ๐Ÿ˜€ :-p

  • Alien Glow Sep 18, 2008 @ 5:40

    I fumbled every time trying to install kernel modules on Debian. Though someone might find this useful. I have picked this bits from different sources.

    Compile and install a Kernel Module in Debian
    KVER=$(uname -r | sed ‘s,-.*,,g’)

    aptitude install linux-headers-$(uname -r) linux-source-$KVER build-essential
    cd /usr/src
    tar jxf linux-source-$KVER.tar.bz2
    ln -s /usr/src/linux-source-$KVER /lib/modules/$(uname -r)/source

    Download the required module source and unpack it
    Enter module source directory
    make install
    To make the module visible to your running kernel, you may like to run
    depmod -a
    modprobe modulename

  • touristguy87 Nov 4, 2008 @ 17:49

    SOP is to follow the instructions line by line from beginning to end to make sure that they actually work before posting them as a “guide”.

    There are too many holes here.

    a) you don’t need to know exactly what verion of the kernel you have, $(uname -r) takes care of that for you.

    b) what’s the difference beween $(uname -r) and $(shell uname -r)?

    c) what about includes like #include etc that I see on the reference pages, here?

    “See a detailed and complete example with C source code – how to Compiling Linux kernel module for more information.”

    That code doesn’t work either. I can’t get the includes to work. If I hardcode them then they just reference other header files that don’t link properly because they have includes written the same way. I can’t even get that example to build.

  • touristguy87 Nov 4, 2008 @ 17:52

    that is to say

    ..where exactly is this file?

    It’s in /lib/modules/$(uname -r)/build/include right? (I found it, I’m doing this from memory at 3am last night) ok so I hardcode that into the #include above and then I just get a bunch of errors saing that linux/whatever.h can’t be found so clearly in that header file are similar #includes.

    I modified the PATH variable to include /lib/modules…include and that still doesn’t work. I guess that I’ll figure this out later and post a solution.

  • ๐Ÿง nixCraft Nov 4, 2008 @ 18:52


    Under Ubuntu Linux 8.x install the following package (following will almost install every kernel source code file):

    sudo apt-get install linux-headers-$(uname -r) linux-libc-dev kernel-package

    Once done create hello.c as follows:
    mkdir ~/hello
    cd ~/hello

    Create hello.c:

    #include <linux/module.h>
    #include <linux/kernel.h>
    int init_module(void)
    	printk(KERN_INFO "init_module() calledn");
    	return 0;
    void cleanup_module(void)
    	printk(KERN_INFO "cleanup_module() calledn");

    Create Makefile (note tabs are important):

    obj-m += hello.o
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

    Type following to build:
    Sample output from my Ubuntu 8.10 box:

    make -C /lib/modules/2.6.27-7-generic/build M=/tmp modules
    make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'
      CC [M]  /tmp/hello.o
      Building modules, stage 2.
      MODPOST 1 modules
      CC      /tmp/hello.mod.o
      LD [M]  /tmp/hello.ko
    make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'


  • touristguy87 Nov 6, 2008 @ 18:04

    ok then I would just remove this part from the above:

    # apt-get install kernel-headers-2.6.xx.xx.xx

    as to just use $(uname -r) is much better

    also any comments about having to change to the “build” directory

    and note that you have to use $(shell uname -r) in the makefile.

    likewise do you need linux-libc-dev or not, it sounds redundant…

    and there is now a zip file with the programs, and two other links as examples.

    this one is probably redundant now except for it points to the original instructions on how to do this…and a lot more.


  • touristguy87 Nov 7, 2008 @ 4:12

    ok also

    obj := vs obj +=

    at the top it is the former, the working code seems to be the latter

    Here I also see

    obj-m = foo.o
    KVERSION = $(shell uname -r)

    and the orignal source:

    has +=

    this is pretty simple code once you’ve looked at it for 2 hours ๐Ÿ˜‰

    I think the main thing is that it has to point to $(uname -r)/build but you have to use $(shell uname -r) in the makefile -C part.

    anyway I see plenty of variation in the basic syntax among the 5 or 6 examples on those 3 links.

  • ๐Ÿง nixCraft Nov 7, 2008 @ 7:03

    Use method which works for you. There is also 3rd method but I don’t wanna confuse you with more stuff. Yes, linux-libc-dev is not required until and unless you are going to play more with low level device driver and other stuff requiring functions from libc.


  • touristguy87 Nov 8, 2008 @ 7:03

    I got it, somehow. I don’t know how.

    I was getting the “can’t find target ‘make’ error”…I updated my system and rebooted and just tried make on a whim and it worked.

    I used $(shell uname -r) in the Make file and += for the labels

    also I removed the function-calls from the code.See the original example here:

  • sathish Nov 13, 2008 @ 9:36

    what is use of .mod.o and .mod.c files , the Makefile which is present in o.s is creating , what info those files are having

  • instruc Jan 6, 2009 @ 17:14

    Great content tips .All you need to do is customize them with your own …Thank you…

  • ycdtosa Jan 19, 2009 @ 11:42

    if build is missing (even after installing headers) this might help:

    ln -s /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build

  • kyle Locke Jan 29, 2009 @ 7:30

    Thanks. Its what I was searchin for.

  • anon Feb 5, 2009 @ 17:12

    Anonymous 09.04.06 at 1:09 am wrote:
    >This is untrue, /lib/modules/$(shell uname -r)/build is a symlink to the source tree.

    build is a symlink to the build environment. Since source trees are build environments too, the build symlink can also point to them. But where just a plain build env without source is present, build points to a directory which merely has
    total 556
    drwxr-xr-x 6 root root 110 Feb 4 12:24 .
    drwxr-xr-x 4 root root 27 Jan 30 21:39 ..
    drwxr-xr-x 3 root root 16 Feb 4 12:24 arch
    drwxr-xr-x 5 root root 55 Feb 4 12:24 include
    drwxr-xr-x 2 root root 16 Feb 4 12:24 include2
    drwxr-xr-x 6 root root 116 Feb 4 12:24 scripts
    -rw-r–r– 1 root root 89994 Jan 30 21:42 .config
    -rw-r–r– 2 root root 530 Jan 30 21:43 Makefile
    -rw-r–r– 1 root root 474571 Jan 30 21:39 Module.symvers

  • m.h Feb 24, 2009 @ 8:11

    about the first module “hello.c ” , I had a problem ,
    I installed my kernel headers but after “make” I was recieved this message …
    Nothing to be done for ‘default’
    and the second one as well ….
    Nothing to be done for ‘all’

    what shall I do ?

  • kim gomez Jun 15, 2009 @ 4:13

    It was interesting to read trough ๐Ÿ™‚ keep up the good work and thanks for all the tips.

  • kim gomez Jun 15, 2009 @ 4:16

    Can you provide more information on this, or do you have some resources you can share where i can get more of such stuff?

  • sharath Aug 14, 2009 @ 14:47


  • saju Aug 17, 2009 @ 13:17

    periyar:/home/saju/Desktop/hello-linux-module# apt-get install kernel-headers-$(uname -r)
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Couldn’t find package kernel-headers-2.6.26-1-686
    ERROR-2 in Debian Lenny.
    periyar:/home/saju/Desktop/hello-linux-module# make
    make -C /lib/modules/2.6.26-1-686/build M=/home/saju/Desktop/hello-linux-module modules
    make: *** /lib/modules/2.6.26-1-686/build: No such file or directory. Stop.
    make: *** [all] Error 2

  • ๐Ÿง nixCraft Aug 17, 2009 @ 14:25

    install kernel-headers package using yum (Fedora / RHEL CentOS) or apt-get (Debian/Ubuntu).

  • saju Aug 18, 2009 @ 10:04

    I solved first Error by #apt-get install linux-headers
    But the second error not solved . Please help

    periyar:/home/saju/Desktop/hello-linux-module# make
    make -C /lib/modules/2.6.26-1-686/build M=/home/saju/Desktop/hello-linux-module modules
    make[1]: Entering directory `/lib/modules/2.6.26-1-686/build’
    make[1]: *** No rule to make target `modules’. Stop.
    make[1]: Leaving directory `/lib/modules/2.6.26-1-686/build’
    make: *** [all] Error 2

  • Benno Sep 10, 2009 @ 3:15

    Great tutorial. Thanks!

  • Rohit Oct 14, 2009 @ 19:19

    Its a wonderful introduction to a fresher to Linux.
    Thanks I was frustated when I found that makefile should be “Makefile” !!!!!!!!

  • Joe Oct 15, 2009 @ 9:00

    What if the hello.c is actually a hello.cpp ? How do we do the Makefile for that?

    • Anon Aug 4, 2014 @ 22:35

      Kernel modules are never written in c++. The kernel itself is c, so a c++ module would never build.

  • baskar Nov 24, 2009 @ 23:22

    I tried this on CentOS5.4 and I cannot proceed after this:

    [cuser@localhost test]$ make
    make -C /lib/modules/2.6.18-164.el5/build M=/home/cuser/test modules
    make: *** /lib/modules/2.6.18-164.el5/build: No such file or directory. Stop.
    make: *** [all] Error 2

    But, I do have kernel-devel and kernel-headers.

    [cuser@localhost test]$ yum search kernel-headers kernel-devel
    Loaded plugins: fastestmirror
    ============================ Matched: kernel-devel =============================
    kernel-devel.x86_64 : Development package for building kernel modules to match
    : the kernel.

    =========================== Matched: kernel-headers ============================
    kernel-headers.x86_64 : Header files for the Linux kernel for use by glibc
    [cuser@localhost test]$

    Could you help? If I figure this out, I can install the Broadcom BCM4312 wireless driver for Linux by Broadcom where I have the same issue.

    Thanks a lot

  • Viper Dec 11, 2009 @ 1:34

    Ubuntu 9.10 x64

    headers, source, module-assistant, build-essential, all installed.

    Typing “make -C /lib/modules/$(uname -r)/build M=$(pwd) modules”
    Get the following error:

    make: Entering directory `/usr/src/linux-headers-2.6.31-16-generic’
    make: *** No rule to make target `para’. Stop.
    make: Leaving directory`/usr/src/linux-headers-2.6.31-16-generic’

    Typing just “make”, adds
    make: *** [default] Error 2
    to the above

    Any comment?

  • touristguy87 Dec 12, 2009 @ 7:57

    a) read all of the above
    b) make sure that your OS is fully up to date

    Trust me, this does work.

  • Viper Dec 12, 2009 @ 11:52

    All was read. OS is up to date.

    But I solved it. Problem was the folder had a space in the name. Replaced with an underscore and it worked.

  • netbrat Feb 5, 2010 @ 22:24

    help me how should i get rid of this error

    sudo make
    make -C /lib/modules/2.6.31-19-generic/build M= modules
    make[1]: Entering directory `/usr/src/linux-headers-2.6.31-19-generic’
    CHK include/linux/version.h
    CHK include/linux/utsrelease.h
    SYMLINK include/asm -> include/asm-x86
    make[2]: *** No rule to make target `kernel/bounds.c’, needed by `kernel/bounds.s’. Stop.
    make[1]: *** [prepare0] Error 2
    make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-19-generic’
    make: *** [all] Error 2

    • Vlad Jun 21, 2010 @ 18:51

      I found an error in Makefile:

      $(PWD) should be $(shell pwd)

      Since PWD is not defined, I think it attempts to compile the entire kernel source.
      It solved this error I got:
      รขโ‚ฌล“make[2]: *** No rule to make target `kernel/bounds.cรขโ‚ฌโ„ข, needed by `kernel/bounds.sรขโ‚ฌโ„ข. Stop.รขโ‚ฌย

      • steven Mar 3, 2011 @ 18:00

        i’m actually compiling a different kernel module and i came across this comment. it fixed my compilation errors.

        thanks so much!

      • Louise Doogan Mar 26, 2011 @ 1:48

        Hi netbrat,

        I am getting the same error using Ubuntu version 2.6.24-19-generic. Did you get to the bottom of this? I am pulling my hair out!!

  • Sumathi Gopal Feb 9, 2010 @ 7:20

    Thank you for this. It worked like a charm. I’m on a Ubuntu laptop with 2.6.28-11 kernel installation; no kernel source code.


  • touristguy87 Feb 11, 2010 @ 16:30

    …in response to the numerous messages that I get about this, yes: Linux development is not as “tight” as I would like it to be. There will be little errors here and there, that you have to figure out and fix. It’s not “plug and chug”.

    But that’s part of its charm. If you’re just a *little* bit intelligent, you can read the errors and figure out what the problem is without knowing exactly what the errors mean. You get a feel for it. All of these bright linux coders don’t want to waste their time going back and documenting and correcting and redocumenting every problem that they have fixed. So sometimes some slip through.

    …remember, you’re getting their code for free. You might have to work with it a little.

    Or you can buy everything that you need from MS or some other major vendor and when you run into bugs with *that* you can pay for a support-incident and wait for them to fix it right ๐Ÿ™‚ Which is not an entirely bad idea as Linux is not as robust as Windows when it comes to things like copying files. It’s fairly easy to screw a file with the Ubuntu desktop, if you’re not careful.
    It’s not perfect. It’s just good, and free. But I wouldn’t, and I can’t, put 100% of my effort into Ubuntu/Linux.

    That’s why I have two laptops. One that runs Ubuntu and Vxbox, and the other that runs xp32sp3. You get stuck on one, just work on the other until you figure it out. Eventually you will figure it out, and learn a lot in the process. And it will help if you ask a specific question and not just copy and paste error messages onto this forum and then say “help me!”. Most errors are variations on a basic theme: some format error, a version-incompatibility or a file that is not where the tool in question thinks that it should be or maybe it doesn’t contain what that tool thinks that it should have. Try to actually read the documentation for the tools that you work with. And then just hope that the documentation is correct ๐Ÿ™‚

    Basically you have one big advantage. 9 times out of 10 the code is right there, all you have to do is open it up and read it, and figure out how it works. There may be small bugs. You might have to fix them. Really that’s not very likely if the above is taken care of. But it’s not impossible. And if that’s too much trouble, write to the developer and ask for help, or just find another tool that does what you need, that actually works. Or another way to do what you need to do. That’s only limited by you.


  • linux Apr 5, 2010 @ 17:55

    I dont have much examples to practice on.. Can you provide some examples to try on? (I have tried examples from LKMPG).

  • Joerg Apr 15, 2010 @ 13:07

    Could you clarify:

    (Ubuntu 9.10)
    I have linux-headers-x.x.x-y in my /usr/src directory. Are they the same as kernel-headers? (I find no kernel-headers anywhere on the machine, and as to apt-getting them, see below).
    – They (the linux-headers) contain a Makefile, can one do the procedure from within there?
    – If yes, there are “linux-headers-x.x.x-y” and “linux-headers-x.x.x-y-generic”, the latter with links. Which one (generic I suppose)?

    And one more question:
    apt-get install kernel-headers-$(uname -r) gives me:
    E: Couldn’t find package kernel-headers-2.6.31-20-generic

    Thanks for enlightening me, Joerg

  • touristguy87 Apr 30, 2010 @ 22:19

    Hint to all before you post in this list:

    before you post in this list

    BEFORE you post in this list

    go to this link:

    See the little box there?
    Take your question and/or comment and put it in there. See what happens.
    You just might find your answer there!

    This page is not Google. It seems that many have confused the two. You will not find the answer to all of your questions here. You just might find them on Google!

    • woNelly May 27, 2010 @ 14:33

      A little bitter that people are finding your post and actually trying what you said? If you give a quick tutorial and people have a question on YOUR tutorial, why should they expect google to answer?

      • touristguy87 May 27, 2010 @ 16:35

        No, I’m annoyed by people who insist on posting stupid thoughtless comments like yours.
        You epitomize the problem.

        Linux is not exactly the most straightforward, logical, and debugged OS that there is out there. But people like you who write first and then think second (if ever, and certainly not well) just make the situation worse. Maybe it hasn’t occurred to you yet but people who know what they are doing don’t want to help people like that because they don’t want to deal with them. You can’t expect someone to help you with every fucking question that you might have about anything they say, no matter how stupid your question is or how easily it would be answered if you would just use either your brain or Google not to mention both. People do not exist to help nitwits like you stumble through life.

      • touristguy87 Mar 3, 2011 @ 22:19 other words, why should you expect *anyone* to answer?
        And what if they don’t? Or their answer is wrong?

        What if, in the end, your brain is the only thing standing between you and utter failure?

        Would you then quit and blame the world for your problems?
        Or would you actually think and maybe think hard and long but keep thinking and trying until you come up with a solution?

        And if in the end, you do that, why would people not say “well it would be nice if you would just do that normally”?

        I’m not saying that that’s the right attitude especially in a help file.
        But if the difference between self-sufficiency and helplessness is 5 minutes of thought?
        Do you really want to make a habit of taking 30 seconds to type a question vs 5 minutes to think through all the options on your own?

        Anyway having seen this thread two dozen times long after I finished with it I would still have to look at my original posts and say that the answer was not found solely in this example. I had to pull up many pages on the same topic and try to get the examples to work there..and when I did so I found out many things which helped me to get this to work. This was definitely not the answer all on its own.

        Yes, Linux sucks that way. It’s definitely true.

        But it can be done and thus the bar exists between the self-sufficient and the overly-dependent who hire them and pay them to do IT work.
        That’s just how it is.
        And were it not that way, Linux software would probably not be open nor would it be so advanced. You’d probably still have software repositories with freeware and shareware but it would be the same crap that you can get for Windows. Instead of having a multitude of development in Linux that is eventually ported over to Win32/64 and made available for free, you’d get a bunch of time-limited shareware crap that is just a copyright-infringement on some expensive proprietary package and very little if any real development would happen in the user-space. We’d be stuck in 1995 and MS would still rule the PC market.

        It is that very arrogance and standoffishness that has helped to free MS users from their chains.
        Without it there would be no competition and no real freedom of choice in the mainstream market.
        And you can’t have your cake and eat it at the same time.
        Face it: the guys who really know their shit are far too busy to help newbies who can’t be bothered to take the time and make the effort to think on their own, not to mention who lack the intellect to do so effectively.
        And for very good reason. They are too smart to let themselves get dumbed down to the point of ineffectiveness.

        And if you think that it is bad here, try going to college and asking your professors stupid questions and see how well that works. No one owes you any explanation for anything and they certainly are not going to waste their time and energy giving you an endless series of explanations. Indeed many people will happily say nothing and let you suffer, just for the entertainment-value that you present to them. Of course you may not like that, you may even resent that, but believe me they probably don’t like you and certainly resent you as well. They will definitely resent doing your thinking for you and having you benefit as a result instead of them.

        And there are a lot of people in this world who walk around expecting people to help them regardless of how stupid or lazy they are. That’s just not a good way to go through life. Eventually someone will make you pay for it. And pay badly…pay in ways that you have yet to even imagine. And then blame you for being stupid enough to get in that position when the real fact is that they merely took advantage of you. That’s not really going to help you when you are the one lying there curled up in pain, even more helpless than before, and they are walking away laughing and counting your money.

        The key to happiness in life is self-sufficiency not a support-network.

        • Kyle Jones Feb 23, 2012 @ 23:45

          That was the best reply ever. I read your article, thought, “yeah, that’s cool, make using the right headers, easy enough. Wow, didn’t know you could make a module that small, neat.” Then I read the comments and wondered what the heck these beginners were trying to do messing with kernel module development, and specialized build processes. It just seemed silly. Good on you for saying it like it is ๐Ÿ™‚

    • Guillaume May 28, 2010 @ 18:39

      Well I found this page using google which make your comment recursively irrelevant

      • touristguy87 Jun 1, 2010 @ 1:27

        only if you *really* have a poor grasp of logic, and believe that this page is the only thing that you can find using Google.

  • embedded_user Jun 21, 2010 @ 17:42


    Thank you for the examples and explanations.

    I had a particular question and wanted to ask here- I did try and google for my answer in various ways, but I did not find any clear answers.

    I have an embedded linux device running 2.6.28 on ARMv6-compatible processor rev 6 (v6l).

    I don’t have access to the kernel, but the ntfs.ko is being loaded as a module and is in a directory where I can alter it.

    The ntfs.ko loaded for the device does not permit read/write access- just read only.

    The device does not have any package loaders, (no apt-get).

    I have an ubunutu install and could run commands from there (though your article seems to imply you would be working with the headers on the actual/running kernel) or is it possible for me to get/install the headers on the embedded machine without apt-get?

    Anyway, thanks for your hard work,

  • michi84 Aug 19, 2010 @ 18:50

    Remember once again: Certain lines within the shown Makefile have to be indented by TABs, _not_ SPACES, so a simple copy&paste won’t do it and leads to the rather meaningless error message: “make: Nothing to be done for `all’.”

  • samuel Oct 2, 2010 @ 1:01

    in Ubuntu 10.04, it’s not
    # apt-get install kernel-headers-$(uname -r)
    # apt-get install linux-headers-$(uname -r)

  • James Feb 5, 2011 @ 19:24

    Thank you for this tutorial. It helped. Immensely.

  • The Asylum Apr 26, 2011 @ 20:05

    Downloading with Axel (for me) is more consistent. It hits about 775-785 kb/s and stays there throughout the entire download.

    Wget fluctuates from as high as 790 kb/s to as low as 50 kb/s, and every number in between.

    The only real flaw with Axel is an easy fix but one that should be made default. The actual terminal output. There is an alternative output that keeps your download progress to a single line, but someone new probably wont find it.

  • Basil Jun 3, 2011 @ 13:28

    Hi Vivek,

    Thanks for the post. I have to compile a module on my VPS that run centOS 32 bit. The folder /lib/modules/ is empty. I looked for the build file on /usr/src/ and other folders on server without luck.

    Could you please shed some light on this..?


  • Jalal Hajigholamali Jun 7, 2011 @ 3:09


    Very useful material

  • Robert Zaleski Jun 8, 2011 @ 13:24

    This is not clear enough for linux beginners.

    Uhmmm, writing a kernel module is the last thing you should be doing as a beginner. If you’re just compiling one, then it depends heavily on the module you are compiling, and the documentation from that module writer is what you should go by. If they don’t have good instructions on how to compile and install, I’d be super hesitant to use it.

    Overall, I thought this was super helpful. I almost had to stop and make the sample module and load it just to do it ๐Ÿ™‚

  • ender ossel Jun 11, 2011 @ 10:24

    i have not a /var/log/messages how can i read the output of my helloworld kernel module? ๐Ÿ™‚

    • ARSHABBIR Aug 15, 2011 @ 6:07

      USE dmesg

  • jalal hajigholamali Aug 16, 2011 @ 16:37

    thanks, very useful materi

  • cap10ibraim Oct 5, 2011 @ 9:10

    Thanks , works on Ubuntu lucid 10.04

  • Airead Fan Jul 5, 2012 @ 6:12

    works on Ubuntu 12.04

    # uname -r
    Linux airead 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

  • Abhijeet Mar 3, 2013 @ 18:28

    hey I did all above mentioned things.
    but when i tried to run insmod command I got “insmod: error inserting ‘hello.ko’: -1 Required key not available”
    What could be the reason??

    Im running Ubuntu12.04(64 bit) on VMWare. previous to above steps i updated all things, installed kernel 3.7.9.

    • ravi Jan 12, 2015 @ 20:44

      Try disabling CONFIG_MODULE_SIG option in the linux .config file.

  • Jojo May 15, 2014 @ 9:00


    I see nothing’s happend here for a while so I’m trying my luck… I tried this example on an i-mx53 board. Along with it comes an SDcard with OS image: Ubuntu 10.04.

    I’m new to this, but it seems that my problem is that the header version and kernel version are not the same. (Error message below:
    make -C /lib/modules/ M=/home/lucid/test modules
    make[1]: Entering directory `/usr/src/linux’
    make[1]: *** No rule to make target `modules’. Stop.
    make[1]: Leaving directory `/usr/src/linux’
    make: *** [all] Error 2)

    The possible linux headers I can install are 2.6.32-versions, but the kernel is a Kernel from Freescale LTIB: So if I understood it correctly, the kernel is the program that runs closest to the hardware. In that case it makes sense that Freescale made a kernel version suitable for the i.mx53 board.

    So I do have linux-headers-2.6.32-21 installed, I guess I have to modify something somewhere to follow through this example…? Suggestions?

  • Laurence Aug 7, 2015 @ 2:33

    Thank you very much

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum