In today’s tutorial, we’ll see how to use dkms to build kernel modules in Nitrux.

Difficulty: ★★★☆☆

📜 Table of Contents

  1. Building dkms drivers using Distrobox
  2. Loading the built dkms modules on Nitrux

Building dkms drivers using Distrobox

The easiest way to build kernel modules using dkms is to get the module sources and build them directly with Nitrux. If it were the case that the modules don’t build, we could build them using Distrobox by using the kernel headers from the host on the container and then add the built modules to the host’s root directory, in this case, Nitrux.

For this example, we’ll build the modules for Anbox that Waydroid uses. Let’s assume we use a similar container as the tutorial to use Distrobox as we did before.

  • 🔰 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. To use Waydroid in Nitrux, see our tutorial about Software Management.

So, first, we need to install dkms if it’s not already installed. Again, we will use the option –no-install-recommends to avoid installing a kernel package in the container; this way, we avoid a problem with dkms.

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 container. Using the container we created in this tutorial as an example, the command would be as follows.

distrobox-enter --name debian12-distrobox -- sudo cp -r linux-headers-$(uname -r) /usr/src/

Next, we must 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.

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.

  • Note: The Liquorix kernel is not signed, which means that dkms will display an error in this regard; that’s expected.
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.

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.

sudo cp -r *.ko /lib/modules/$(uname -r)/updates/dkms/
sudo dkms autoinstall -k $(uname -r)

Then, we rebuild the list of module dependencies with depmod 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.