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>
Contents
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:
On systems that use SecureBoot, it allows to sign the modules with the Machine Owner Key (MOK) (keys need to be generated, enrolled and configured for module signing).
- DKMS packages are easily portable between distributions with different kernel toolchains.
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:
If "#MODULE_VERSION#" is used as PACKAGE_VERSION, it will be replaced with the upstream version of the package by dh_dkms, but this will require to #install sources into a folder with a version-dependent name.
DEST_MODULE_LOCATION[0] is important only when the module replaces an in-tree module. Otherwise use something like /extra or /updates or /updates/dkms.
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 dkmsThis 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
dh-dkms must be added to Build-Depends: (since DebianBookworm it is a separate package from dkms).
As usually, ${misc:Depends} must be added to each binary package's Depends: (it will be expanded to contain dkms).
By convention, "binary" DKMS packages are usually named "drivername-kernel-dkms" (for example Package: mydriver-kernel-dkms) and they provide virtual packages named "drivername-kernel" (for example Provides: mydriver-kernel).
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:
