insmod error in kernel module programming
我刚刚开始使用模块化编程。
以上是我的两个文件:
你好.c
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <linux/init.h>
#include <linux/module.h> static int hello_init(void) static void hello_exit(void) module_init(hello_init); |
制作文件
1
2 3 4 5 6 7 8 9 |
obj–m += hello.o
KDIR = /usr/src/linux–headers–3.13.0–46–generic all: clean: |
这是我的终端输出在 insmod 命令中显示错误,请帮助。
1
2 3 4 5 6 7 8 |
anubhav@anubhav–Inspiron–3421:~/Desktop/os$ make
make –C /usr/src/linux–headers–3.13.0–46–generic SUBDIRS=/home/anubhav/Desktop/os modules make[1]: Entering directory `/usr/src/linux–headers–3.13.0–46–generic‘ Building modules, stage 2. MODPOST 1 modules make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic’ anubhav@anubhav–Inspiron–3421:~/Desktop/os$ insmod hello.ko insmod: ERROR: could not insert module hello.ko: Operation not permitted |
- 只有 root 用户通常有权插入/删除内核模块。 su 到 root,或使用 sudo(如果适用)以 root 身份运行命令。
- @lsowen 我试过 “su” 和 “su -“。但是在提供密码后,我得到了消息”su:身份验证失败”。任何其他前进的方式
- 此消息意味着您输入了错误的密码(或者不是允许成为 root 的用户组的成员)。您需要在 su 使用的密码是 root 密码,而不是您的用户密码。
- @lsowen ubuntu 网站说,用户可以使用 sudo 命令添加任何需要以 root 身份执行的命令。我的 insmod 命令有效,我使用 dmesg 收到了消息。谢谢。
- 你没有看到 printk(KERN_ALERT”TEST: Good Bye”); 因为你还没有完成 rmmod hello 对吗?
如果您启用了安全启动,较新的内核将不允许插入任意内核模块。因此,您可以在 BIOS 中禁用安全启动,或者您需要对要安装的内核模块进行签名。
安全签署内核模块的步骤:
您需要成为 root 才能执行第 2 步
正如isowen所说,只有root可以加载或卸载模块。
执行 insmod hello 时会在 hello_init() 中看到打印,执行 rmmod hello 时会看到 hello_exit() 中的打印。
n
来源:https://www.codenong.com/29036987/