$ cat hello.c #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "Goodbye, cruel world\n"); } module_init(hello_init); module_exit(hello_exit);
sudo dnf install kernel-devel-`uname -r`
$ cat Makefile obj-m += hello.o .PHONY: build clean load unload build: make -C /lib/modules/$(shell uname -r)/build modules M=$(shell pwd) clean: make -C /lib/modules/$(shell uname -r)/build clean M=$(shell pwd) load: sudo insmod hello.ko unload: -sudo rmmod hello
$ make load sudo insmod hello.ko $ dmesg -t | tail -3 hello: loading out-of-tree module taints kernel. hello: module verification failed: signature and/or required key missing - tainting kernel Hello, world $ make unload sudo rmmod hello $ dmesg | tail -1 Goodbye, cruel world