How to compile a kernel module with a new source

I am trying to compile the Hello World module. I have a new Ubuntu on my system that does not have a compiled kernel.

My core:

2.6.32-34-generic

I gave the following Makefile and got an 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

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

There is a folder /usr/src/linux-headers-2.6.32-34-generic .

Since it did not work, I downloaded linux-headers-2.6.32-34-shared 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 

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

I have some general questions to ask.

After a new installation, it is best to compile the kernel. After I compiled the kernel and built the module, it worked flawlessly before. But I could not know what to do in this situation.

+4
source share
4 answers

make [2]: * There is no rule for creating a target /home/james/Desktop/hello/hello-1.c', needed by /home/james/Desktop/hello/hello-1.o. Stop

In the first compilation, you encounter this error because the hello-1.c file is not in the directory / home / james / Desktop / hello /.

+2
source

You need to install some kind of package, for example, "kernel-devel" on Fedora (sorry I'm not a Ubuntu user), it provides headers and .config to compile your kernel module.

+1
source
  • Check if hello-1.c exists in the directory / home / james / Desktop / hello /.
  • You need to have modules_enabled in your kernel. To do this, you need to build a new kernel. The following article explains how to properly build the kernel. Include modules in the kernel assembly configuration.

    http://kernelnewbies.org/FAQ/KernelCompilation

0
source

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 because the source code of the kernel has been downloaded and compiled earlier.

This is how you should compile any kernel module.

After loading the kernel source, you must prepare it to add any modules to it.

Copy the old “config-xxxx” file from the / boot / directory to the new kernel source directory and rename it as “.config”.

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

Next, you need to do “make” (and wait for a while) - it will generate a new kernel file “vmlinux” along with many other files that are read by the compilation process of the modules.

Now you can go to the directory where the source code of the kernel module 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 the Makefile are your header file and the source file, which is hello-1.c, located together.

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

0
source

Source: https://habr.com/ru/post/1383157/


All Articles