关于linux:insmod:错误:无法插入模块HelloWorld.ko:不允许操作

insmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted

我正在尝试学习linux和内核开发。

我能够构建模块,但无法加载。

HelloWorld.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*  
 *  hello-1.c - The simplest kernel module.
 */
#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.\
");

    /*
     * A non 0 return means init_module failed; module can't be loaded.
     */
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO"Goodbye world 1.\
");
}

这是我的制作文件:

1
2
3
4
5
6
7
8
9
10
KERNEL_SOURCE := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

obj-m += HelloWorld.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

在执行insmod加载模块权限时被拒绝。我甚至尝试用root以及modprobe来做,但是没有用。

我也尝试了Link,但问题仍然相同。

希望我能得到一些帮助。我正在使用ubuntu 18.04LTS。


所以我遇到了同样的问题,这对我有用:

  • 您需要使用mokutil禁用安全启动,请使用此链接中的第一个答案

  • 通过sudo运行insmod命令。

  • 祝你好运。


    首先,请确保在makefile中毕竟有制表符:并且干净:没有空格
    然后保存并运行命令make
    之后,通过以下命令插入内核。
    $ sudo insmod file_name.ko
    最后,显示。
    $ dmesg | tail -1