create_module - Linux


create_module is a powerful command used to create Linux kernel modules, enabling users to extend kernel functionality and add custom features. It plays a vital role in kernel development, allowing the incorporation of specialized drivers, hardware support, and custom features.


create_module [-o output_dir] [-n module_name] [-P] [-L path_to_library] [-I path_to_include] pathname


  • -o: Specify the output directory for the generated module.
  • -n: Set the name for the generated module.
  • -P: Precompile the module into a .ko file.
  • -L: Add a library path for linking.
  • -I: Add an include path for compilation.


Simple Module Creation:

create_module /path/to/source.c

Specifying Module Name and Output Directory:

create_module -n my_module -o ~/module_dir /path/to/source.c

Precompiling the Module:

create_module -P /path/to/source.c

Adding Link and Include Paths:

create_module -L /path/to/library -I /path/to/include /path/to/source.c

Common Issues

  • Kernel Headers Not Found: Ensure that the required kernel headers are installed and the correct path is set using -I.
  • Compilation Errors: Verify that the source code is syntactically correct and conforms to kernel coding conventions.
  • Module Loading Failures: Check kernel log messages for errors related to module insertion or initialization.


Using create_module with insmod:

create_module -P /path/to/source.c
insmod my_module.ko

Creating a Custom Kernel:

create_module -P /path/to/module1.c /path/to/module2.c
mknod /dev/my_device c 247 0
insmod my_module1.ko my_module2.ko

Related Commands

  • modinfo: Display information about installed modules.
  • insmod: Insert a module into the running kernel.
  • rmmod: Remove a module from the running kernel.
  • make: Build kernel modules from source code.