This installment introduces loadable kernel modules (LKMs): code you can add to a running Linux kernel, often to provide hardware support. It starts with a minimal module that logs when it is loaded or removed, then shows how to build an external .ko file and manage it with standard module tools. The key modern caveat is to build against the prepared kernel tree for the exact target—and to account for that kernel’s module-signing policy.
What a loadable kernel module does
A configured Linux kernel can provide functionality either by compiling it directly into the kernel or by building it as a module that can be loaded later. Modules are commonly used for hardware support, but they can also add filesystem support or other kernel functionality. The earlier installment in Michael Eager’s series recaps the kernel build products: the kernel image (often named vmlinuz), an initial RAM filesystem (initramfs, historically also called initrd), and System.map. Modules complement those build products; they are not a replacement for the kernel itself.
Three introductory device classes
- Character devices expose data as a sequential stream of bytes.
- Block devices move data in fixed-size blocks and commonly underpin filesystems.
- Network devices provide packet-oriented interfaces.
This is a useful starting distinction, not a complete map of Linux’s device model. A real driver must use the appropriate kernel subsystem and interface for its hardware.
Build a minimal module
The example module, lkm.c, has one entry point for loading and another for removal. Its load-time function writes a message to the kernel log; its cleanup function writes a message when the module is removed. In the older example these functions are named init_module() and cleanup_module(). A conventional modern style uses initialization and exit functions registered with module_init() and module_exit(); either way, the essential idea is that the kernel invokes the entry point on load and the cleanup routine on removal.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
A minimal modern-style source file can look like this:
#include <linux/init.h>
#include <linux/module.h>
static int __init lkm_init(void)
{
pr_info("lkm: loadedn");
return 0;
}
static void __exit lkm_exit(void)
{
pr_info("lkm: removedn");
}
module_init(lkm_init);
module_exit(lkm_exit);
MODULE_LICENSE("GPL");
The message-writing calls emit records to the kernel log, not to the terminal that ran the load command. pr_info() is the modern convenience form used above; the historical article uses printk. The license declaration supplies module license metadata. It does not sign the module or determine whether signature enforcement is active.
Build against the target kernel
External modules should use the kernel build system rather than a standalone compiler invocation. The kernel documentation states, “kbuild is the build system used by the Linux kernel.” Follow the current Building External Modules documentation for the target kernel.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
For an external module in the current directory, a simple Makefile can declare the module and invoke kbuild:
obj-m := lkm.o
all:
make -C <kernel-build-directory> M=$PWD
clean:
make -C <kernel-build-directory> M=$PWD clean
Replace <kernel-build-directory> with the prepared build tree for the kernel that will run the module. The kernel documentation gives the command form make -C <kernel-directory> M=$PWD; for Linux 6.13 and later, it also documents using -f instead of -C. The build tree needs the relevant kernel configuration and headers, and the kernel must have module support enabled. The result is a loadable object such as lkm.ko.
Match the build tree to the device
- For a module intended for the machine you are using, use that machine’s running kernel’s matching prepared build files.
- For embedded or cross-development, use the prepared build tree and configuration for the target kernel—not the development host’s kernel merely because it is convenient.
- Obtain matching development files or build artifacts from the target distribution or device vendor, and follow documentation for that kernel version.
The historical example’s terminal output identifies Fedora 19 and Linux 3.12.8 and uses the then-current kernel-devel package name. Those details describe that example’s environment, not a universal or current package-installation recipe.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Inspect, load, and remove the module
Once the build produces lkm.ko, the basic tools show its metadata and exercise its lifecycle. Loading with insmod requires the module’s path; it does not resolve dependencies for you.
- Inspect metadata: run
modinfo ./lkm.ko. This reports available module metadata, including fields such as its license declaration. - Load the file directly: run
sudo insmod ./lkm.ko. A successful load adds the module to the running kernel; the message goes to the kernel log. - Check loaded modules: run
lsmodand look forlkm. - Remove it: run
sudo rmmod lkm. Pass the module name, not the filename ending in.ko.
Use the system’s kernel-log viewer to find the messages emitted by the module; the exact command or interface varies by distribution. A load can fail if the module was built for a different kernel, the kernel rejects its signature, a required dependency is unavailable, or the module’s initialization routine returns an error.
Install for dependency-aware loading
For managed loading, place the module in the module tree for the kernel version it targets, update the dependency information, and use modprobe. The older article demonstrates copying a file into a kernel-specific directory and running depmod -a; for current systems, use the target distribution’s prescribed installation path and packaging workflow rather than copying the old path blindly.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
- Install the built module into the target kernel’s module tree. The kernel build documentation supports installation through the
modules_installtarget; consult the target system’s documentation for the appropriate destination and deployment procedure. - Run
depmod -afor the relevant installed kernel so dependency and module-map information is refreshed. - Run
sudo modprobe lkmto load by module name. Unlikeinsmod,modprobecan use dependency information to load required modules. - Run
sudo modprobe -r lkmto request removal through the same dependency-aware tool.
These commands operate on the module tree and kernel selected by the running system unless the relevant tools are explicitly directed otherwise. In an embedded deployment, ensure the installed module tree, dependency metadata, and kernel image all belong to the same target build.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Understand taint, license metadata, and signatures
A kernel may mark itself tainted after loading certain modules. Taint records conditions relevant to kernel support and debugging; it is not itself proof that the module is broken. The historical example reported taint in connection with missing license metadata and an absent signature. These are distinct issues: a license declaration describes the module’s licensing metadata, while a signature is cryptographic data checked by the kernel’s module-signing mechanism.
As described in the current Kernel module signing facility documentation, actual loading behavior depends on kernel configuration and boot parameters. In a permissive configuration, an unsigned module or one signed by an unknown key may be allowed to load and may taint the kernel. If CONFIG_MODULE_SIG_FORCE is enabled, or the kernel is booted with module.sig_enforce=1, only modules with valid signatures trusted by that kernel are accepted. A malformed signature is rejected.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
For debugging a kernel problem, report whether out-of-tree or proprietary modules are loaded and whether the kernel is tainted; that context can matter when diagnosing a failure. Do not treat adding MODULE_LICENSE as a substitute for signing, or assume that every system accepts unsigned modules.
From the logging example to a useful driver
The minimal module demonstrates the build and load cycle, but it does not control hardware. The next step is a module that registers with the appropriate kernel subsystem and implements a device interface. In this series, the next installment points toward a simple character-device driver. That progression keeps the essential workflow visible: choose the right device interface, build for the exact target kernel, load under its policy, and inspect behavior through kernel logging and subsystem tools.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

