How to build kernel module rpm's

Using the new kernel module convention

Starting with Scientific Linux 3.0.2 we started using an rpm convention when we need to install kernel modules, that are separate from the main kernel. The rpm name kernel-module--.
The most famous of these is the new openafs kernel module called kernel-module-openafs-2.4.21-20.EL. But for this example, we are going to build a kernel-module rpm for the broken agpart, that does not work on i810 video cards. Please note that this is not the only way to build these rpm's. There are other more elegant ways.

Step 1

For this example you need to have and know

Step 2

Download this generic spec file kernel-module-mymodule.spec and save it in /usr/src/redhat/SPECS/
And then edit it to meet your needs. Below are the main things you should edit.

# The kernel version you are building for
%define kernel 2.4.21-20.0.1.EL

Change this to be whatever kernel version you are building for, see step 1.

# The name of the module you are supplying
%define modname agpgart

Whatever the .o file is called is best.

# The version of the module
%define modversion 0.99

This is usually found by doing a 'grep -i version' on the .h file of whatever module you are building. If you are doing this for a prebuild binary, then it's whatever the vendor told you the version is.

# The path to the module, after it is installed
%define modpath /lib/modules/%{kernel}/kernel/drivers/char/agp

See step 1

# Which revision are we on
%define pkgrelease 1.SL

This is so if you messed up on this rpm, or want to add changes, you just increase this number, and rebuild.

# Is this a new module, or are we replacing an existing module
# 1 - new module
# 0 - replacing an existing module
%define newmodule 0

In some cases you might be adding a completely new module, that isn't in a stock kernel rpm, such as openafs. If that is the case, you want to set this to 1. If you are replacing a kernel module, such as agpgart, then you want to set this to 0.
This will change post install scripts, as well as the names of modules.

License: GPL
Most of what you do will probrubly be GPL, but don't do something like put proprietary drivers in, and then leave this as GPL. So be sure to make the right license.

Packager: Troy Dawson
Change this so that people know who did it. Otherwise they'll think I did this.

%changelog
* Wed Dec 08 2004 Troy Dawson 1.SL
- created the generic module spec file for easy customization

Be sure to put an entry in the changelog. This might seem like alot of extra work, but really, it only take a minute or two, and when you come back to this rpm 6 months from now, you'll be glad that you did.

Step 3

Copy your driver to /usr/src/redhat/SOURCES/
If using this spec file, you will need to name it (module).o.(kernel), so for this example we will copy our recompiled agpgart driver to
/usr/src/redhat/SOURCES/agpgart.o.2.4.21-20.0.1.EL

Step 4

Build the rpm.
cd /usr/src/redhat/SPECS
rpmbuild -ba kernel-module-mymodule.spec


Written by Troy Dawson dawson@fnal.gov
December 8, 2004