Linux 使用 insmod 时出错“无法插入模块 hello_world.ko:模块格式无效”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21244481/
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
Error using insmod "Could not insert module hello_world.ko: Invalid module format"
提问by user3204332
I'm trying to make a hello_worldkernel module using C and Bash on a Raspberry Pi.
我正在尝试在 Raspberry Pi 上使用 C 和 Bash制作一个hello_world内核模块。
I successfully used the make command to generate a hello_world.ko
file.
我成功地使用 make 命令生成了一个hello_world.ko
文件。
However, when I try to use the insmod hello_world.ko
command, I get the following error:
但是,当我尝试使用该insmod hello_world.ko
命令时,出现以下错误:
Error: could not insert module hello_world.ko: Invalid module format
错误:无法插入模块 hello_world.ko:模块格式无效
I tried following the steps described on the Raspberry Pi forum, but I didn't have much luck.
我尝试按照Raspberry Pi 论坛上描述的步骤进行操作,但运气不佳。
I think this may be due to a version mismatch between my kernel and the Linux headers. What role do these headers play in this process and how do I get versions that match my kernel?
我认为这可能是由于我的内核和 Linux 头文件之间的版本不匹配。这些头文件在这个过程中扮演什么角色,我如何获得与我的内核匹配的版本?
回答by ikstream
The header files define the interfaces between your modules and the kernel as well as the interfaces between userspace and kernel. If there is a mismatch between your kernel version and header files, your module wont work,as you expected. Your current header files are typically available in your repository. You could check your currently running kernel by:
头文件定义了模块和内核之间的接口以及用户空间和内核之间的接口。如果您的内核版本和头文件不匹配,您的模块将无法正常工作。您当前的头文件通常在您的存储库中可用。您可以通过以下方式检查当前正在运行的内核:
uname -r
afterwards check your repo for linux headers:
之后检查你的 repo 是否有 linux 头文件:
sudo apt-cache search linux-headers
and install them.
并安装它们。