Building a kernel with modules

If you have configured your kernel to use modules, you will need to do the following:

	cd /usr/src/linux
	make modules

If you want a log of the whole process, the following will work.

	make modules >make.log 2>&1

After this do:

	make modules_install
This last step puts the modules into "/lib/modules/kernel_release/", where "kernel_release" is something like 2.2.12-20smp, or some such directory that corresponds to your current kernel version. You just might want to make a backup copy of this directory if you are experimenting (tar does a nice job and you can just leave mod_2.2.12-20smp.tar in /lib/modules).

look at /usr/src/linux/Documentation/modules.txt for more information.

Now, as for building your own modules and getting them to load into your kernel, entire books can and have been written on the subject. One sage piece of advice is that for a module to load into your kernel, it must be compiled in the same way as your kernel. This seemingly trivial bit of advice, actually tells it all.

In my case, trying to build a simple module that called printk to show a simple messages would always produce:

	insmod hello.o
	hello.o: unresolved symbol printk
It turns out the following compile switches save the day:
	-DMODULE
	-DMODVERSIONS
	-D__KERNEL__
	-D__SMP__