Reputation: 162
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.
I am using ubuntu 18.04LTS.
Upvotes: 13
Views: 53140
Reputation: 375
So I had the same problem and this worked for me:
You need to disable Secure Boot using mokutil use the first answer in this link
Run the insmod command via sudo.
Upvotes: 8
Reputation: 6782
If your kernel is locally build and locally signed with a generated signature,you could sign the module using same keys.
<kernel source>/scripts/sign-file sha512 MOK.priv MOK.pem module.ko
https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html, https://github.com/jakeday/linux-surface/blob/3267e4ea1f318bb9716d6742d79162de8277dea2/SIGNING.md
Upvotes: 0
Reputation: 447
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.
Upvotes: 0
Reputation: 1
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
Upvotes: -2