5

I have written a simple hello world kernel module, compiled it and install in /lib/modules/kernel_version/extra/ path.

With insmod its getting loaded properly, but with modprobe i am getting an error

modprobe: FATAL: Module hello_world.ko not found.

I have installed all the per-requisite.

Here is Makefile to compile and install:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD)  modules
make -C /lib/modules/$(shell uname -r)/build  M=$(PWD)  modules_install

Please tell me how to get is done.

Thanks in Advance.

osgx
  • 90,338
  • 53
  • 357
  • 513
Usr1
  • 369
  • 1
  • 6
  • 15

2 Answers2

10

This is because modprobe inserts modules by reading a file called modules.dep under /lib/modules/$(shell uname -r)/. So after compiling and installing your module make sure you recreate this dependency file once again.

Here is how it is done

  1. After installation of your module, check whether it is copied to /lib/modules/
  2. if it is found, then go to -> /lib/modules/$(shell uname -r)/ and use depmod command to create the dependency list of your new module.


Once this is done, you will be able to locate your module name under the file /lib/modules/$(shell uname -r)/modules.dep.

After this you can use modprobe to insert your module.

EDIT:

Below is the Makefile I used to build with root permission and test.

target ?= hello_world
obj-m = $(target).o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules_install

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Santosh A
  • 5,173
  • 27
  • 37
  • Same error: once i run Makefile module is already located in /lib/modules/$(shell uname -r)/modules.dep . – Usr1 Nov 24 '14 at 06:03
  • INSTALL /home/vishal/test/linux_dd/hello_world.ko Can't read private key DEPMOD 3.13.0-24-generic make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-24-generic' – Usr1 Nov 24 '14 at 06:05
  • above is some output snippet from makefile. – Usr1 Nov 24 '14 at 06:06
  • 1
    Did you use `root` permission when using `modules_install` and `depmod` ? If not then use `sudo` and try again – Santosh A Nov 24 '14 at 06:09
  • sorry , i did not get you. please explain. – Usr1 Nov 24 '14 at 06:45
  • With the above mentioned `Makefile` I compiled and installed a module `hello_world`. then used `depmod` command in the /lib/modules/(uname -r) directory to create/recreate `modules.dep` file. After which I tried `modprobe` command to insert my module – Santosh A Nov 24 '14 at 06:48
  • 2
    try using strace with the modprobe command. you should be able to see what path names it's trying to access when searching for the file. – Gil Hamilton Nov 24 '14 at 13:03
4

I had the same problem once. My problem was that I didn't remove the extension when giving the command. I.e.

modprobe foo.ko

gives the above error. But this:

modprobe foo

works!

Maximilian Ast
  • 3,369
  • 12
  • 36
  • 47
nLasse
  • 41
  • 1