Pages

Unixbhaskar's Blog

Friday, July 31, 2009

How to build perticular kernel module :step by step

This article shows how to rebuild only a single module that comes with the main kernel tree for folks that neither need nor want to rebuild the whole kernel. If you want to build an out-of-tree module, than that module's documentation is probably the best starting point.


To make the intention of this howto somewhat clearer, this is the Problem I had: I have an old box i use for server-purposes and want to extend its functionality to an access-point. It has an ath5k-driven card, and for my running kernel (2.6.29-2-686 debian sid build) ath5k needs to be patched to enable master mode. Since the box is somewhat slow, I did not want to rebuild the kernel, plus that would force me to restart and losing uptime ;)

OK here we go:

apt-get install linux-headers-`uname-r` linux-source-$YourKernelsVersion
cd /usr/src
tar xjf linux-source-$Version.tar.bz2


kernels Makefile has a target M=$DIR you can use to build single modules. However, running this in /usr/src/linux-source-$Version fails, at least on my box, since I had not used it to actually build a kernel. Header files of a complete Build are missing, I understand. For this reason, we use linux-headers-`uname -r`-directory. However, this directory does not contain everything we need, most of the header files reside in linux-headers-$Version-common dir. I simply copied its contents into linux-headers-`uname -r`. There are propably more elegant ways...

cd linux-headers-`uname -r`
cp -rf ../linux-headers-$Version-common/* .


Figure out what directory your wanted module resides in. For me this is drivers/net/wireless/ath5k

cd linux-headers-`uname -r`
mkdir -p Path/To/Module
cp -rf ../linux-source-$Version/Path/To/Module/* Path/To/Module
make -M=Path/To/Module


You propably know how to go on yourself, but for completeness sake:
Now you have compiled the module, check it runs properly. You may have to rmmod earlier versions of the module.
insmod Path/To/Module/Module.ko

If it works properly, its time to install it to your system:

cd /lib/modules/`uname -r`
mkdir -p Path/To/Module


if there is another build of the module you just compiled, you may want to do a backup:

mv Path/To/Module/Module.ko Path/To/Module/Module.ko.bak
cp /usr/src/linux-headers-`uname -r`/Path/To/Module/Module.ko Path/To/Module
depmod -a


Congratulations! If you made it this way, you finished. For me, it's now time to setup hostap.
Bhaskar Chowdhury
Chat Google Talk: unixbhaskar Skype: unixbhaskar Y! messenger: unixbhaskar
Contact Me StumbleuponFacebookDiggTwitterLinkedinRedditWordpressTechnorati

No comments:

Post a Comment