title: not able to remove loadable kernel module(LKM) using rmmod
body: <p>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 &amp; load it to kernel.
  For loading I use </p>
  
  <blockquote>
    <p>sudo insmod nmod_main.ko</p>
  </blockquote>
  
  <p>Now, If I try to remove it using </p>
  
  <blockquote>
    <p>sudo rmmod nmod_main.ko</p>
  </blockquote>
  
  <p>it gives me bellow error.
  <strong>ERROR: Removing 'nmod_main': Device or resource busy</strong></p>
  
  <p>lsmod gives bellow information:</p>
  
  <blockquote>
    <p>Module Size Used by</p>
    
    <p>nmod_main 12394 0 [permanent]</p>
  </blockquote>
  
  <p>Why this module shows <strong>permanent?</strong></p>
  
  <p>Bellow is the C-code for this module.</p>
  
  <pre><code>/********** Start of code ************/
  #define __KERNEL__
  #define MODULE
  #include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  
  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 ************/
  </code></pre>
  
  <p>I am getting some compilation warnings as bellow:</p>
  
  <blockquote>
    <p>Building with KERNELRELEASE = 3.4.0-030400-generic-pae</p>
    
    <p>CC [M] ../src/nmod_main.o</p>
    
    <p>../src/nmod_main.c:1:0: warning: "<strong>KERNEL</strong>" redefined [enabled by default]</p>
    
    <p>:0:0: note: this is the location of the previous definition</p>
    
    <p>../src/nmod_main.c:2:0: warning: "MODULE" redefined [enabled by default]</p>
    
    <p>:0:0: note: this is the location of the previous definition</p>
    
    <p>Building modules, stage 2.</p>
    
    <p>Building with KERNELRELEASE = 3.4.0-030400-generic-pae </p>
  </blockquote>
  
  <p>Please can anybody help me in this regard.</p>
  
  <p>I am using bellow makefile for building this module:</p>
  
  <pre><code>ifeq ($(KERNELRELEASE),)  
  
  KERNELDIR ?= /lib/modules/$(shell uname -r)/build 
  PWD := $(shell pwd)  
  
  .PHONY: build clean  
  
  build:
          $(MAKE) -C $(KERNELDIR) M=$(PWD) modules  
  
  clean:
          rm -rf ../src/*.o ../src/*~ core ../src/.depend ../src/.*.cmd ../src/*.ko ../src/*.mod.c 
  else  
  
  $(info Building with KERNELRELEASE = ${KERNELRELEASE}) 
  obj-m :=    ../src/nmod_main.o  
  
  endi
  </code></pre>