Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-19-2014, 02:51 AM   #1
Prafull Barpute
LQ Newbie
Registered: Feb 2014
Posts: 2

Rep: Reputation: Disabled
Unhappy not able to remove loadable kernel module(LKM) using rmmod.


I am trying to write kernel module for ubuntu 12.04 LTS OS.
kernel version is 3.4.0-030400-generic-pae
I am able to compile it & load it to kernel.
For loading I use
sudo insmod nmod_main.ko
Now, If I try to remove it using
sudo rmmod nmod_main.ko
it gives me bellow error.
ERROR: Removing 'nmod_main': Device or resource busy

lsmod gives bellow information:
Module Size Used by
nmod_main 12394 0 [permanent]
Why this module shows permanent?

Bellow is the C-code for this module.

/********** Start of code ************/
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
        printk(KERN_INFO "init_module() called\n");
        return 0;

void cleanup_module(void)
        printk(KERN_INFO "cleanup_module() called\n");
/********** End of code ************/

I am getting some compilation warnings as bellow

Building with KERNELRELEASE = 3.4.0-030400-generic-pae
CC [M] ../src/nmod_main.o
../src/nmod_main.c:1:0: warning: "__KERNEL__" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
../src/nmod_main.c:2:0: warning: "MODULE" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
Building modules, stage 2.
Building with KERNELRELEASE = 3.4.0-030400-generic-pae
Please can anybody help me in this regard.

Prafull Barpute
Old 02-20-2014, 08:52 AM   #2
Senior Member
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,125
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
A couple of things come to mind.

first I wouldn't do the __KERNEL__ and MODULE defines
second you aren't telling the kernel what the init and exit fuctions are, you need to do something like


third they need to be declared to be of a type module_init and module_exit can work with, use the __init and __exit macros to do this.

static int __init init_module(void) {...}
static int __exit cleanup_module(void) {...}

forth make sure you are using a compatible compiler, if they aren't compatible you'll sometimes get this issue
1 members found this post helpful.
Old 02-24-2014, 04:05 AM   #3
Prafull Barpute
LQ Newbie
Registered: Feb 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Problem Solved

This problem is solved. Yes it is problem related to toolchain. I downloaded .deb files to install kernel from url "". But I was no sure about the toolchain used to generate these .deb files. So I finally download linux kernel source from ""->compile & install on my laptop & then compile my module. Problem disappeared. Thanks @estabroo for providing me valuable clue.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"insmod inserted the LKM into the kernel, But rmmod not removing it back" SIG_SEGV Linux - Embedded & Single-board computer 3 07-31-2012 09:17 AM
[Q] HOW TO rmmod with malfunction device driver kernel module. jspking Linux - General 2 04-08-2012 02:16 AM
loadable kernel module (LKM) issues shakthi Linux - Kernel 4 07-26-2011 09:02 AM
I want add my own system call using LKM (loadable kernel module)... raga4223688 Linux - Software 1 03-07-2007 07:21 AM
Linux 2.6 PCI driver module causing kernel panic on remove (rmmod) briek Linux - Software 2 09-18-2006 10:04 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration