6
votes

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.

2
Maybe your module is not signed, while kernel have restrict policy for unsigned modules?Alex Hoppus
@Alex So you are saying i may need to somehow remove the policy restrictions?kpk

2 Answers

3
votes

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.

-1
votes

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