Rebuilding a single kernel module
Posted by gnurbs on Wed 22 Jul 2009 at 23:27
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...
[ Send Message | View Steve's Scratchpad | View Weblogs ]
One thing that has changed in recent kernels is that /lib/modules/$(name -r)/updates is checked for modules first.
So you don't need to backup and overwrite the existing module, just place your new one in the updates directory and it will be loaded in preference to the existing one.
[ Parent | Reply to this comment ]
Green text on white background is a really poor choice.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
- mkdir -p /Path/To/Module
I assume the leading '/' in the directory chain is incorrect.
Also, I noticed that you copied the headers into your linux source directory, but then proceeded to copy the module source to the headers directory and compile it from there. Any reason why you didn't just compile it in the source directory, after copying headers?
- mv Path/To/Module/Module.ko Path/To/Module/Module.ko.bak
cp Path/To/Module/Module.ko /lib/modules/`uname -r`/kernel/Path/To/Module
So you've renamed Module.ko to Module.ko.bak. Then you try to copy the Module.ko that you've just renamed?
Lastly, and this is just being picky, I noticed that the current directory in your root prompt is always the home dir. You may want to put in something a little more informative, to indicate what dir you want to be in.
[ Parent | Reply to this comment ]
actually, these root-prompts where automatically inserted by the [code]-bb-tag I used. obviously not the best choice, with this and the readability problem...
anyway I removed them now.
@copy to source: actually, I left out one step. sorry for this :/ I did not copy the headers into the source dir, but the linux-headers-common into the linux-headers-dir - did not use the source dir, propably because I thought it would fail, just because it failed before (when I tried before realising that I needed the headers...)
that part you quoted is mostly trash, youre right... should be correct now
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
it should be "make M=Path/To/Module", as the "M" is a variable (processed by the makefile), not an option (recognized by make).
thanks.
[ Parent | Reply to this comment ]
sudo apt-get install linux-source-2.6.32 kernel-package linux-headers-`uname -r` cd /usr/src tar jxf linux-source-2.6.32.tar.bz2 cd linux-source-2.6.32 ln -s /boot/config-2.6.32-2-amd64 .config ln -s /usr/src/linux-headers-2.6.32-2-amd64/Module.symvers Module.symvers make modules_prepare make M=drivers/usb/misc/ sudo insmod drivers/usb/misc/usbsevseg.koThe above is my history slightly edited so please excuse any errors.
[ Parent | Reply to this comment ]
: root; mkdir /lib/modules/$(uname -r)/update : root; cp drivers/usb/misc/usbsevseg.ko /lib/modules/$(uname -r)/update/. : root; depmod -a : root; rmmod usbsevseg : root; modprobe -v usbsevseg insmod /lib/modules/2.6.32-2-amd64/update/usbsevseg.koStuart
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
/usr/src/linux-source-2.6.32# make M=fs/xfs
LD fs/xfs/built-in.o
Building modules, stage 2.
MODPOST 0 modules
and no xfs.ko-File was created. Any suggestions?
Hopefully anyone out there, who could help me!
[ Parent | Reply to this comment ]
make M=fs/cifs
and
make M=/absolute/path/to/fs/cifs
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]