title: How to compile a kernel module against a new Source
body: <p>I am trying to compile a <code>Hello World</code> module. I am having a fresh Ubuntu in my system which doesn't have any compiled kernel.</p>
  
  <p>My kernel is:</p>
  
  <p>2.6.32-34-generic</p>
  
  <p>I gave the following Makefile and got the error:</p>
  
  <pre><code>obj-m += hello-1.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
  
  # make
  make -C /lib/modules/2.6.32-34-generic/build M=/home/james/Desktop/hello modules
  make[1]: Entering directory `/usr/src/linux-headers-2.6.32-34-generic'
  make[2]: *** No rule to make target `/home/james/Desktop/hello/hello-1.c', needed by `/home/james/Desktop/hello/hello-1.o'.  Stop.
  make[1]: *** [_module_/home/james/Desktop/hello] Error 2
  make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-34-generic'
  make: *** [all] Error 2
  </code></pre>
  
  <p>The contents of my /lib/modules/2.6.32-34-generic are</p>
  
  <pre><code>total 3864
  lrwxrwxrwx  1 root root     40 2011-11-05 15:55 build -&gt; /usr/src/linux-headers-2.6.32-34-generic
  drwxr-xr-x  2 root root   4096 2011-11-05 15:49 initrd
  drwxr-xr-x 10 root root   4096 2011-11-05 15:49 kernel
  .......................................................
  .......................................................
  </code></pre>
  
  <p>The folder <code>/usr/src/linux-headers-2.6.32-34-generic</code> exists.</p>
  
  <p>Since it didnt work, I downloaded the <a href="http://packages.ubuntu.com/lucid-updates/devel/linux-headers-2.6.32-34-generic" rel="nofollow">linux-headers-2.6.32-34-generic source from Ubuntu</a> and compiled and changed my Makefile to:</p>
  
  <pre><code>obj-m += hello-1.o
  all:
      make -C /usr/src/linux-2.6.32/ M=$(PWD) modules
  
  clean:
      make -C /usr/src/linux-2.6.32/ M=$(PWD) clean
  
  #make
  make -C /usr/src/linux-2.6.32/ M=/home/james/Desktop/hello modules
  make[1]: Entering directory `/usr/src/linux-2.6.32'
  
    ERROR: Kernel configuration is invalid.
           include/linux/autoconf.h or include/config/auto.conf are missing.
           Run 'make oldconfig &amp;&amp; make prepare' on kernel src to fix it.
  
  
    WARNING: Symbol version dump /usr/src/linux-2.6.32/Module.symvers
             is missing; modules will have no dependencies and modversions.
  
  make[2]: *** No rule to make target `/home/james/Desktop/hello/hello-1.c', needed by `/home/james/Desktop/hello/hello-1.o'.  Stop.
  make[1]: *** [_module_/home/james/Desktop/hello] Error 2
  make[1]: Leaving directory `/usr/src/linux-2.6.32'
  make: *** [all] Error 2
  </code></pre>
  
  <p>Could someone help me solving this.http://packages.ubuntu.com/lucid-updates/devel/linux-headers-2.6.32-34-generic</p>
  
  <p>I have some general questions to ask.</p>
  
  <p>After a fresh install what is the best way of compiling a kernel. After I compiled the kernel and built a module it worked flawlessly earlier. But I couldnt know what to do this in this situation</p>