3
votes

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.

2

2 Answers

10
votes

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
2
votes

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!