55

I'm trying to get a kernel module to load at boot.

If I run insmod /path/to/module.ko, it works fine. But this has to be repeated every time I reboot.

If I run modprobe /path/to/module.ko, it can't find the module. I know modprobe uses a configuration file, but I can't get it to load the module even after adding /path/to/module.ko to /etc/modules.

What is the proper configuration?

sep332
  • 1,039
  • 2
  • 13
  • 24

4 Answers4

86

You can make a symbolic link of your module to the standard path, so depmod will see it and you'll be able load it as any other module.

sudo ln -s /path/to/module.ko /lib/modules/`uname -r`
sudo depmod -a
sudo modprobe module

If you add the module name to /etc/modules it will be loaded any time you boot.

Anyway I think that the proper configuration is to copy the module to the standard paths.

Jaime Soriano
  • 7,309
  • 2
  • 33
  • 45
  • 5
    If you *really* want, you can write "search /some/other/path" to /etc/depmod.conf or /etc/depmod.d/something, but I'd still suggest doing as Jaime suggested and copying or symlinking to /lib/modules/`uname -r`, where everybody expects modules to be. – ephemient Oct 22 '08 at 14:52
  • you can also rewrite include/config/kernel.release and recompile kernel. Your modules then will be in /lib/modules// – Jan Matějka Nov 16 '13 at 08:54
  • 1
    I just had to scracth my head a bit, until I discovered, that I was under `/lib/modules/` of *wrong* kernel version. So indeed, use that `uname -r`, at least to verify current kernel version... – hyde Nov 05 '14 at 16:29
  • I am currently building a docker system based on `linuxkit/alpine` where I want to load a kernel module. For a start I am trying to do [this test](https://github.com/linuxkit/linuxkit/tree/master/test/cases/020_kernel/011_kmod_4.9.x), but I don't even have a `/lib/modules/` folder not to speak of one for a kernel version nor a `modules.dep`. So after creating the paths, `depmod -a` still results in a `Segmentation fault`. Any hints? – BadAtLaTeX Jun 04 '19 at 12:56
  • since there is some different in depmod.conf among distros (such as Ubuntu include 'ubuntu' in search path). i think write your own conf is a rather than an elegant way. – Kevin Chan Sep 09 '22 at 03:31
13

Follow following steps:

  1. Copy hello.ko to /lib/modules/'uname-r'/misc/
  2. Add misc/hello.ko entry in /lib/modules/'uname-r'/modules.dep
  3. sudo depmod
  4. sudo modprobe hello

modprobe will check modules.dep file for any dependency.

VVN
  • 1,607
  • 2
  • 16
  • 25
tusharrnimje
  • 331
  • 2
  • 11
6

I think the key is to copy the module to the standard paths.

Once that is done, modprobe only accepts the module name, so leave off the path and ".ko" extension.

Ray Li
  • 2,311
  • 3
  • 17
  • 13
0

Per @Ray Li's answer, just following the steps below would suffice:

sudo -i
cp hello.ko /lib/modules/`uname-r`/
depmod
modprobe hello
Aaron Chen
  • 136
  • 9