PDA

View Full Version : Error while performing insmod for my first kernel programme



Rahul04789
June 5th, 2013, 05:13 PM
root@rahul-VPCEG28FN:/home/rahul/modules# insmod mod_first.ko
insmod: error inserting 'mod_first.ko': -1 File exists

dwhitney67
June 5th, 2013, 05:19 PM
Undoubtedly you have already inserted (loaded) the kernel module in a previous attempt. Now, when you attempt to load it again, you get the error "File exists".

Try unloading the module before attempting to load it again.


$ sudo rmmod mod_first

$ sudo insmod mod_first.ko

Rahul04789
June 5th, 2013, 05:19 PM
Hi all,

Today I started with my first kernel programming and got an error while executing the command "insmod mod_first.ko"
Below is the error message:

root@rahul-VPCEG28FN:/home/rahul/modules# insmod mod_first.ko
insmod: error inserting 'mod_first.ko': -1 File exists

I am also providing my "mod_first.c" file:

#include<linux/module.h>
#include<linux/init.h>

MODULE_AUTHOR("Rahul");
MODULE_DESCRIPTION("My first kernel module");

int mod_init(void)
{
printk("\nModule init\n");
return 0;
}

void mod_exit(void)
{
printk("\nModule exit\n");
}
module_init(mod_init);
module_exit(mod_exit);

Following is my makefile:

obj-m:=mod_first.o

KDIR=/lib/modules/$(shell uname -r)/build

all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.*



Please tell me what to be done in oorder to remove the error.
I am very keen/enthusiast to know all these kernel programming.

Regards,

oldos2er
June 5th, 2013, 05:27 PM
Threads merged. Please do not create multiple threads for the same or similar questions.

Rahul04789
June 6th, 2013, 05:02 PM
Hey thanks! I got it and now working fine..