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?
Our current recommended approach is to use this project template. If you want to test it, the steps are:
- Clone 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 masterprocess after committing your changes to the repository
@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?
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 to your own kernel module should work.
@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?
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
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?
I’m having exactly the same problem.
depmod can’t run due to read-only filesystem.
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
OK, so its no problem if
modprobe thinks the module isn’t installed?
Why is it that we can’t use
depmod? Is it possible to do all the work of
modprobe using just
It wasn’t a problem for me. I’m able to utilize my module after
insmod even though
You can also restart the module with
rmmod my_module followed by
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.
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.