Linux “致命:找不到模块错误”使用 modprobe

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3140478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 20:11:31  来源:igfitidea点击:

"FATAL: Module not found error" using modprobe

clinuxlinux-kernelkernellinux-device-driver

提问by Ravi Gupta

I have a problem with modprobecommand... I compiled the hello world module and loaded it with insmod, it works fine and when I do lsmod, I can see it in the output list. But when I insert this module using modprobeI am getting a FATAL error:

我的modprobe命令有问题...我编译了 hello world 模块并加载了它insmod,它工作正常,当我这样做时lsmod,我可以在输出列表中看到它。但是当我使用插入这个模块时,我modprobe收到了一个致命错误:

root@okapi:/home/ravi# modprobe ./hello.ko 
FATAL: Module ./hello.ko not found.
root@okapi:/home/ravi#

Here is the module code:

下面是模块代码:

#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk(KERN_ALERT "Hello, world\n");
        return 0;
}
static void hello_exit(void)
{
        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

and Makefile

和生成文件

obj-m += hello.o

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

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

采纳答案by che

The reason is that modprobelooks into /lib/modules/$(uname -r)for the modules and therefore won't work with local file path. That's one of differences between modprobeand insmod.

原因是modprobe查找/lib/modules/$(uname -r)模块,因此不适用于本地文件路径。这之间的差异的一个modprobeinsmod

回答by Sjoerd

Try insmodinstead of modprobe. Modprobe looks in the module directory /lib/modules/uname -rfor all the modules and other files

尝试insmod代替 modprobe。Modprobe 在模块目录 /lib/modules/ 中uname -r查找所有模块和其他文件

回答by Elf King

The best thing is to actually use the kernel makefile to install the module:

最好的办法是实际使用内核 makefile 来安装模块:

Here is are snippets to add to your Makefile

这是要添加到 Makefile 的片段

around the top add:

在顶部周围添加:

PWD=$(shell pwd)
VER=$(shell uname -r)
KERNEL_BUILD=/lib/modules/$(VER)/build
# Later if you want to package the module binary you can provide an INSTALL_ROOT
# INSTALL_ROOT=/tmp/install-root

around the end add:

在最后添加:

install:
        $(MAKE) -C $(KERNEL_BUILD) M=$(PWD) \
           INSTALL_MOD_PATH=$(INSTALL_ROOT) modules_install

and then you can issue

然后你可以发出

    sudo make install

this will put it either in /lib/modules/$(uname -r)/extra/

这将把它放在 /lib/modules/$(uname -r)/extra/

or /lib/modules/$(uname -r)/misc/

或 /lib/modules/$(uname -r)/misc/

and run depmod appropriately

并适当地运行 depmod

回答by Gouse

Insert this in your Makefile

 $(MAKE) -C $(KDIR) M=$(PWD) modules_install                      

 it will install the module in the directory /lib/modules/<var>/extra/
 After make , insert module with modprobe module_name (without .ko extension)

OR

或者

After your normal make, you copy module module_name.ko into   directory  /lib/modules/<var>/extra/

then do modprobe module_name (without .ko extension)

然后做 modprobe module_name (没有 .ko 扩展名)

回答by Yaroslav

Ensure that your network is brought down before loading module:

在加载模块之前确保您的网络已关闭:

sudo stop networking

It helped me - https://help.ubuntu.com/community/UbuntuBonding

它帮助了我 - https://help.ubuntu.com/community/UbuntuBonding

回答by sharath kumar

i think there should be entry of your your_module.ko in /lib/modules/uname -r/modules.dep and in /lib/modules/uname -r/modules.dep.bin for "modprobe your_module" command to work

我认为应该在 /lib/modules/ uname -r/modules.dep 和 /lib/modules/ uname -r/modules.dep.bin 中输入 your_module.ko 以使“modprobe your_module”命令起作用