Occasionally you may experience problems in a specific kernel module that requires a patch. Once patched, you can follow these directions to compile only the module affected, saving a bunch of time.
Assume the following, for this example:
- You are building a module for Ubuntu 3.2.0-21-generic kernel.
- Your source tree with the patched module is located in /usr/src/linux-source-3.2.0
- Your linux header source is located in /usr/src/linux-headers-3.2.0-21-generic
- Your working folder ( where you are building the new module ) is /usr/src/mytree
In this case, your EXTRAVERSION is -21-generic ( this is the specific flavor of the 3.2.0 kernel we are building ) this is important to note, and will be used later in this example.
Now to create your working folder and change into it:
mkdir /usr/src/mytree cd /usr/src/mytree
Now that you are in your working folder, you need to copy over your kernel configuration file and Module.symvers file.
cp /boot/config-`uname -r` .config cp /usr/src/linux-headers-3.2.0-21-generic/Module.symvers .
Now with those files in place, you need to change to your source folder and prep your work area by running a few make commands. These commands make use of the EXTRAVERSION we noted above:
cd /usr/src/linux-source-3.2.0 make EXTRAVERSION=-21-generic O=/usr/src/mytree oldconfig make EXTRAVERSION=-21-generic O=/usr/src/mytree prepare make EXTRAVERSION=-21-generic O=/usr/src/mytree outputmakefile make EXTRAVERSION=-21-generic O=/usr/src/mytree archprepare make EXTRAVERSION=-21-generic O=/usr/src/mytree modules SUBDIRS=scripts
At this point you are ready to compile the module you have patched. Suppose it is the drivers/net/wireless/rt2x00 module:
make EXTRAVERSION=-21-generic O=/usr/src/mytree modules SUBDIRS=drivers/net/wireless/rt2x00
At this point you should have a drivers/net/wireless/rt2x00 folder in your working folder ( /usr/src/mytree ) which contains the .ko module files.
Simply backup the old modules in /lib/modules/3.2.0-21-generic/kernel/drivers/net/wireless/rt2x00 , and replace them with your new ones, then reload or reboot to test the new modules!