Created
November 13, 2025 20:47
-
-
Save wojtekka/d08612f6a108507cbc8e67e737e92700 to your computer and use it in GitHub Desktop.
Building out-of-tree Linux kernel module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cat > Kbuild << EOF | |
| obj-m := foo.o | |
| EOF | |
| cat > Makefile << EOF | |
| KDIR ?= /lib/modules/`uname -r`/build | |
| default: | |
| $(MAKE) -C $(KDIR) M=$$PWD | |
| EOF | |
| cat > foo.c << EOF | |
| #include <linux/module.h> | |
| static int foo_init(void) | |
| { | |
| printk("foo_init\n"); | |
| return 0; | |
| } | |
| static void foo_exit(void) | |
| { | |
| printk("foo_exit\n"); | |
| } | |
| module_init(foo_init); | |
| module_exit(foo_exit); | |
| MODULE_AUTHOR("John Doe <john@doe>"); | |
| MODULE_DESCRIPTION("Foo module"); | |
| MODULE_LICENSE("GPL v2"); | |
| EOF | |
| make | |
| sudo insmod foo.ko |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment