Using DKMS to build Asterisk's dahdi-linux modules


The XiVO application runs using Asterisk, an open-source telephony software. In order to work properly, this software uses DAHDI, a collection of open source drivers. Those drivers contain some modules that need to be recompiled every time the kernel of the machine is updated.
As of May 2019, the recompilation of those modules was done manually - that had to be done every time the kernel was updated, thus taking a lot of time that could have been used to do something else.
DKMS is a framework which allows automatic rebuilding of modules when a new kernel is installed. Getting those modules to build with DKMS allows them to build themselves automatically at every kernel update, thus saving precious time.

This article will guide you through what DAHDI is, explain what were the consequences of having to build its modules manually and how using DKMS solved those by allowing DAHDI’s modules to build themselves.

What is DAHDI?

DAHDI stands for Digium Asterisk Hardware Device Interface.

It is a collection of open source drivers (for Linux) which act as an interface with different kinds of telephony related hardware. DAHDI is made of two parts:

Here, we will focus on dahdi-linux, as dahdi-tools does not depend of the kernel version and therefore does not need to be recompiled when the kernel is updated.

The DAHDI modules are needed for several things in XiVO to work properly, among which figure the conference calls.

Problem: dahdi-linux had to be built manually

Contrary to most packages which can be installed on your machine regardless of your kernel version - provided that it’s not too old, some packages actually need to be built against the Linux kernel. This means that during their build process, they will need to access your kernel headers in /usr/src. A bad repercussion of this is that if you update your kernel version, the package will stop working. dahdi-linux is one of those packages, but there are many others, such as VirtualBox.

XiVO’s dahdi-linux package is slightly modified so it better suits the application’s needs. Unfortunately, this means that the building of the package needs to be done by the XiVO team - that was the case for each and every single kernel version, hence limiting users to a number of kernel versions, the ones for which the dahdi-linux-modules package had been built.

Building the packages ourselves for every kernel version had several drawbacks:

  • Since it was a manual operation, it cost precious time that could have been used doing something else;
  • It prevented clients from updating their kernel version until the corresponding dahdi-linux-modules package was built and uploaded;
  • Only a limited number of dahdi-linux-modules packages were built, so only a handful of kernel versions were supported;
  • Every kernel version meant a new dahdi-linux-modules version, which had to be deployed on every XiVO LTS manually;
  • Finally, the number of different dahdi-linux-modules packages was starting to get out of hand:

dahdi-linux-modules packages

Solution: building dahdi-linux with DKMS

DKMS stands for Dynamic Kernel Module Support.

It is a framework used to build Linux kernel modules. More specifically, it allows automatic rebuilding of modules every time a new kernel is installed. DKMS was made by Dell and is free software.

Its main goal is to recompile all DKMS modules when a new kernel version is installed, thus allowing drivers and other devices to continue working after a Linux kernel upgrade, so the user doesn’t have to recompile all the modules manually.
Another benefit of DKMS is that it allows the user to install new drivers on his system without the need for manual compilation, for an arbitrary kernel version.

Based on that knowledge, we decided to build dahdi-linux with DKMS, hence creating a new package, dahdi-linux-dkms, meant to replace the old dahdi-linux-modules. Here are some of its advantages:

  • It only has to be installed once and will then adapt itself to most kernel versions (provided they are not too old or too recent);
  • It adapts itself to new kernel versions automatically, as soon as you upgrade your system;
  • Several hundreds of kernel versions are supported, the only ones which are not supported being the ones whose source code is incompatible with the version of dahdi-linux you want to install (such as very old / very recent versions);
  • There is only one dahdi-linux-dkms package, contrasting with the multiple dahdi-linux-modules packages.

How does it work?

Automatic installation of dahdi-linux-dkms

To automatically install the package dahdi-linux-dkms, a dependency to dahdi-linux-dkms was added to the package asterisk.

Removal of the dahdi-linux-modules-* packages

The package dahdi-linux-dkms is meant to replace all the dahdi-linux-modules-* packages. If some of them are installed, they will be directly purged by the xivo-upgrade script.

When installing the package, the lines in the xivo_install script responsible for the installation of dahdi-linux-modules were simply removed.

Installing the standard kernel version during the XiVO installation process

A dependency to the packages linux-headers-amd64 and linux-image-amd64 was added to the package dahdi-linux-dkms. The reason for that is that in lots of cases, a XiVO machine can work without having the kernel headers’ source code stored in /usr/src. However, this is crucial for DKMS, as it cannot work without the kernel headers source.

Installing those packages is not without consequences. Yes, it will download the headers and the image, but it will do that for the standard kernel of your Debian version:

  • 3.16.0-9 for Linux 8 Jessie.
  • 4.9.0-9 for Linux 9 Stretch.

Wiki page: https://en.wikipedia.org/wiki/Dynamic_Kernel_Module_Support

Man page: https://manpages.debian.org/stretch/dkms/dkms.8.en.html

Simplistic DKMS walk-through: https://help.ubuntu.com/community/DKMS

Good tutorial of all the DKMS commands we used: https://wiki.kubuntu.org/Kernel/Dev/DKMSPackaging