我刚开始进行模块化编程。
上面是我的两个文件:
你好.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 Bye");
}
module_init(hello_init);
module_exit(hello_exit);
生成文件
obj-m += hello.o
KDIR = /usr/src/linux-headers-3.13.0-46-generic
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
这是我的终端输出,显示 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
最佳答案
如果您启用了安全启动,较新的内核将不允许插入任意内核模块。因此,您可以在 BIOS 中禁用安全启动,或者您需要签署要安装的内核模块。
安全签署内核模块的步骤:
- 创建一个可以在固件中导入的X509证书
- 注册刚刚创建的公钥
- 签署您要安装的模块
- 安装模块
您需要成为 root 用户才能执行第 2 步和第 4 步。详细过程在 nice Ubuntu blog 中有描述。 .
关于c - 内核模块编程中的insmod错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036987/