Description
PART 1
Create a Kernel Module “simple”.
– Create a program named simple.c (prints appropriate messages when the kernel module is loaded and unloaded).
– Create a Makefile for compiling the program.
simple.c
#include
{
printk(KERN_INFO “Loading Modulen”);
return 0;}
/* This function is called when the module is removed. */
void simple_exit(void) {
printk(KERN_INFO “Removing Modulen”);
}
Makefile
obj-m += simple.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
Note: Makefile should be in the same directory as simple.c
1.Compile kernel module simple.c $make Note: if the compiling succeeds, several files are produced.
2.Load Kernel Module $sudo insmod simple.ko Check out contents in kernel log buffer. $dmesg
3.Remove Kernel Module $sudo rmmod simple Check out contents in kernel log buffer. $dmesg