title: Creating simple kernel module
body: <p>I've just started learning linux kernel modules and trying to write simple Hello world program.</p>
  
  <p>So mymod.c:</p>
  
  <pre><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Author");
  MODULE_DESCRIPTION("\"Hello, world!\" minimal module");
  MODULE_VERSION("printk");
  
  int init_module(void)
  {
      printk("&lt;1&gt;Hello world 1.\n");
      return 0;
  } 
  
  void cleanup_module(void)
  {
      printk(KERN_ALERT "Goodbye world 1.\n");
  }
  </code></pre>
  
  <p>Makefile:</p>
  
  <pre><code>obj-m += mymod.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
  </code></pre>
  
  <p>make outout:</p>
  
  <pre><code>make -C /lib/modules/3.2.0-23-generic-pae/build M=/root modules
  make[1]: Entering directory `/usr/src/linux-3.2.42'
  
    WARNING: Symbol version dump /usr/src/linux-3.2.42/Module.symvers
             is missing; modules will have no dependencies and modversions.
  
    Building modules, stage 2.
    MODPOST 1 modules
  make[1]: Leaving directory `/usr/src/linux-3.2.42'
  </code></pre>
  
  <p>So it creates files I needed, but when I try to install this by</p>
  
  <pre><code>insmod mymod.ko
  </code></pre>
  
  <p>I get next output:</p>
  
  <pre><code>insmod: error inserting 'mymod.ko': -1 Invalid module format
  </code></pre>
  
  <p>So I'd like to know what's the problem?</p>
  
  <p>PS. OS - Ubuntu Server 12.04. Kernel - linux 3.2.0-23 pae</p>
  
  <p>UPDATE:</p>
  
  <p>I've downloaded from kernel.org kernel 3.2.42 and put it in /usr/src and did 'make defconfig &amp;&amp; make prepare', 'make modules_prepare'. Also I've created link in /lib/modules/3.2.0-23-generic-pae/build.</p>