This is a simple Linux kernel module that demonstrates basic module initialization and cleanup. When loaded, it logs a message to the kernel log, and when unloaded, it logs another message.
- No input
- When the module is loaded:
"Hello, Check Point!" - When the module is unloaded:
"Goodbye, Check Point!"
Create a file named Makefile in the same directory as your module source code (basic_module.c) with the following content:
obj-m += basic_module.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) cleanNote: Replace basic_module.o with the object file name matching your source file if it's different.
Run the following command to compile the module:
makeThis will generate a basic_module.ko file, which is the compiled kernel module.
-
To load the module into the kernel:
sudo insmod basic_module.ko
-
To unload the module from the kernel:
sudo rmmod basic_module
To view the messages logged by the module, check the kernel log:
dmesg | tailYou should see the following messages:
-
After loading the module:
Hello, Check Point! -
After unloading the module:
Goodbye, Check Point!