2014-11-24 220 views
2

我编写了一个简单的hello world内核模块,编译并安装在/lib/modules/kernel_version/extra/的路径中。找不到模块:modprobe

随着insmod它得到正确加载,但modprobe我得到

modprobe: FATAL: Module hello_world.ko not found. 

我已经安装了所有的每一个必要的错误。

这里是Makefile进行编译和安装:

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

请告诉我怎么去完成。

在此先感谢。

回答

6

这是因为modprobe插入通过读取文件的模块称为modules.dep/LIB /模块/ $(壳UNAME -r)/。所以在编译和安装模块之后,请确保重新创建这个依赖文件。

这里是它是如何做

  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.

这之后您可以使用modprobe您插入模块。

编辑:

下面是我用来构建具有root权限和测试Makefile

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 
+0

同样的错误: 一旦我运行Makefile模块已经位于/ lib/modules/$(shell uname -r)/modules.dep。 – v123 2014-11-24 06:03:38

+0

INSTALL /home/vishal/test/linux_dd/hello_world.ko 无法读取私钥 DEPMOD 3.13.0-24-generic make [1]:离开目录'/usr/src/linux-headers-3.13。上面的0-24-通用' – v123 2014-11-24 06:05:53

+0

是makefile的一些输出片段。 – v123 2014-11-24 06:06:26

0

我曾经有同样的问题。我的问题是,在发出命令时我没有删除扩展名。即

modprobe foo.ko 

给出了上述错误。但是这个:

modprobe foo 

作品!