Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 791 of 93611. Introduction to Embedded LinuxFree lesson

Managing Kernel Modules at Runtime

Utilize kernel utilities to insert, remove, and query the status of dynamic drivers while the embedded Linux system is actively running.

In this lesson, you will learn how to dynamically extend the functionality of an embedded Linux kernel by inserting and managing loadable kernel modules (LKMs) without requiring a system reboot.

The Modular Kernel Philosophy

A monolithic kernel can become bloated if every possible driver is compiled directly into the kernel image. To save memory in embedded systems, we use a modular design. By compiling drivers as separate .ko (Kernel Object) files, we can keep the kernel image small and only load specific hardware support when the system is actively running and the hardware is detected.

Runtime Module Management

When your embedded system is live, you interact with the kernel’s module subsystem using three primary utilities found in the kmod package:

  1. insmod / modprobe: To insert a driver. While insmod loads a specific file path, modprobe is the industry standard because it intelligently handles module dependencies (e.g., if your Wi-Fi driver requires a specific crypto module, modprobe loads both).
  2. lsmod: To query the status of currently loaded drivers. This utility parses /proc/modules to show you what is residing in kernel memory, its size, and the number of other modules currently using it (the "Used by" count).
  3. rmmod: To remove a module. This effectively unloads the driver from memory, provided no other process or module is currently relying on it.

Practical Example

If you are deploying a custom sensor driver, you might navigate to your module directory and execute the following:

# Check if the module is currently present
lsmod | grep my_sensor

# Load the module into the kernel
modprobe my_sensor

# Confirm the module is active and check the dependency count
lsmod | grep my_sensor

If you need to update the driver for a field patch, you simply run rmmod my_sensor, replace the .ko file in your filesystem, and modprobe the new version. This capability is vital for OTA (Over-The-Air) updates where minimizing downtime is critical for the reliability of the embedded application.

Key Takeaway: Managing kernel modules at runtime allows you to maintain a lean kernel image by dynamically loading and unloading hardware drivers, enabling modular system updates without interrupting the boot process.