# Custom kernel modules / firmware - best practices

**URL:** <https://forums.balena.io/t/custom-kernel-modules-firmware-best-practices/166994>\
**Category:** balenaOS\
**Created:** [July 30, 2020, 10:14pm UTC](https://forums.balena.io/t/custom-kernel-modules-firmware-best-practices/166994 "2020-07-30T22:14:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drcnyc](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@drcnyc](https://forums.balena.io/u/drcnyc)\
**Post date:** [July 30, 2020, 10:14pm UTC](https://forums.balena.io/t/custom-kernel-modules-firmware-best-practices/166994/1 "2020-07-30T22:14:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rahul-thakoor](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rahul-thakoor](https://forums.balena.io/u/rahul-thakoor)\
**Post date:** [July 31, 2020, 10:57am UTC](https://forums.balena.io/t/custom-kernel-modules-firmware-best-practices/166994/6 "2020-07-31T10:57:41Z")

</div>

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](https://github.com/balena-os/kernel-module-build)

> 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
