【发布时间】:2016-05-01 16:14:02
【问题描述】:
我不明白为什么 insmod 给出 Invalid parameters 错误(在 dmesg 中看不到任何内容):
$ sudo insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Invalid parameters
$ sudo insmod /hello.ko
insmod: ERROR: could not load module /hello.ko: No such file or directory
我的模块中没有参数。这只是你好世界的例子。
我的环境:
$ uname -r
3.16.0-4-amd64
我已经安装了所有可能的内核头文件包:
linux-headers-3.16.0-4-all
linux-headers-3.16.0-4-all-amd64
linux-headers-3.16.0-4-amd64
linux-headers-3.16.0-4-common
linux-headers-amd64
我的代码:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
MODULE_LICENSE("GPL");
我使用以下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
make 输出:
$ 制作
make -C /lib/modules/3.16.0-4-amd64/build M=/home/user/c.driver/driver-1 modules
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
Makefile:10: *** mixed implicit and normal rules: deprecated syntax
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
CC [M] /home/user/c.driver/driver-1/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/user/c.driver/driver-1/hello.mod.o
LD [M] /home/user/c.driver/driver-1/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'
更新:与 14.04.1-Ubuntu 的结果相同
【问题讨论】:
-
你试过 insmod hello.ko 而不是 insmod ./hello.ko 吗?
-
通常在
dmesg消息中解释了模块加载失败的原因。检查一下。 -
@Tsyvarev 我知道,但与内核模块无关。最后一个 -
Parallels Linux shared folders filesystem driver 1.2.1 loaded。会不会是Parallels造成的? VM 正在 Parallels Desktop 下运行。 -
猜猜你在内核中启用了 CONFIG_MODULES=y 吗?
-
尝试 zcat /proc/config.gz | grep CONFIG_MODULES
标签: linux makefile kernel-module insmod