# Install linux headers for kernel module development

**URL:** <https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590>\
**Category:** Product support\
**Created:** [February 18, 2018, 10:20pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590 "2018-02-18T22:20:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![CWright017](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/cwright017/32/753_2.png) [@CWright017](https://forums.balena.io/u/CWright017)\
**Post date:** [February 18, 2018, 10:20pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/1 "2018-02-18T22:20:54Z")

</div>

I’m trying to compile v4l2loopback, a kernel module to allow for virtual video devices. ResinOS seems to be missing the build dir inside the kernel directory. Is there a way to install the headers on Resin? Could I add them to the SD card?

---

<div class="post-metadata">

**Author:** ![lekkas](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/lekkas/32/78_2.png) [@lekkas](https://forums.balena.io/u/lekkas)\
**Post date:** [February 21, 2018, 1:07pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/3 "2018-02-21T13:07:27Z")

</div>

Hi @CWright017,

Our current recommended approach is to use [this project template](https://github.com/resin-io-playground/kernel-module-build). If you want to test it, the steps are:

- Clone [https://github.com/resin-io-playground/kernel-module-build](https://github.com/resin-io-playground/kernel-module-build)
- Modify it according to your needs (see README in the project)
- Build your kernel modules as part of the `git push resin master` process after committing your changes to the repository

---

<div class="post-metadata">

**Author:** ![CWright017](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/cwright017/32/753_2.png) [@CWright017](https://forums.balena.io/u/CWright017)\
**Post date:** [February 21, 2018, 10:21pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/4 "2018-02-21T22:21:11Z")

</div>

@lekkas thank you that’s amazing. Upon building the module, it has a Makefile with an install location of /lib/modules/build… but when I tired building the module in a separate docker file and copying it over to my resin container - that location was either missing or read only. Will this approach solve that?

---

<div class="post-metadata">

**Author:** ![lekkas](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/lekkas/32/78_2.png) [@lekkas](https://forums.balena.io/u/lekkas)\
**Post date:** [February 22, 2018, 12:17pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/5 "2018-02-22T12:17:28Z")

</div>

hi @CWright017 ,

The module build and install process will take place on our builders and the resulting module should end up under `/lib/modules/$(shell uname -r)/build` in the generated container image. So yes, adapting the template project and the respective [example template Makefile](https://github.com/resin-io-playground/kernel-module-build/blob/master/example_module/Makefile) to your own kernel module should work.

---

<div class="post-metadata">

**Author:** ![CWright017](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/cwright017/32/753_2.png) [@CWright017](https://forums.balena.io/u/CWright017)\
**Post date:** [February 24, 2018, 11:30am UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/6 "2018-02-24T11:30:25Z")

</div>

@lekkas thanks for the update! Module build worked fine, I copied the build.sh script to my own project - although there is no `/lib/modules/$(shell uname -r)/build` dir only a `/lib/modules/$(shell uname -r)` dir, so using modprobe won’t work, but insmod seems to work fine.

I was just wondering, is the lack of `build` dir a raspian base image thing? Or have I missed a step?

---

<div class="post-metadata">

**Author:** ![dysri](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dysri/32/1186_2.png) [@dysri](https://forums.balena.io/u/dysri)\
**Post date:** [October 4, 2018, 1:17am UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/7 "2018-10-04T01:17:55Z")

</div>

Hi @lekkas ,

I’m currently experiencing a related issue. I followed the ‘kernel-module-build’ example, and successfully built my out-of-tree module into a `my_module.ko` file.

Installing the module with `insmod my_module.ko` causes a subsequent `lsmod` command to list ‘my\_module’, but `modprobe my_module` fails to find the module, stating:

> `modprobe: FATAL: Module my_module not found.`

I suspect this is related to an inability to access the `/lib/modules/` due to its ‘read-only filesystem’ permissions, which prevents me from running `depmod -a` or otherwise copying/linking my module into the appropriate directory.

Is there a workaround that would allow me to properly install and load the module during startup of the container?

---

<div class="post-metadata">

**Author:** ![seb](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@seb](https://forums.balena.io/u/seb)\
**Post date:** [October 12, 2018, 5:18pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/12 "2018-10-12T17:18:58Z")

</div>

I’m having exactly the same problem. `depmod` can’t run due to read-only filesystem.

---

<div class="post-metadata">

**Author:** ![dysri](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dysri/32/1186_2.png) [@dysri](https://forums.balena.io/u/dysri)\
**Post date:** [October 12, 2018, 7:07pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/13 "2018-10-12T19:07:46Z")

</div>

I’ve since resolved my issue. Running `insmod $mod_dir/my_module.ko` successfully loads the module. You will also need to load any dependencies with `insmod` directly. You cannot use `modprobe` or `depmod`.

---

<div class="post-metadata">

**Author:** ![seb](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@seb](https://forums.balena.io/u/seb)\
**Post date:** [October 12, 2018, 7:21pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/14 "2018-10-12T19:21:50Z")

</div>

OK, so its no problem if `modprobe` thinks the module isn’t installed?  
Why is it that we can’t use `modprobe` and `depmod`? Is it possible to do all the work of `modprobe` using just `insmod`?

---

<div class="post-metadata">

**Author:** ![dysri](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dysri/32/1186_2.png) [@dysri](https://forums.balena.io/u/dysri)\
**Post date:** [October 12, 2018, 7:45pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/15 "2018-10-12T19:45:54Z")

</div>

It wasn’t a problem for me. I’m able to utilize my module after `insmod` even though `modprobe` fails.  
You can also restart the module with `rmmod my_module` followed by `insmod`.  
My understanding regarding the file permissions is that resin constrains what’s accessible and modifiable by the end user after the build steps (even during the build steps), for stability and security reasons. You can start reading up on specifics [here](https://resinos.io/docs/architecture/).

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [October 12, 2018, 8:31pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/16 "2018-10-12T20:31:11Z")

</div>

`insmod` is what should be used indeed for custom built out-of-tree kernel modules. `modprobe` can be still useful in other cases though, but the module has to be already registered when the OS image is built.

As for the read-only filesystem - it also reduces the chance of SD card corruption due to various reasons like power failures, etc.

---

<div class="post-metadata">

**Author:** ![jkridner](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jkridner/32/4982_2.png) [@jkridner](https://forums.balena.io/u/jkridner)\
**Post date:** [December 31, 2020, 6:08pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/17 "2020-12-31T18:08:33Z")

</div>

For

`./build.sh build --device beaglebone-green-wifi --os-version 2.58.3+rev4 my_module`

I keep getting an error that headers aren’t found.

I did a list and will try `--device beaglebone-black --os-version 2.58.3+rev4.dev`.

Is there a reason the latest versions aren’t there for all devices? Is it OK to just use `--device beaglebone-black`? I mean, it should be the same kernel.

---

<div class="post-metadata">

**Author:** ![jkridner](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jkridner/32/4982_2.png) [@jkridner](https://forums.balena.io/u/jkridner)\
**Post date:** [January 3, 2021, 10:01pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/20 "2021-01-03T22:01:09Z")

</div>

The module built using beaglebone-black headers, but I’m getting funny behavior where the iio subsystem stops responding. Is this the same kernel as for beaglebone-green-wifi?

BTW, I’m not able to tell what beagleboard patch-level a kernel is at using `uname -a`. The 5.4.70-ti kernel is now at r20. It could be possible just to submit the patches I need to the beagleboard kernel.

---

<div class="post-metadata">

**Author:** ![acostach](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@acostach](https://forums.balena.io/u/acostach)\
**Post date:** [January 6, 2021, 10:02am UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/22 "2021-01-06T10:02:38Z")

</div>

Hi Jason,

The kernel headers are published and available for the versions that are listed in the dashboard for image download. For the Beaglebone Green Wireless the 2.58.3+rev4 headers are currently available only in staging, so you can switch “cloud” to “staging” in [https://github.com/balena-os/kernel-module-build/blob/93da0fefec03692c0b5a819355d599b449b9c5c7/build.sh#L5](https://github.com/balena-os/kernel-module-build/blob/93da0fefec03692c0b5a819355d599b449b9c5c7/build.sh#L5) to get the headers from there.

Yes, all beaglebone use the same kernel, and 2.58.3+rev4 uses the kernel revision 5.4.70-ti-r19, as visible [here](https://github.com/balena-os/balena-beaglebone/blob/be012cf32c7593ce010f85db6d29aa3cd77a8cf1/layers/meta-balena-beaglebone/recipes-kernel/linux/linux-beagleboard_5.4.bb#L23).

Do you need us to update to r20? Also, if you have some kernel module that you need in the OS and it is public, sure, you are welcome to PR it in the balena-beablebone repository.

---

<div class="post-metadata">

**Author:** ![jkridner](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jkridner/32/4982_2.png) [@jkridner](https://forums.balena.io/u/jkridner)\
**Post date:** [January 11, 2021, 2:16pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/24 "2021-01-11T14:16:32Z")

</div>

Please update to r21. I think there is already an effort to do so.

---

<div class="post-metadata">

**Author:** ![acostach](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@acostach](https://forums.balena.io/u/acostach)\
**Post date:** [January 11, 2021, 8:34pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/26 "2021-01-11T20:34:42Z")

</div>

Hi @jkridner,

v2.65.1+rev2 is now available in the staging dashboard for the Beaglebone Black and includes r21 as well as the HM3301 module, let us know if it works for you and we can bring it in production too.

---

<div class="post-metadata">

**Author:** ![jkridner](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jkridner/32/4982_2.png) [@jkridner](https://forums.balena.io/u/jkridner)\
**Post date:** [January 11, 2021, 8:35pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/27 "2021-01-11T20:35:43Z")

</div>

Awesome, thanks! Oh, btw, this is for BeagleBone Green Gateway, currently identified as BeagleBone Green Wireless in the production system.

BTW, I’m still getting the error I mentioned in [Update to custom OS version or kernel (confused by error in cloud dashboard)](https://forums.balena.io/t/update-to-custom-os-version-or-kernel-confused-by-error-in-cloud-dashboard/231503/11). So, I really don’t know how to trigger an update. I’ll see if it is possible in the staging server.

---

<div class="post-metadata">

**Author:** ![acostach](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@acostach](https://forums.balena.io/u/acostach)\
**Post date:** [January 11, 2021, 8:39pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/28 "2021-01-11T20:39:24Z")

</div>

@jkridner I deployed it for the Gateway in staging too, it’s already there at the same 2.65.1+rev2 version. The Gateweay board is scheduled to arrive on Wednesday, as soon as it arrives we can bring that one in production too.

Regarding the error you see, maybe you are trying to perform an update on a device that has the Beaglebone Gateway image flashed but it’s running in the production dashboard, where this new device type is not available yet?

---

<div class="post-metadata">

**Author:** ![jkridner](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jkridner/32/4982_2.png) [@jkridner](https://forums.balena.io/u/jkridner)\
**Post date:** [January 11, 2021, 8:59pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/29 "2021-01-11T20:59:18Z")

</div>

I used the process at [https://www.balena.io/docs/learn/more/masterclasses/advanced-cli/](https://www.balena.io/docs/learn/more/masterclasses/advanced-cli/) to move one of the (local) device to the staging server. The 2.65.1+rev2 update was then available in the GUI. Thanks!

For remotely deployed devices, is there a process for performing the ‘leave’ and ‘join’ operations on them?

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [January 11, 2021, 9:52pm UTC](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590/30 "2021-01-11T21:52:47Z")

</div>

Hi @jkridner, unfortunately once you perform the leave operation, the device becomes inaccessible. There is an option to replace the config.json on a remote device with one downloaded from the staging app dashboard, but this carries a lot of risk of putting the device in a bad state if anything goes wrong.

Here’s some info on working with the config json:

> **[Balena Device Debugging Masterclass - Balena Documentation](https://www.balena.io/docs/learn/more/masterclasses/device-debugging/#7-working-with-the-configjson-file)**

We do plan on deploying the new kernel to production, is this something that can wait until then?

[Next page](https://forums.balena.io/t/install-linux-headers-for-kernel-module-development/2590.md?page=2)
