Skip to content

Rebuilding a single kernel module

ahmadrezamontazerolghaem edited this page Feb 17, 2016 · 2 revisions

Rebuilding a single kernel module

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