4
votes

I am trying to compile a Hello World module. I am having a fresh Ubuntu in my system which doesn't have any compiled kernel.

My kernel is:

2.6.32-34-generic

I gave the following Makefile and got the error:

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

The contents of my /lib/modules/2.6.32-34-generic are

total 3864
lrwxrwxrwx  1 root root     40 2011-11-05 15:55 build -> /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
.......................................................
.......................................................

The folder /usr/src/linux-headers-2.6.32-34-generic exists.

Since it didnt work, I downloaded the linux-headers-2.6.32-34-generic source from Ubuntu and compiled and changed my Makefile to:

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 && 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

Could someone help me solving this.http://packages.ubuntu.com/lucid-updates/devel/linux-headers-2.6.32-34-generic

I have some general questions to ask.

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

4

4 Answers

1
votes

make[2]: * No rule to make target /home/james/Desktop/hello/hello-1.c', needed by/home/james/Desktop/hello/hello-1.o'. Stop

Your are facing this error in the first compilation because hello-1.c file is missing in /home/james/Desktop/hello/ directory.

2
votes

You need to install some package like 'kernel-devel' on Fedora (sorry I am not a Ubuntu user), it provides the headers and .config to compile your kernel module.

2
votes

The error:

ERROR: Kernel configuration is invalid.
         include/linux/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && 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.

simply is because your kernel source is newly downloaded and uncompiled before.

This is how u should compile any kernel module.

After download the kernel source, you must prepare it for adding any modules to it.

Copy the older-kernel's "config-xxxx" file from the /boot/ directory into the new kernel source directory, and rename it as ".config".

Then execute "make oldconfig", which will take a backup of the .config into .config.old, and regenerate a new .config based on the new kernel source. Just enter "ENTER" for all the default settings (lots of them).

Next is to do a "make" (and wait for some time) - it will generate a new kernel file "vmlinux", together with many other files which is read by the modules compilation process.

Now you can go to your directory where the kernel module source code is located, and based on the following Makefile:

obj-m += hello-1.o

default: modules

modules:

    make -C /kernel_source/ M=$(PWD) modules

clean:
    make -C /kernel_source/ M=$(PWD) clean

Together with Makefile are your header and source file, which is hello-1.c located together.

Just "make" and your kernel modules should be generated successfully.

0
votes
  1. Check if hello-1.c exists in /home/james/Desktop/hello/ directory.
  2. You need to have modules_enabled in your kernel. You need to compile a fresh kernel to do this. Following post explains how to build kernel nicely. Enable modules in configuration of kernel build.

    http://kernelnewbies.org/FAQ/KernelCompilation