On Red Hat Enterprise Linux, it is sometime desireable to compile a kernel module that is not included with the standard distribution. This document describes the basic procedure.
You will need a stock Red Hat kernel installed as well as the appropriate kernel-devel package. For example, on an SMP system, the following two packages should be installed (the version number may be different of course).
In addition, you need the source for the module you wish to compile. With RHEL, the easiest way to get the correct source for your current kernel is with up2date as follows.
[root@coma ~] up2date --get-source kernel-smp
This will put the source RPM in /var/spool/up2date. Install it with RPM.
[root@coma ~] rpm -ivh /var/spool/up2date/kernel-2.6.9-34.EL.src.rpm
Now run rpmbuild to extract and prepare the kernel sources. The prepare phase of rpmbuild will extract the source from the archive, then apply all of the Redhat patches.
[root@coma ~] cd /usr/src/redhat/SPECS/ [root@coma BUILD] rpmbuild -bp kernel-2.6.spec
You will find the complete kernel source in /usr/src/redhat/BUILD/kernel-2.6.9 (the exact directory might vary if your kernal version is different).
Copy the source for the module that you wish to compile into the kernel development tree.
[root@coma ~] uname -r 2.6.9-34.ELsmp [root@coma ~] cp -r /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9/fs/reiserfs/. \ /lib/modules/$(uname -r)/build/fs/reiserfs/
Now you have to run menuconfig and enable the module (reiserfs in this case).
[root@coma ~] cd /lib/modules/$(uname -r)/build [root@coma build] make menuconfig
Now you can compile the module.
[root@coma ~] cd /lib/modules/$(uname -r)/build [root@coma build] make SUBDIRS=fs/reiserfs/ modules
Now the module should be compiled. You will find the module in the directory where the source is located.
Depending on the module, you may have to create a new directory. In this example, the reiserfs directory doesn’t exists. We create it, copy in the module, change it’s permissions and run depmod to update the module list.
[root@coma ~] cd /lib/modules/$(uname -r) [root@coma 2.6.9-34.ELsmp] mkdir kernel/fs/reiserfs [root@coma 2.6.9-34.ELsmp] cp build/fs/reiserfs/reiserfs.ko kernel/fs/reiserfs/ [root@coma 2.6.9-34.ELsmp] chmod 744 kernel/fs/reiserfs/reiserfs.ko [root@coma 2.6.9-34.ELsmp] depmod
Now you can load the module with modprobe.
[root@coma ~] modprobe reiserfs
If all goes according to plan, the module should load and be usable.
The information above was inspired by the following site.
This site is geared more at adding a third party driver which is also a very useful thing.