Replies: 2 comments
-
Hello! Welcome to the world of kernel module development. Don't worry; we all start somewhere, and I'm here to help. To print messages to the kernel log (dmesg), you can use the #include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple kernel module");
MODULE_VERSION("0.1");
static int __init hello_init(void) {
printk(KERN_INFO "Hello, world!\n");
return 0;
}
static void __exit hello_exit(void) {
printk(KERN_INFO "Goodbye, world!\n");
}
module_init(hello_init);
module_exit(hello_exit); Make sure you compile your module with debugging enabled. You can add make -C /path/to/kernel/source M=$(pwd) modules
sudo insmod your_module.ko You can check if your module is loaded and see its output in dmesg: lsmod | grep your_module
dmesg | grep "Hello, world!" This should help you confirm if your module is being applied and printing messages as expected. If you encounter any issues or have more questions, feel free to ask. Happy learning! :) |
Beta Was this translation helpful? Give feedback.
-
what is nv_log binary?! |
Beta Was this translation helpful? Give feedback.
-
Hi :) I'm fairly new to the world of kernel module development, and I'm hoping to get a bit of guidance - I think I've got the kernel modules compiling, installed, and in use, but I don't know how to confirm this. Some kind of "hello world" would be nice - even just a way to print a message to
dmesg
to let me know that it's applying my code.I've tried a few things (
nv_log
,dpPrint
,DP_LOG
) but nothing seems to work. I also tried setting an appropriate keyword filter usingRmMsg
and compiling withmake modules -j$(nproc) DEBUG=1
- the latter doesn't seem to have had an effect, and the former just spams a bunch of stuff todmesg
so I'm not sure if what I'm printing is there or not (grep
can't find it but perhaps it's just being deleted by later calls?)I'd appreciate some guidance, and apologies if these are trivial questions - I'm very eager to learn :)
Beta Was this translation helpful? Give feedback.
All reactions