11

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.

kpk
  • 142
  • 1
  • 2
  • 11

4 Answers4

6

So I had the same problem and this worked for me:

  1. You need to disable Secure Boot using mokutil use the first answer in this link

  2. Run the insmod command via sudo.

Good Luck.

YanBir
  • 345
  • 4
  • 12
0

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.

ashish
  • 409
  • 4
  • 7
0

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

Chand Priyankara
  • 6,739
  • 2
  • 40
  • 63
-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

Jin Lee
  • 3,194
  • 12
  • 46
  • 86