How to: Compile Linux kernel modules

This is one the essential and important task. Many time we upgrade our kernel and some precompiled drivers won’t work with Linux. Especially if you have weird hardware; then vendor may send you driver code aka C files to compile. Or even you can write your own Linux kernel driver. Compiling kernel driver is easy. Kernel 2.6.xx makes it even much more easier. Following steps are required to compile driver as module:

1) You need running kernel source code; if you don’t have a source code download it from Untar kernel source code (tar ball) in /usr/src using tar command:
$ tar -zxvf kernel* -C /usr/src

To be frank kernel headers are more than sufficient to compile kernel modules / drivers. See how to install kernel headers under Debian / Ubuntu Linux or RHEL / CentOS / Fedora Linux.

2) Next go to your kernel module source code directory and simply create the Makefile file as follows (assuming your kernel module name is foo):
$ vi Makefile

3) Add following text to it:

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

4) Compile module using make command (module build can be done by any user) :
$ make
It will finally creates the foo.ko module in current directory. You can see all actual compile command stored in .foo* files in same directory.

5) Once module compiled successfully, load it using insmod or modprobe command. You need to be root user or privileged user to run insmod:
# insmod foo.ko

Example: hello.c module

1) hello.c C source code. Copy following code and save to hello.c
$ mkdir demo; cd demo
$ vi hello.c

2)Add following c source code to it:

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */

static int __init hello_start(void)
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;

static void __exit hello_end(void)
printk(KERN_INFO "Goodbye Mr.\n");


This is an example modified from original source for demonstration purpose.

3) Save the file. Create new Makefile as follows:
$ vi Makefile
Append following make commands:

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

4) Save and close the file.

5) Compile hello.c module:
$ make

6) Become a root user (use su or sudo) and load the module:
$ su -
# insmod hello.ko

Note you can see message on screen if you are logged in as root under run level 3.

7) Verify that module loaded:
# lsmod | less

8) See message in /var/log/message file:
# tail -f /var/log/message

9) Unload the module:
# rmmod hello

10) Load module when Linux system comes up. File /etc/modules use to load kernel boot time. This file should contain the names of kernel modules that are to be loaded at boot time, one per line. First copy your module to /lib/modules/$(uname -r)/kernel/drivers. Following are suggested steps:

(a) Create directory for hello module:
# mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
(b) Copy module:
# cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
(c) Edit /etc/modules file under Debian Linux:
# vi /etc/modules
(d) Add following line to it:
(e) Reboot to see changes. Use lsmod or dmesg command to verify module loaded or not.
# cat /proc/modules
# lsmod | less

See also:

  • Read man pages of lsmod, rmmod, modprobe, modules
  • Documentation located in your kernel source directory (for example /usr/src/linux-2.6.xx.xx/Documentation/) and README file located under kernel source code tree /usr/src/linux-2.6.xx.xx/README
  • Read tutorial online.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 74 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
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
74 comments… add one
  • Anonymous Aug 23, 2005 @ 10:33

    Aha … intresting gone try this.

  • swift May 4, 2007 @ 3:28

    hi when i compile this by running make file this type of erro occcur …what to do

    make -f make
    make -C /lib/modules/2.6.18-1.2798.fc6/build M=/home/mclamna modules
    make[1]: Entering directory `/usr/src/kernels/2.6.18-1.2798.fc6-i686′
    scripts/ /home/mclamna/Makefile: No such file or directory
    make[2]: *** No rule to make target `/home/mclamna/Makefile’. Stop.
    make[1]: *** [_module_/home/mclamna] Error 2
    make[1]: Leaving directory `/usr/src/kernels/2.6.18-1.2798.fc6-i686′
    make: *** [all] Error 2

  • shan Jan 18, 2008 @ 6:23

    dis s wat i encountered wen using

    CHK include/linux/version.h
    CHK include/linux/utsrelease.h
    HOSTCC scripts/basic/fixdep
    In file included from /usr/include/bits/posix1_lim.h:153,
    from /usr/include/limits.h:145,
    from /usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h:122,
    from /usr/lib/gcc/i486-linux-gnu/4.1.2/include/syslimits.h:7,
    from /usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h:11,
    from scripts/basic/fixdep.c:113:
    /usr/include/bits/local_lim.h:36:26: error: linux/limits.h: No such file or directory
    In file included from /usr/include/sys/socket.h:35,
    from /usr/include/netinet/in.h:24,
    from /usr/include/arpa/inet.h:23,
    from scripts/basic/fixdep.c:115:
    /usr/include/bits/socket.h:310:24: error: asm/socket.h: No such file or directory
    scripts/basic/fixdep.c: In function ‘use_config’:
    scripts/basic/fixdep.c:204: error: ‘PATH_MAX’ undeclared (first use in this function)
    scripts/basic/fixdep.c:204: error: (Each undeclared identifier is reported only once
    scripts/basic/fixdep.c:204: error: for each function it appears in.)
    scripts/basic/fixdep.c:204: warning: unused variable ‘s’
    scripts/basic/fixdep.c: In function ‘parse_dep_file’:
    scripts/basic/fixdep.c:300: error: ‘PATH_MAX’ undeclared (first use in this function)
    scripts/basic/fixdep.c:300: warning: unused variable ‘s’
    make[1]: *** [scripts/basic/fixdep] Error 1
    make: *** [scripts_basic] Error 2

  • Nitin May 24, 2008 @ 16:56

    Hi swift, I guess u have not created Makefile in ur present directory, plz make sure that makefile name is correct and its case sensitive, it should be ‘Makefile’.

  • Nitin Jun 3, 2008 @ 14:22

    Hi, This was very much helpful but now I’m stuck because i didn’t understand how this particular makefile is working, so i’m not able to write it for multiple files. Please could anyone explain how this makefile works with a example for multiple files.

  • john Jun 6, 2008 @ 19:27

    how to cross compile lkm for arm?

  • Mohammad Aug 11, 2008 @ 16:21

    Dear Vivek ,
    Thanks alots for yr teaching.
    i compile a new module on fedora core 6 and make it very good. but in fedora i dont know how to submit for when linux start up , can load automaticly. i didnot find /etc/modules in fedora.

  • touristguy87 Nov 4, 2008 @ 6:19

    I followed the instructions as written even copying and pasting the code, I got nada.

    I was able to install the headers using
    apt-get install linux-headers-$(uname -r)

    then I copied and pasted the hello.c text and the Makefile from this page but I got nothing.
    make: Nothing to be done for ‘all’.

    I must be missing something

    this is in Ubuntu 8.04

  • touristguy87 Nov 8, 2008 @ 6:56

    ok I got it somehow, honestly I am not sure how but I patched my install (now running kernel-headers 2.6.24-21 generic) and rebooted, sudo -i, just tried running make and it worked.

    before I was getting “can’t find target ‘make’ error that seems so common. It now is working!!!

  • mangesh Nov 20, 2008 @ 10:49

    how do I cross compile a module using kbuild. Please help

  • mix Jan 7, 2009 @ 2:53

    The reason that make: Nothing to be done for ‘all’ is you should modify the Makefile, replace the space in each make command with tab.

    • s singh Feb 7, 2011 @ 14:27

      i am getting the same error and replacing spaces with tab is not working.
      some other solution..??

  • kernelmodule Jan 22, 2009 @ 11:48

    After executing the insmod the message is not being displayed…Can u pls guide me on whats goin wrong?

    • Anjan Jan 13, 2011 @ 8:09

      try looking for messages in dmesg i.e., after #insmod hello.ko
      try #dmesg
      u will be able to see the messages

      • tahi Aug 28, 2014 @ 5:17

        hello: disagrees about version of symbol module_layout
        i can’t install module to my system
        uname –all
        Linux debian-vir1 3.2.0-4-486 #1 Debian 3.2.60-1+deb7u3 i686 GNU/Linux
        OS is installed on virtualbox.
        what’s wrong in here?

  • scrat Jan 23, 2009 @ 20:25

    Oh, big thanks, source of Makefile is very helpful.

  • Victor May 18, 2009 @ 16:36


    I’m trying to compile your hello.c module in a Fedora Core 9 with a kernel. My gcc compiler is 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC). My kernel-devel package is installed with my current kernel version.

    When I try to compile I get the following:

    root@leela:[~/pruebas-modulos]$ make
    make -C /lib/modules/ M=/root/pruebas-modulos modules
    make[1]: se ingresa al directorio `/usr/src/kernels/′
    Building modules, stage 2.
    MODPOST 0 modules
    make[1]: se sale del directorio `/usr/src/kernels/′

    root@leela:[~/pruebas-modulos]$ ls
    hello.c hello.o Makefile Module.markers modules.order Module.symvers

    As you can see I do not obtain the .ko file. I have searched across the web in order to understand why I am not getting my .ko file, but I am not able to find anything useful. I would appreciate if you could help me to find why the makefile is not working

    Thanks in advance,

  • Jun 5, 2009 @ 4:25

    Hey, check that you makefile if you make a mistake with “obj-m” with “obj_m”, I have the same problem as you do.
    When I write “obj-m” instead of “obj_m”, everything goes good.

  • reveil Jul 27, 2009 @ 10:53

    Be sure you have tabs instead of spaces in the Makefile. Obvious and common mistake but took me a few minutes to figure this out after copy-pasting.

  • shreyas karmahe Aug 24, 2009 @ 5:42

    could u please tell me how can i install the kernel updates as I despirately need linux source code.

  • blaine Sep 23, 2009 @ 17:30

    Thank you for posting this. It is very hard to figure out how to just make a single module manually. This post should be ranked higher when searching “How to compile a single kernel module”. Self fulfilling prophecy, perhaps?

  • Adam Oct 14, 2009 @ 15:24

    Thanks, this ended a few hours of frustration.

  • Alok Nov 4, 2009 @ 13:41

    I have tried load module when Linux system comes up but it’s not displaying in
    #cat /proc/modules
    I have done these things successfully.
    # mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
    # cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
    # vi /etc/modules

    and Added “hello” word in next line.
    any suggestion would be welcome

    with regards

    • Devang Apr 23, 2013 @ 5:13

      Hi Alok,

      I am also facing the same problem. Have your query been solved ?
      If solved, tell me the procedure, it will be a great help to me.

      Thanks & Regards,

  • abhi Jan 10, 2010 @ 13:03

    Thanks a lot. Found this article v. useful

  • Arnab Chakraborty Jan 17, 2010 @ 12:07


    I found the article very helpful. Unlike many other linux tutorials, this one worked (with me) within the first few attempts! Just one minor point:

    I had to change
    tail -f /var/log/message
    tail -f /var/log/messages


  • mario Mar 23, 2010 @ 10:09

    Be sure , tabs instead of spaces in the Makefile!!!!!!!!

  • Alvaro Mar 25, 2010 @ 22:19

    Please can anybody help me out, I need to add the pktgen module, but I’m finding it difficult
    Thanks in advance

  • Martin Apr 3, 2010 @ 13:07

    thanks for that article. I try to compile a helloworld.c against the sources of my running kernel now quite a while without success. First the distro-kernel, and then also the kernel. It all looks good to me. make enters the right directories. the error is _always_ “No Rule for target ….. ” like in the first comment above.

    I don’t really understand all about the makefile. make is called from inside the kernel tree through the makefile right? Still, it really should be fine, but it doesnt work. Does anybody have a hint?

  • Zed Apr 4, 2010 @ 21:50

    Hi guys… I’m getting really desperate, I need to program a network device drivers for one of my projects, and I can’t even get the hello world done properly !

    I followed the protocol above, and when it comes to the make command, here is what I get:

    root@ubuntu:/usr/src/linux-source-2.6.31/include# make

    make -C /lib/modules/2.6.31-20-generic/build M=/usr/src/linux-source-2.6.31/include modules
    make[1]: Entering directory `/usr/src/linux-headers-2.6.31-20-generic’
    Building modules, stage 2.
    MODPOST 0 modules
    make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-20-generic’

    So no hello.ko file generated ! I already spent so many hours on this, checked that I have tabs instead of spaces in the makefile, and nothing changed…

    Thanks for your help guys !


  • Vlad Jun 21, 2010 @ 18:44

    I found an error in Makefile you have:

    $(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.”

  • smash Jul 21, 2010 @ 0:00

    Thanks a lot to mix and reveil for pointing out the tabs in place of spaces. I spent like 3 hrs trying to build a module from another site, and had no clue what was wrong. It all boiled down to tabs.
    Also thanks to whoever made this tut. 🙂

  • touristguy87 Jul 21, 2010 @ 22:27

    One thing I learned from this exercise is to always start from a working example.

  • Tapas Mishrae Aug 21, 2010 @ 1:42

    Checked it.
    Following is my program
    extern void *sys_table[];
    asmlinkage int(*main_sys_exit)(int);
    asmlinkage int alt_exit_function(int err_code)
    printk(“Sys_exit called with err_code=%dn”,err_code);
    return main_sys_exit(err_code);

    int init_module()
    void cleanup_module()

    and following is make file
    obj-m = sample2.o
    make -C /lib/modules/$(uname -r)/build/M=$(PWD) modules
    make -C /lib/modules/$(uname -r)/build/M=$(PWD) clean

    but I got error

    make -C /lib/modules//build/M=/home/tapas/LKP/pandora/temp/sample2 modules
    make: *** /lib/modules//build/M=/home/tapas/LKP/pandora/temp/sample2: No such file or directory. Stop.
    make: *** [all] Error 2

    where as I had installed Kernel headers.

  • touristguy87 Aug 21, 2010 @ 6:26

    If you cannot get that to work that is one thing.
    If you can get THAT to work but you cannot get YOUR code to work then
    for chrissakes
    figure out what you have done different that doesn’t work and fix it l!!!!

  • Lucas Nov 18, 2010 @ 18:05

    my system is ubuntu 10.04 kernel 2.6.32-25-generic, i did everything as described in article and.. when i do(as root: sudo -i ):
    # insmod hello.ko
    i get answer :
    # insmod: error inserting ‘hello.ko’: -1 Invalid module format

    And I’ve no idea what can be wrong.. or what I do wrong… would be gratefull for help

  • PAgore Nov 19, 2010 @ 9:51

    Cool! 🙂
    I compiled my first module in Linux.

    Thanks for your instructions!!!

  • Prashant Nov 21, 2010 @ 17:00

    I made a hello-1.c and Makefile in the same directory.
    when is issue “make” command, it gives error:
    make −C /lib/modules/2.6.32-25-generic/build M=/home/prashant modules
    make[1]: Entering directory `/home/prashant’
    make[1]: *** No rule to make target `−C’. Stop.
    make[1]: Leaving directory `/home/prashant’
    make: *** [all] Error 2

    I am getting this error from so long. I even changed my working directory to root.

    • Suneel Oct 29, 2011 @ 7:44

      How did you fix this problem Prashanth? I’m getting exactly same error make[1]: *** No rule to make target `−C’. Stop. Please help me if you have some info on this.

  • SIFE Dec 1, 2010 @ 8:47

    I have trouble with my custom kernel for the last tow days, it does not boot due [b]ahci[/b] module, can I compile it as module and then make initrd image or I have to add it to kernel configuration, if so where I have to activate it, I tried to go to:
    Device drivers-> Serial ATA Drivers and Parelle ATA Drivers-> AHCI SATA Support
    But it seems does not compile it according to this message when I install modules:
    WARNING: No module ahci found for kernel 2.6.37-rc4, continuing anyway

  • SIFE Dec 1, 2010 @ 8:48

    I have trouble with my custom kernel for the last tow days, it does not boot due ahci module, can I compile it as module and then make initrd image or I have to add it to kernel configuration, if so where I have to activate it, I tried to go to:
    Device drivers-> Serial ATA Drivers and Parelle ATA Drivers-> AHCI SATA Support
    But it seems does not compile it according to this message when I install modules:

    WARNING: No module ahci found for kernel 2.6.37-rc4, continuing anyway

  • Prabhu Dec 8, 2010 @ 10:44

    Cool article. My first module programming is running successfully. Thanks a lot.
    – Prabhu

  • Romy Jan 28, 2011 @ 18:12

    Really Thankful…..A great note for Beginners

  • Rigved Rakshit Feb 4, 2011 @ 14:36

    The line:

    obj-m = foo.o

    is wrong. It should be:

    obj-m += foo.o

  • s singh Feb 7, 2011 @ 15:26

    i am getting the following error after executing make
    make: Nothing to be done for `all’.

    • alexpally Apr 10, 2011 @ 16:48

      You must use TABs instead of spaces in make file

  • touristguy87 Feb 14, 2011 @ 2:08

    um, obviously one part of the problem here is the fact that depending on what editor you use, what exactly the offsets are between different sections of the relevant files and whether you use spaces or tabs, you will get different results.

    that’s on top of exactly what version of Linux you’re running, and what version of the relevant libraries.

    Trust me on this. Start with a working example, one that you simply download and run, with no edits. If you don’t have one find one on the internet somewhere. The most that you can pick up from a guide like this are just guidelines for what should work. Doesn’t mean that it will work for you on your system, the way that you’ve configured it or edited the file.
    When it should work and it does not? odds are that you are about to learn something new about Linux.
    good luck

  • touristguy87 Feb 14, 2011 @ 2:09

    also remember that there is a difference between ‘ and `
    just as between space and tab
    so if you see one don’t use the other

  • touristguy87 Mar 1, 2011 @ 15:18

    If you’re really having trouble getting this to fly, then I would suggest reading this:
    The full documentation on gnu make
    probably will help a lot.
    and as always
    start with something that works and make minimal changes between verifications
    something as small as a simple tab where the make utility expects spaces or vice-versa
    will definitely keep it from working. Not to mention an out-of-date install or an install that needs a reboot.

  • sudhanshu Mar 7, 2011 @ 18:00

    @s singh
    refer to link
    copy and paste the following from that page itself

    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

    but you will have to modify as:-

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

    as pointed out by one of friend here.
    be sure to copy and paste from this link only no need of replacing space with tabs and all that

  • Iranist Sep 22, 2011 @ 19:29

    It was so useful, thanks!

  • Debian user Nov 11, 2011 @ 1:13

    Debian Squeeze 2.6.32-5-amd64

    It worked right away!

    Thank you. ^^

    — screen dump —
    Module Size Used by
    hello 786 0
    powernow_k8 10978 1
    cpufreq_stats 2740 0
    cpufreq_conservative 5162 0
    cpufreq_userspace 1992 0
    parport_pc 18855 0
    cpufreq_powersave 902 0
    ppdev 5030 0

  • Kesava Nov 14, 2011 @ 6:15

    when I try to do the same with the different code; getting the following error. Any Help is really appreciated.

    > make
    make -C /lib/modules/ SUBDIRS=/home/vmware1/netp15 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


    • Moe Mar 21, 2012 @ 21:17

      In the makefile change all spaces to tabs….
      also change the lines with



      M=$(shell pwd)

  • Martin Apr 19, 2012 @ 20:42

    Just a great entry point for beginners!

  • mansha Apr 20, 2012 @ 22:01

    i try to follow these steps but i fieled plz someone reply me
    int init_module(void)
    printk(KERN_INFO “Hello world 1.n”);
    * * A non 0 return means init_module failed; module can’t be loaded.
    * */
    return 0;
    void cleanup_module(void)
    printk(KERN_INFO “Goodbye world 1.n”);

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

    finally i execute “make” and i get this message

    make: Nothing to be done for `all’.
    plz help mz so urgent

    • arizonadude Apr 27, 2012 @ 17:34

      I had the same problem, and it turns out that if you copy and paste the code above there is some random encoding, try to type all the Makefile in an editor and then save it 🙂

  • arizonadude Apr 27, 2012 @ 18:46

    I also needed to run depmod command to load the module after a reboot

  • sandeep Jun 1, 2012 @ 6:36

    ya its working fine
    thanks very much

  • teju Jun 16, 2012 @ 9:58

    iam trying to write a simple hello module i hae written a Makefile as
    obj-m += hello.o
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) module
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) module
    i given make
    i am getting the error of
    missing a saparetor like tat
    wheather i have to re install any packages i am using fedora16 3.1.0-7 linux kernel

  • arizonadude Jun 22, 2012 @ 20:40

    I think your problem relies for the line obj-m += hello.o . According to the code above, it doesn’t have the ‘+’ sign. Also I think it is modules and not module.

  • kks Sep 28, 2012 @ 12:06

    I have kernel module. I wanted to compile it as user mode application. what steps do i need to follow.
    Say i have wireless driver from compat wireless. Now i have debug it to know trace the API calls across three sub layers(wpa-supplicant, cfg80211,nl80211,mac80211) using hwsim. In this wpa_supplicant is user space module/application and other are kernel mode.
    I have to now compile them together as user space modules/application. and probable use simple print statement or use gdb to know the flow.
    Please help.

  • paulus Nov 9, 2012 @ 15:50

    GNU make insists that every command line beginns with a tab (can’t give u a reason for that)
    so just add this tabulator to your two make commands and it should work.

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

  • Sudarshan Apr 11, 2013 @ 8:16

    Thanks you. I followed your instructions. Removed spaces from Makefile and replaced with tabs, it worked for me.

  • AruniRC Apr 15, 2013 @ 4:28

    I just wrote the makefile as given, but cannot compile using make.

    the console keeps showing this message

    make: Nothing to be done for `all’.

    could someone please help?

    • AruniRC Apr 15, 2013 @ 4:32

      sorry. this was mentioned in previous comments

    • praveen Sh Oct 2, 2015 @ 11:30

      Im also getting same error is there any solution, because i’m new to this domain. thank you

  • Yogesh Sep 3, 2013 @ 12:37

    i have error “kernel/module.h” &”/kernel/init.h” is not avaliable . on my ubntu linux os.
    so what need to be run program.

  • Yogesh Sep 3, 2013 @ 12:43

    is there required compiled hello.c file before Makefile ?

  • Rosario Tyrell Nov 17, 2014 @ 20:48

    @ Alex, quel commento è probabile che non fatta da un lettore normale, ma piuttosto da un lettore in visita che ha inciampato sul posto per caso.

  • Dinali Aug 16, 2015 @ 17:41

    Hi, i did kernel model writing and i get a problem when compiling. can you help me to fix this.
    I installed header files but it wont help me.

    dinali@dinali-VirtualBox:~/Documents/hello$ make hello
    cc hello.c -o hello
    hello.c:1:64: fatal error: linux/module.h: No such file or directory
    #include // included for all kernel modules
    compilation terminated.
    make: *** [hello] Error 1

  • lennard Apr 2, 2016 @ 9:04


    i got the following error:
    make -C /lib/modules/4.4.0-kali1-amd64/build M=/root/workspaces/codeblocks modules
    make[1]: Entering directory ‘/usr/src/linux-headers-4.4.0-kali1-amd64’
    Makefile:10: *** mixed implicit and normal rules: deprecated syntax
    /usr/src/linux-headers-4.4.0-kali1-common/scripts/ /root/workspaces/codeblocks/Makefile: No such file or directory
    make[4]: *** No rule to make target ‘/root/workspaces/codeblocks/Makefile’. Stop.
    /usr/src/linux-headers-4.4.0-kali1-common/Makefile:1401: recipe for target ‘_module_/root/workspaces/codeblocks’ failed
    make[3]: *** [_module_/root/workspaces/codeblocks] Error 2
    Makefile:146: recipe for target ‘sub-make’ failed
    make[2]: *** [sub-make] Error 2
    Makefile:8: recipe for target ‘all’ failed
    make[1]: *** [all] Error 2
    make[1]: Leaving directory ‘/usr/src/linux-headers-4.4.0-kali1-amd64’
    makefile:3: recipe for target ‘all’ failed
    make: *** [all] Error 2

    does anyone have a solution ?

    already edit:
    spaces to tab
    install the linux headers (apt-get install linux-headers-4.4.0-kali1-all); and (apt-get install linux-headers-4.4.0-kali1-amd64)

    my code in hello.c is:

    MODULE_DESCRIPTION(“Some shitty words”);

    static int __init hello_init(void)
    printk(KERN_INFO “Hello world!n”);
    return 0;

    static void __exit hello_cleanup(void)
    printk(KERN_INFO “Cleaning up module.n”);


    if it helps my gcc output:
    #> gcc -o hello.h hello.c

    hello.c:1:64: fatal error: linux/module.h: No such file or directory
    compilation terminated.

    so any suggestions ?

  • tushar May 15, 2016 @ 8:39

    tushar@tushar:~/Desktop/Untitled Folder$ make
    make -C /lib/modules/3.19.0-49-generic/build M=/home/tushar/Desktop/Untitled Folder modules
    make[1]: Entering directory `/usr/src/linux-headers-3.19.0-49-generic’
    Makefile:669: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
    make[1]: *** No rule to make target `Folder’. Stop.
    make[1]: Leaving directory `/usr/src/linux-headers-3.19.0-49-generic’
    make: *** [all] Error 2

  • Willie Sep 6, 2016 @ 4:43

    I’m getting this error, have you guys ever seen this error . I’m using ubuntu 14.04

    make[1]: Entering directory `/usr/src/linux-headers-3.13.0-95-generic’
    /usr/src/linux-headers-3.13.0-95-generic/arch/x86/Makefile:111: CONFIG_X86_X32 enabled but no binutils support
    Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR: -fstack-protector not supported by compiler
    Makefile:614: *** missing separator. Stop.
    make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-95-generic’
    make: *** [all] Error 2

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