A lightweight, user-friendly C utility for managing Linux kernel modules. Load, unload, list, and check kernel modules with a simple CLI interface powered by the libkmod library.
Current version: v0.0.3
last edits:
- get info of specific module added
- List loaded modules - View all currently loaded kernel modules with details
- Load modules - Insert kernel modules (.ko files) with optional parameters
- Unload modules - Remove kernel modules by name
- Check module status - Quickly verify if a specific module is loaded
- Dependency tracking - View module dependencies and reference counts
- Error handling - Clear, user-friendly error messages
- Lightweight - Minimal dependencies, fast execution
- Generic - Works with any kernel module, not hardware-specific
- Linux system with kernel module support
- GCC compiler (or compatible C compiler)
libkmod-devpackage installedpkg-configfor build configurationmakefor building
sudo apt-get update
sudo apt-get install libkmod-dev pkg-config build-essentialcd /path/to/KMM
makeThe compiled binary will be at: ./kmm
mkdir ~/.local/share/KMM
touch ~/.local/shate/KMM/log_data.log
./kmm help./kmm help./kmm listShows module name, size (KB), reference count, and dependencies.
Example output:
=== Loaded Kernel Modules ===
Name Size (KB) RefCnt Dependencies
---- -------- ------ ------------
vboxnetadp 28 0 vboxdrv
vboxnetflt 32 0 vboxdrv
vboxdrv 680 2 -
snd_seq_dummy 12 0 soundcore, snd, snd_timer
./kmm check <module_name>Examples:
./kmm check vboxdrv # Loaded
./kmm check nonexistent # Not loadedsudo ./kmm load <path_to_module.ko> [parameters]Examples:
sudo ./kmm load ./my_driver.ko
sudo ./kmm load ./my_driver.ko param1=value1 param2=value2sudo ./kmm unload <module_name>Example:
sudo ./kmm unload my_driverKMM uses a 3-layer architecture for clean separation of concerns:
┌─────────────────────────────────────┐
│ CLI Layer (main.c) │
│ - Command dispatcher │
│ - User input parsing │
│ - Output formatting │
└──────────┬──────────────────────────┘
│
┌──────────▼──────────────────────────┐
│ API Layer (module_manager.h/.c) │
│ - Core operations │
│ - Error handling │
│ - Context management │
└──────────┬──────────────────────────┘
│
┌──────────▼──────────────────────────┐
│ libkmod (kernel interface) │
│ - Kernel module database │
│ - Load/unload via kernel │
└─────────────────────────────────────┘
module_manager.h - Public API header defining:
ModuleInfostruct with module metadata- 6 core functions:
mm_init,mm_cleanup,mm_load,mm_unload,mm_list,mm_is_loaded,mm_last_error
module_manager.c - Implementation using libkmod:
- Manages kernel module context (
kmod_ctx) - Centralizes error handling with
g_error_msgbuffer - Iterates loaded modules via
/proc/modules - Handles module loading/unloading through kernel syscalls
main.c - CLI interface:
- Command dispatcher (load, unload, list, check, help)
- Pretty-printed output formatting
- Argument parsing and validation
make # Clean, build, and linkmake cleanmake check-deps# View available make targets
make helpTo add new functionality:
- Add API function in
include/module_manager.h - Implement function in
src/module_manager.cusing libkmod - Add CLI command handler in
src/main.c - Rebuild with
make
// module_manager.h
int mm_get_size(const char *name);
// module_manager.c
int mm_get_size(const char *name) {
// Implementation using libkmod
struct kmod_module *mod;
kmod_module_new_from_name(g_ctx, name, &mod);
long size = kmod_module_get_size(mod);
kmod_module_unref(mod);
return size;
}
// main.c
int cmd_size(int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: kmm size <name>\n");
return 1;
}
long size = mm_get_size(argv[2]);
printf("Module size: %ld bytes\n", size);
return 0;
}- Requires root to load/unload modules (use
sudo) - Only lists loaded modules (built-in modules may not appear)
- No module parameter persistence across reboots
- Cannot load built-in modules (already in kernel)
- Logging to file (
~/.local/share/KMM/kmm.log) - Dependency resolution (prevent unload if depended upon)
- Module search in standard directories (
/lib/modules/...) - Module reload functionality
- JSON output format
- Configuration file support
Install libkmod development headers:
sudo apt-get install libkmod-devUse sudo:
sudo ./kmm load ./my_module.koVerify module file path is correct and file exists:
ls -la /path/to/module.koUse ./kmm check to verify current state:
./kmm check my_moduleKMM/
├── README.md # This file
├── Makefile # Build configuration
├── include/
│ └── module_manager.h # Public API header (55 lines)
├── src/
│ ├── main.c # CLI dispatcher (176 lines)
│ └── module_manager.c # libkmod implementation (230+ lines)
└── build/ # Build artifacts (generated)
├── main.o
├── module_manager.o
└── kmm # Final executable
KMM is optimized for speed and minimal memory usage:
- Single-pass module listing (O(n) complexity)
- Lazy context initialization
- Immediate resource cleanup
- Typical execution time: <50ms for list operations
This project is distributed under the GPL-3.0 License.
To contribute improvements:
- Test thoroughly on your system
- Ensure no memory leaks (
valgrindrecommended) - Keep code style consistent
- Update README if adding features
# Test help
./kmm help
# List modules
./kmm list | head -5
# Check specific modules
./kmm check vboxdrv
./kmm check nonexistent
# Load test (requires .ko file and sudo)
# sudo ./kmm load ./test_module.koFor issues or questions:
- Check the Troubleshooting section
- Verify libkmod is installed:
pkg-config --modversion libkmod - Check kernel module support:
ls /lib/modules/$(uname -r)/
Last Updated: January 2026
Kernel Module Manager (KMM) - Manage kernel modules with ease