It's easy to write modules for kernels that are forked off main kernel tree
This is what you do roughly
Compiling Kernel
However most of the distributions come with several variations of stock kernel. The intention there is to make sure that people choose the one that best describes their needs. For example the slackware box I'm working on has 3 versions of 2.6.21.5 kernel. To distinguish these versions from each other, the distributions use an extraversion string. This extraversion string is meant to throw a hint about the specific kernel. For example the 3 different versions on my slack box are 2.6.21.5-smp, 2.6.21.5-hugesmp and 2.6.21.5-huge.
You run into a problem while trying to load modules for such kernels. In such cases, the module compiles ok but gives an error when we try to load the same. More verbose module load error may be found in dmesg output. It generally has something like
hello: version magic '2.6.21.5 SMP mod_unload 686 ' should be '2.6.21.5-smp SMP mod_unload 686 '
To get rid of this error, edit your .config file to have the same EXTRAVERSION string a sin the kernel that you're trying to load. Alternatively get the kernel .config file from the distribution that you're running. As a hint, these files are generally installed where the kernel is, typically in /boot directory. Then fire the following commands to use this config
make -C /usr/src/linux-2.6.21.5 M=`pwd` modules
The Makefile looks like this
===== Makefile ==========
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
===== End Makefile ======
This will set you up compiling and loading modules with a stock kernel with an extraversion string.
This is what you do roughly
Compiling Kernel
- make menuconfig
- make
- make modules
- make modules_install
- copy the image to your boot partition and update the boot loader
- Download kernel sources and do a make oldconfig && make prepare there
- Create a module and its specific Makefile
- Compile the module pointing to this kernel directory for headers
- Load the compiled module via insmod
However most of the distributions come with several variations of stock kernel. The intention there is to make sure that people choose the one that best describes their needs. For example the slackware box I'm working on has 3 versions of 2.6.21.5 kernel. To distinguish these versions from each other, the distributions use an extraversion string. This extraversion string is meant to throw a hint about the specific kernel. For example the 3 different versions on my slack box are 2.6.21.5-smp, 2.6.21.5-hugesmp and 2.6.21.5-huge.
You run into a problem while trying to load modules for such kernels. In such cases, the module compiles ok but gives an error when we try to load the same. More verbose module load error may be found in dmesg output. It generally has something like
hello: version magic '2.6.21.5 SMP mod_unload 686 ' should be '2.6.21.5-smp SMP mod_unload 686 '
To get rid of this error, edit your .config file to have the same EXTRAVERSION string a sin the kernel that you're trying to load. Alternatively get the kernel .config file from the distribution that you're running. As a hint, these files are generally installed where the kernel is, typically in /boot directory. Then fire the following commands to use this config
- make oldconfig
- make prepare
make -C /usr/src/linux-2.6.21.5 M=`pwd` modules
The Makefile looks like this
===== Makefile ==========
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
===== End Makefile ======
This will set you up compiling and loading modules with a stock kernel with an extraversion string.