In today’s tutorial, we’ll see how to use Dynamic Kernel Module Support (DKMS) to build kernel modules in Nitrux.
Difficulty: ★★★☆☆
📜 Table of Contents
Building DKMS drivers using Distrobox
The gist of the tutorial is the following: To build a module using DKMS on a Distrobox container, we need to copy the kernel headers from the host to the container, install DKMS on the container, obtain the driver we want to build, and then add the built modules to the host’s root directory.
So, first, we need to install DKMS on a container; let’s assume we use a container similar to the tutorial to use Distrobox. Again, we will use the option –no-install-recommends to avoid installing a kernel package in the container; this way, we avoid future problems when building the modules.
distrobox-enter --name debian12-distrobox -- sudo apt install -y --no-install-recommends dkms
Next, we need to copy the kernel headers on our root directory to any directory in our home. We must do this on a tab where we’re not inside the container.
cp -r /usr/src/linux-headers-$(uname -r) $(pwd)
Then, we copy the resulting directory to /usr/src in the containers’ root.
distrobox-enter --name debian12-distrobox -- sudo cp -r linux-headers-$(uname -r) /usr/src/
For this tutorial, we’ll build the modules for Anbox that Waydroid uses; the procedure for other modules might be slightly different.
So, download the Anbox modules from this repository and extract the archive. Then, we (as indicated by the README on that repository) copy the module sources to /usr/src on the container’s root. Assuming the archive was extracted to our home directory, the commands would be as follows.
- 🔰 Information: Since Nitrux 2.8.0, we include Waydroid by default; the procedure below is not necessary to use it. It’s only an example of this tutorial. To use Waydroid in Nitrux, see our tutorial about Software Management.
- 🔰 Information: Notice that the resulting directory path is ~/$REPOSITORY-BRANCH/$DRIVER/$VERSION, where DRIVER/$VERSION is essential as it has to match when using the command later.
distrobox-enter --name debian12-distrobox -- sudo cp -r ~/anbox-modules-master/ashmem-1 /usr/src/ distrobox-enter --name debian12-distrobox -- sudo cp -r ~/anbox-modules-master/binder-1 /usr/src/
Before building the modules, we need to create the directory structure in /lib. To do this, run the following command.
distrobox-enter --name debian12-distrobox -- sudo mkdir -p /lib/modules/$(uname -r)
Then, we must create a symlink to the directory. To do this, run the following command.
distrobox-enter --name debian12-distrobox -- sudo ln -svf /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build
And now, we can build the modules with DKMS. To do this, run the following command.
- ⚠️ Important: The Liquorix kernel is not signed, which means that DKMS will display an error in this regard; that’s expected.
- 🔰 Information: Notice that the command format is $DRIVER/$VERSION, which matches the directory path.
distrobox-enter --name debian12-distrobox -- sudo dkms install ashmem/1 distrobox-enter --name debian12-distrobox -- sudo dkms install binder/1
Once DKMS finishes building the modules, it will display their location in /lib/modules/$KERNEL_RELEASE/updates/DKMS/, so now we copy these files from the container to our home and then copy them to the root directory of Nitrux. First, let’s copy the files from the container’s root directory to any directory on our home. For this step, we have to enter the container. Otherwise, when we run the command to copy the files, it will attempt to copy files from the hosts’ root; once that’s done, type exit.
- ⚠️ Important: The command below creates, copies, edits, or moves files in the root directory; see XFS Features and Root Immutability in Nitrux.
distrobox-enter --name debian12-distrobox cp -r /lib/modules/$(uname -r)/updates/dkms/* $(pwd) exit
Loading the built DKMS modules on Nitrux
Now, on a separate tab outside of the container, we can copy the files to the root directory of Nitrux and tell DKMS to auto-install them.
- ⚠️ Important: The commands below create, copy, edit, or move files in the root directory; see XFS Features and Root Immutability in Nitrux.
sudo cp -r *.ko /lib/modules/$(uname -r)/updates/dkms/ sudo dkms autoinstall -k $(uname -r)
Then, we build the list of module dependencies with depmod again and load the modules with modprobe to use them immediately.
sudo depmod sudo modprobe -a ashmem_linux binder_linux
Or, we can add a configuration file to load the modules during boot. The file should be in the path /etc/modules-load.d and can have any name.
>> anbox-modules.conf printf "%s\n" \ '# Load Anbox ashmem and binder modules' \ '' \ 'ashmem_linux' \ 'binder_linux' \ '' sudo mv anbox-modules.conf /etc/modules-load.d/
Now, the modules will be loaded when the distribution boots.
That’s it; this concludes today’s tutorial.