How to compile and run your own kernel modules
Compiling kernel modules requires a special setup, with a
purpose-build Makefile. The easiest way to do this is to download the
example directory
and modify it as appropriate.
The procedure to compile and run a kernel module is as follows:
-
Modify the makefile by replacing every occurrence of helloWorld
and kernelRead by the names of the modules you wish to create.
-
compile the modules by running make in the
directory where the modules reside. If the compilation succeeds,
the resulting module code is contained in the file <module_name>.ko
-
Now become superuser by typing
su -
You will be asked for the root-password, which was distributed
separately.
-
Insert module into the running kernel by typing
insmod <module_name>.ko
Any output generated by the printk -function will
appear in the file /var/log/messages . The best command to
watch this output is
tail -f /var/log/messages
- You can remove existing modules which are unused via the
command
rmmod <module_name>
Page maintained by E.Ritter@cs.bham.ac.uk