Translation(s): English - Русский


This page describes how to create Debian packages containing Linux kernel modules sources to be built automatically upon installation using DKMS.

Originally discussed: <1255800860.2488.616.camel@localhost>


Introduction

As documented in dkms(8), the DKMS ("Dynamic Kernel Module Support") framework allows kernel modules to be dynamically built for each kernel on your system in a simplified and organized fashion. Such building of kernel modules happens "on the fly" (mainly at package installation time) on the local system, rather than building them centrally on the Debian infrastructure.

The "binary" Debian package contains only sources and depends on the dkms package. See ddcci-dkms as an example.

Using DKMS vs binary module packages has the following advantages:


Package Configuration

DKMS config

For each "binary" DKMS package, create a file named "package-name.dkms" in debian folder, for example debian/mydriver-kernel-dkms.dkms. If there's only 1 binary package, the file may be named simply debian/dkms. These files should either follow the format documented in the dkms manual page or contain a path (relative to the package's root) to a relevant upstream DKMS config file. A typical example:

PACKAGE_NAME="mydriver"
PACKAGE_VERSION="1"
AUTOINSTALL=yes

BUILT_MODULE_NAME[0]="$PACKAGE_NAME"
DEST_MODULE_LOCATION[0]=/extra
MAKE[0]="make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build"
CLEAN="make -C ${kernel_source_dir} M=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"

Notes:


Module Makefile

As commands to make and clean module binaries are provided in DKMS config files, a Makefile for a DKMS module usually only needs to append its object filenames to obj-m, for example:

obj-m += mydriver.o

An upstream Makefile may contain rules, that need to be moved to the DKMS config file and adapted to use DKMS variables similarly as shown in the example config above.


rules

In a generic case, all that is necessary is to add --with dkms to dh arguments:

 #!/usr/bin/make -f

%:
        dh $@ --with dkms

This will trigger dh_dkms to generate postinst and prerm for each binary package for which a DKMS config file exists.

ToDo: there must be no space before #!/usr/bin/make -f but it is then inproperly rendered by this wiki.


control


install

Each "binary" DKMS package's source files and Makefile must be installed in /usr/src/${PACKAGE_NAME}-${PACKAGE_VERSION}/ folder, where PACKAGE_NAME and PACKAGE_VERSION values are the ones from the corresponding DKMS config. For example if kernel module files and Makefile for mydriver defined in the config above are located in kernel subfolder of the source package, its install-file could look like this:

kernel/* /usr/src/mydriver-1/


Related resources

Debian links:

External guides:


Help wanted

ToDo: other documentation that might need changes:


CategoryKernel | CategoryPackaging