Search code examples
ubuntudrivers

"Invalid module format" when inserting a custom Linux kernel module


I'm trying to write a Linux kernel module, but I'm stuck just writing some stub code. I've compiled this code in Ubuntu:

#include <linux/module.h>
int init_module(void){ printk("<1> hellp"); return 0;}
void cleanup_module(void){ printk("<1> bye");}

However, when I try to insmod it I get the error:

Invalid module format

After googling I figured it may be some problem with version compatibility, but I'm not sure. What am I doing wrong?


Solution

  • You're missing the MODULE_ parameters, here's an empty kernel project:

    #include <linux/module.h>
    #include <linux/kernel.h>
    
    static void __exit cleanup(void)
    {
    }
    
    
    static int __init startup(void)
    {
    }
    
    module_init(startup);
    module_exit(cleanup);
    
    MODULE_LICENSE("GPL");
    MODULE_AUTHOR("Someone Like You");