C 内核模块编程中的insmod错误
我只是从模块化编程开始 以上是我的两个文件: 你好,cC 内核模块编程中的insmod错误,c,linux,linux-kernel,C,Linux,Linux Kernel,我只是从模块化编程开始 以上是我的两个文件: 你好,c #include <linux/init.h> #include <linux/module.h> static int hello_init(void) { printk(KERN_ALERT "TEST: Hello world\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "TEST: Good B
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk(KERN_ALERT "TEST: Hello world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "TEST: Good Bye");
}
module_init(hello_init);
module_exit(hello_exit);
这是我的终端输出,显示insmod命令中的错误,请帮助
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
正如isowen提到的,只有root用户可以加载或卸载模块
执行
insmod hello
操作时,您会在hello\u init()
中看到打印,执行rmmod hello
操作时,您会在hello\u exit()
中看到打印。如果启用了安全引导,则较新的内核将不允许插入任意内核模块。因此,您可以在BIOS中禁用安全引导,或者需要对要安装的内核模块进行签名
安全签署内核模块的步骤:
您需要是root用户才能执行步骤2和4。详细的过程在nice中描述。执行
cat/proc/sys/kernel/modules\u disabled
,如果您看到结果
1
然后执行echo'kernel.modules\u disabled=1'>/etc/sysctl.d/99 custom.conf
然后重新启动并重试BR nu11secur1ty通常只有root
用户具有插入/删除内核模块的权限。要么转到root
,要么使用(如果适用)以root身份运行命令。@lsowen我尝试了“su”和“su-”。但在提供密码后,我得到消息“su:Authentication failure”。任何其他移动头的方式此消息意味着您输入了错误的密码(或者您不是允许成为root用户的用户组成员)。您需要在su
使用的密码是root
密码,而不是您的用户密码。@lsowentubuntu网站说,用户可以使用sudo命令预先发送任何需要作为root用户执行的命令。我的insmod命令起作用了,我使用dmesg得到了消息。谢谢。你没有看到printk(KERN_ALERT“TEST:再见”)代码>因为你没有做过rmmod hello
是吗?
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