Adding New Kernel Modules
From Freespire
Building a kernel module that is not yet included in the los-kernel-extras package is a two step process. First you need to create a source package for it. Then you need to add a build directory to the los-kernel-extras package. If you are lucky, the source will already be available as a debian package. You might search for this at | Debian or | Ubuntu package servers. We will use the example of fuse, a kernel module that implements user space file systems. As of right now, fuse-source version 2.5.3-2.1 is available in Debian unstable (sid), so we will use that. We put these lines in our sources.list:
deb ftp://ftp.debian.org/debian sid main contrib non-free deb-src ftp://ftp.debian.org/debian sid main contrib non-free
and install the source package
# sudo apt-get update # sudo apt-get install fuse-source
This installs the file /usr/src/fuse.tar.bz2 which contains the fuse source code. Now we need to modify the los-kernel-extra-2.6.14 package to add a fuse subdirectory. We'll assume that you have already run "apt-get source los-kernel-extra-2.6.14", changed directory into the resulting los-kernel-extra-2.6.14-2.6.14.4 directory, and installed the necessary build dependencies as described in the previous section. Now we will create a fuse subdirectory and copy one of the existing Makefiles into it as a template:
# mkdir fuse # cp cloop/Makefile fuse/
Now we need to edit the Makefile to get the module to build. There is no straightforward method for doing this, but the Makefiles in the various subdirectories may give some ideas. Also, the unpacked module source may contain a debian/rules file that will show you what needs to be done. There are three make targets in the file: build, install, and clean. For historical reasons, these names are not quite accurate descriptions of what the targets should do: the build target should unpack the source (unless it is already unpacked) and the install target should build *and* install the kernel module. Here is the Makefile for the fuse module:
NAME = fuse
build:
if [ ! -e /usr/src/modules/$(NAME) ]; then \
cd /usr/src && tar xfj $(NAME).tar.bz2; \
fi
install:
cd /usr/src/modules/$(NAME)/kernel && \
./configure \
--host=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) \
--build=$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) \
--prefix=/usr \
--mandir=\$${prefix}/share/man \
--infodir=\$${prefix}/share/info \
--with-kernel="/usr/src/linux" \
--disable-lib --disable-util \
--disable-example
make -C /usr/src/modules/$(NAME)/kernel all-y
make -C /usr/src/modules/$(NAME)/kernel DESTDIR=$(CURDIR)/../debian/tmp install-y
echo lib/modules/$(DHH_EXVER)/kernel/fs/$(NAME)/$(NAME).ko >> ../debian/$(DHH_NAME).install
clean:
rm -rf /usr/src/modules/$(NAME)
The build target just unpacks the tarball. The install target is taken directly from the debian/rules file in the fuse/kernel directory, except for the echo command on the last line. That echo command adds a line to the .install file to make sure that the kernel module gets included in the resulting deb. Note the use of the magic DHH_EXVER variable in the install rule: this is the kernel version number extended with the kernel's build suffix (e.g. "-smp".) The DHH_KVER variable is just the kernel source version number. The DHH_NAME is also magic, it contains the full name of the package we are building (e.g. los-kernel-extra-2.6.14.) The clean rule just removes the unpacked source.
Once you have written rules to build and install the kernel module, you need to modify the control files so that the module actually will get built. Edit the file debian/rules.conf and add a line WORKING+=fuse to get the module to be built. It is also necessary to add the fuse-source package to the Build-Depends list in debian/control.
Finally, if you plan to install the package on more than one machine, upload the package to any apt repository, or if you plan to submit your changes to us for inclusion in the standard kernel package (which you should) you should modify the los-kernel-suite-2.6.14 package so that it pulls in the fuse-utils package which is required for using the fuse kernel module. This means apt-getting the los-kernel-source-2.6.14 source, editing the debian/control file to add fuse-utils to the dependency list, adding a changelog entry to bump the version number, and then using dpkg-buildpackage to build the package.

