Description

This is a very simple kernel module that uses printk to write “Hello world!”.

Resources

See this link by Johannes 4GNU_Linux

Module

#include <linux/module.h>
#include <linux/init.h>

int hello_start(void)
{
    printk(KERN_INFO "Hello world!\n");
    return 0;
}

void hello_end(void)
{
    printk(KERN_INFO "Hello module unloaded\n");
}

module_init(hello_start);
module_exit(hello_end);


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Cl1nical");
MODULE_DESCRIPTION("Hello World Kernel Module");
MODULE_VERSION("0.1");

Makefile

obj-m += main.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

Result

Compile using the following command in the dir:

make

Insert the module into the kernel Disclaimer: Use a VM

sudo insmod main.ko

Use the following command to display the output:

sudo dmesg