compiling test module
I am trying to compile a test module (hello) to learn how to do it. I was trying to follow the instructions here tldp.org/LDP/lkmpg/2.6/html/lkmpg.html which didn't work. I get error 2, file not found in /usr/src/linux-headers-3.2.0-4-common/arch/x86/Makefile
I tried also using the directions here: linuxforums.org/forum/kernel/61673-how-write-my-makefile-for-a-hello-kernel-module.html
However, I am getting the exact same error. I found a post from idera (SQL monitoring softeare I think) stating a bug in the >2.6.29 kernels that have the architecture specific module directories (wiki.r1soft.com/display/kb/Compiling+a+module+on+Debian+with+Linux+Kernel+2.6 .29+and+higher)
I dont know what is wrong and I'm sure there is something simple and stupid I have overlooked. Can someone show me what's wrong?
I checked the Makefiles for virtual box on that VM and those seem to reference /lib/modules/<kernel>/build as well so I don't understand what I am doing wrong. :(
obj-m := hello-1.c
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Whats your distro ? Whats the output of 'uname -r' ? Did you install kernel-devel and kernel-header packages ?
I am running the 3.2.0-4 kernel on 64 bit Debian wheezy (RC1 is the current release I think) I have the Linux headers installed and I should have kernel-devel installed but I'll double check when I get home from work. I do also have the package build-essentials installed.
I cant seem to find the kernel-devel package. I've tried that and linux-kernel-devel.
Originally Posted by cmattv
I do have the headers. Do you know what this package is called for Debian?
I use Fedora , there its known as kernel-devel - I think linux-kernel-devel should the one for Debian.
You said, your are using 64-bit - Can you check /lib64/modules ?
Customizing & Installing Linux Kernel on Debian Wheezy | Biboroku
I had some issues with Fedora while creating kernel modules- what I used to do is - just ignore existing kernel - download the latest stable from kernel.org and install that kernel with old
configuration (make oldconfig) and then update grub menu with new kernel . Reboot and login - now kernel dev becomes much easier :)
hmm i don't have /lib64/modules. I only have ld-linux-x86-64.so.2 in /lib64. In /lib I have a modules directory and in that I have a 3.2.0-4-amd64 and 3.2.0-4-rt-amd64
Unfortunately I manually compiled some applications and I don't remember which ones. I'd prefer not to replace the kernel every time I want to make a module for it.
did I make a mistake in the makefile? is there some setting I missed? I tried linux-kernel-devel as well and that package couldn't be found either.
Makefile seems fine to my eyes. I think its problem with missing kernel src. I'll try to find a Ubuntu/Debian VM and check this out.
Originally Posted by cmattv
The Debian package for the Linux source code is linux-source
Okay installed debian on VMware box. Yes,even i got the same error message.
Then I did
It installed some different architecture header files -
root@debian:/home/laks# apt-get install linux-headers*
You may want to remove the unnecessary ones.
Now I can do this !
make -C /lib/modules/2.6.32-5-amd64/build M=/home/laks modules
make: Entering directory `/usr/src/linux-headers-2.6.32-5-amd64'
CC [M] /home/laks/hello.o
Building modules, stage 2.
MODPOST 1 modules
LD [M] /home/laks/hello.ko
make: Leaving directory `/usr/src/linux-headers-2.6.32-5-amd64'
So Its a problem with missing correct header files. Install only required packages via apt-get install
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
#root@debian:/home/laks# cat hello.c
* hello-1.c - The simplest kernel module.
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
printk(KERN_INFO "Hello world 1.\n");
* A non 0 return means init_module failed; module can't be loaded.
printk(KERN_INFO "Goodbye world 1.\n");
I've just run apt-cache policy linux-headers* and there's one or twenty of them so a trick to install things related to your running architecture is to use back ticks and run the uname command. For example
on my Siduction box returns
apt-cache policy linux-headers-`uname -r`
This can also be applied to things like apt-get install. I assume that something similar would work in the Red Hat world?
*** 3.8-12 0
500 http://ftp.spline.de/pub/siduction/base/ unstable/main amd64 Packages