'insmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted
I am trying to learn linux and kernel development.
I am able to build the module but am unable to load it.
HelloWorld.c
/*
* 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.\n");
/*
* 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.\n");
}
And here is my make file:
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
while doing insmod for loading the module permission is getting denied. I tried even doing it with root and also with modprobe, but no use.
I also tried Link but issue still the same.
Hope i get some help. I am using ubuntu 18.04LTS.
Solution 1:[1]
If $ sudo insmod file_name.ko fails with mentioned error, then do dmesg | tail -1
and it will give idea of what exactly went wrong while installing kernel-module.
In my case it was because another module was overlapping on same /sys/class location.
After doing sudo rmmod <that_module.ko> I was able to load my new kernel module.
Solution 2:[2]
First, make sure in makefile there is tab after all: and clean: not space
then save it and run command make
After that, insert the kernel by following command.
$ sudo insmod file_name.ko
Finally, display.
$ dmesg | tail -1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ashish |
| Solution 2 | Jin Lee |
