Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 653
kpk Avatar asked Oct 24 '19 17:10

kpk


People also ask

What is insmod in Linux with an example?

insmod command in Linux systems is used to insert modules into the kernel. Linux is an Operating System which allows the user to load kernel modules on run time to extend the kernel functionalities.

What does insmod do in Linux?

The insmod command is used to insert modules into the kernel. Kernel modules are usually used to add support for new hardware (as device drivers) and/or filesystems, or for adding system calls. This command inserts the kernel object file (. ko) into the kernel.

What is insmod and modprobe?

insmod is similar to modprobe: it can insert a module into the Linux kernel. Unlike modprobe, however, insmod does not read its modules from a set location, automatically insert them, and manage any dependencies. insmod can insert a single module from any location, and does not consider dependencies when doing so.

What does modprobe do in Linux?

Use the modprobe command to add or remove modules on Linux. The command works intelligently and adds any dependent modules automatically. The kernel uses modprobe to request modules. The modprobe command searches through the standard installed module directories to find the necessary drivers.


1 Answers

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.

like image 156
YanBir Avatar answered Oct 23 '22 12:10

YanBir