Making a linux module

Asked by José Marcos Gomes

I'm using 10.04 - 2.6.32-27-generic and I'm trying to figure out my problem to install VirtualBox OSE.

To make things simple, I reproduced the problem in few lines:

Entered the following in file "dummy.c":

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

static int __init hello_start(void)
{
 printk(KERN_INFO "Loading dummy module...\n");
 return 0;
}

static void __exit hello_end(void)
{
 printk(KERN_INFO "Exit dummy module.\n");
}

module_init(hello_start);
module_exit(hello_end);
</code>

And the following in the file "Makefile":

<code>
obj-m = dummy.o
KVERSION = $(shell uname -r)
all:
       make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
       make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
</code>

Entered the command:

<code>
make
</code>

I expected that the build generate the file "dummy.ko" but this is what I got:

<code>
make -C /lib/modules/2.6.32-27-generic/build M=/home/marcos/DummyModule modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-27-generic'
make[1]: *** No rule to make target `modules'. Stop.
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-27-generic'
make: *** [all] Error 2
[2]+ Done gedit dummy.c
</code>

Investigating the directory "/usr/src/linux-headers-2.6.32-27-generic" I don't see the expected "Makefile" file!

In https://help.ubuntu.com/community/Kernel/Compile is a too detailed procedure to build the kernel and I don't see what's wrong with my system configuration.

In https://wiki.ubuntu.com/KernelCustomBuild, a much more simple recipe, the shortcut:

<code>
make -C /usr/src/linux-headers-`uname -r` M=`pwd` modules
</code>

Results in:

<code>
make: Entering directory `/usr/src/linux-headers-2.6.32-27-generic'
make: *** No rule to make target `modules'. Stop.
make: Leaving directory `/usr/src/linux-headers-2.6.32-27-generic'
</code>

So the question is: <b>How to accomplish this in a simple manner? What can be wrong?</b>

Question information

Revision history for this message
José Marcos Gomes (jose-marcos-gomes) said :
#1

Ok,

It's silly and I'm in shame, but somewhat I did wrong sometime ago (I don't know when or what), but this is solved:

sudo apt-get remove linux-headers-`uname -r`
sudo apt-get install linux-headers-`uname -r`