Custom kernel modules / firmware - best practices

We currently use two custom kernel modules in our multi-container app (iwlwifi and v4l2loopback) and currently the way we ensure they are loaded is via a standalone kernel module container, whose sole purpose is to bind mount the /lib/modules and /lib/firmware folders using the io.balena.features.kernel-modules and io.balena.features.firmware labels in docker-compose.yml, modifying them to be read-write and installing the modules / firmware. Then, all other containers that require the device functionality also have the two labels applied and can use the devices.

This feels like a less than ideal approach as it requires a separate container just to deploy the modules, and then I validate that the modules are actually installed in the containers that use them. We use a custom base image that is based off of balenalib/jetson-nano-ubuntu and I’m wondering if it would be possible build the drivers and load them into the base image. My only question is how to actually do this, because presumably they can’t be installed in the builder, and rather they would need to be installed using the startup script. The problem is that we have multiple containers that require the modules, so I’m not sure I would want multiple containers having read/write access and attempting to install the modules.

Has anyone else used custom kernel modules, and if so how is it typically done? Is the kernel module container the best approach, or is there a different way to do this that would work better?

Hey there!
As you guessed, the current way of adding custom kernel modules is to have a container build it at runtime and insmod the modules. We have an example repo that shows how to do that here

The problem is that we have multiple containers that require the modules, so I’m not sure I would want multiple containers having read/write access and attempting to install the modules.

As for this, I find it a bit confusing. If you follow the approach in the repo I linked above, once the custom module is inserted, it should be available to other containers with io.balena.features.kernel-modules and io.balena.features.firmware labels.

Let us know if this works for you or if you have other questions.
Thanks