Unable to insert module to kernel

1.9k Views Asked by At

This is my introduction to kernel module. I'm following The Linux Kernel Module Programming Guide and just wrote my first simple module.

This is my module file hello.c;

/*
*  hello.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");
}

module_init(init_module);
module_exit(cleanup_module);

here is my Makefile

obj−m += hello.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

when I run make command, this is what I get..

make -C /lib/modules/4.15.0-45-generic/build M=/home/nailaakbar modules

make1: Entering directory '/usr/src/linux-headers-4.15.0-45-generic'

Building modules, stage 2.

MODPOST 0 modules

make1: Leaving directory '/usr/src/linux-headers-4.15.0-45-generic'

make result

but now when I try to insert it in kernel by using this command;

sudo insmod hello.k

I got this error

insmod: ERROR: could not load module hello.ko: No such file or directory

I've tried different solutions like making both functions static, or changing files location but nothing worked out.

Currently I'm running all these commands on Desktop and I'm using dual boot for linux environment.

Can anyone help me out that what I'm doing wrong here??

Possible duplicate question actually solved my issue but it was not directly my issue. I went through that question during my issue searching but couldn't get the idea. It was actually one comment on my question, that changed my view for error and then that mentioned answer resolved my issue.

0

There are 0 best solutions below