Kernel Modules & Device Management
Module 6 · Processes, Kernel & Hardware

Kernel Modules & Device Management

Kernel space vs. user space, loading and managing kernel modules, and the udev/lspci/lsusb toolkit for identifying attached hardware.

Kernel Space vs. User Space

The kernel splits memory into two protected regions:

SpaceRunsAccess level
Kernel spaceThe kernel itself, plus system modules like device drivers and filesystem codeFull, unrestricted hardware access
User spaceEverything else — your applications, shells, and servicesRestricted; must go through the kernel to touch hardware

This split exists for stability and security: a crash or bug in a user-space application can’t take down the whole system, because it never has direct access to memory or hardware it doesn’t own.

Kernel design philosophies differ in how much lives in kernel space:

TypeApproach
Monolithic (Linux)Nearly everything — drivers, filesystems, networking — runs in kernel space for performance, with modules allowing pieces to load/unload dynamically
MicrokernelThe kernel itself runs the bare minimum needed for a functional OS; most services run in user space instead, favoring isolation and fault tolerance over raw speed

Check which kernel a system is running with uname -r (version) or uname -s (just the kernel name — “Linux”).

The kernel’s major layers, each responsible for one core job: the system call interface (handles calls from user applications into the kernel), process management, memory management, and filesystem management — plus device management, covered later in this lesson.


Kernel Modules

A kernel module is a system-level object that extends kernel functionality — a driver, filesystem, or feature — without recompiling or rebooting the entire kernel. Modules for the running kernel live under /lib/modules/$(uname -r)/, organized into subdirectories by purpose:

SubdirectoryContains modules for
kernel/arch/Architecture-specific support
kernel/crypto/Encryption and other cryptographic functions
kernel/drivers/Hardware device drivers
kernel/fs/Filesystem types
kernel/net/Networking components — firewalls, protocols

Managing modules:

TaskCommand
List currently loaded moduleslsmod
Show detailed information about one modulemodinfo modulename
Load a module into the running kernel (no dependency resolution)insmod modulename.ko
Unload a modulermmod modulename
Load or unload a module, automatically resolving dependenciesmodprobe modulename / modprobe -r modulename
Rebuild the module dependency databasedepmod — updates modules.dep, scanning /lib/modules/[kernel_version]/ for every module
⚠️ Common Pitfall: insmod Doesn't Resolve Dependencies — modprobe Does

insmod loads exactly the module you name and nothing else — if that module depends on another module that isn’t already loaded, it fails outright. modprobe consults modules.dep (built by depmod) and loads the full dependency chain automatically. Use modprobe for anything beyond quick testing.

Loaded modules can call functions defined in other modules through kernel symbols — exported functions and objects that let modules interoperate instead of duplicating code (visible via /proc/kallsyms).

Persisting module configuration:

LocationPurpose
/etc/modprobe.d/*.confSettings that apply persistently to modules loaded on this system — blacklisting a module, setting load-time options
/sys/module/modulename/parameters/Configurable runtime parameters for a currently-loaded module
sysctlView or set kernel parameters at runtime generally (not module-specific) — sysctl -a to list all, sysctl -w param=value to set one
/etc/sysctl.conf (and /etc/sysctl.d/*.conf)Persist sysctl parameter changes across reboots

Identifying and Managing Hardware

TaskCommand
Display hardware info as reported by the kernel, in detaillshw (add -short for a compact one-line-per-device summary)
List devices on the USB buslsusb
List devices on the PCI buslspci
Dump the system’s DMI/SMBIOS table (motherboard, BIOS, memory module details)dmidecode
Live kernel/hardware event log — the first place to check after plugging something indmesg

Hot-pluggable devices (USB drives, eSATA disks) can be physically added or removed without a reboot. udev is the subsystem that manages automatic detection and configuration of hardware as it appears or disappears, working from a layered set of rule directories:

DirectoryPurpose
/usr/lib/udev/rules.d/Default rules shipped by the distribution/packages
/etc/udev/rules.d/Custom, administrator-authored rules — takes precedence over the defaults
/run/udev/rules.d/Rules generated dynamically by the running system
TaskCommand
Manage the udev subsystemudevadm
Show device attributes udev sees for a given deviceudevadm info /dev/sdb
Watch udev events liveudevadm monitor
Manually trigger udev to re-process devicesudevadm trigger

Device bus and connector reference:

TermWhat it is
SATABus interface standard for attaching storage devices to traditional computers
PCIeExpansion bus interface standard for attaching peripheral cards (network, storage controllers, GPUs)
HBA (Host Bus Adapter)Hardware component connecting a host system to a storage device/network
NIC (Network Interface Card)Provides the physical interface for a host to exchange data over a network
GPIOGeneral-purpose pins on a circuit board with no fixed, dedicated function — configurable by software

Printing: CUPS (Common UNIX Printing System) is Linux’s print management system. Submit a file for printing with lp or lpr; check the print queue with lpstat or lpq.

⚠️ Common Pitfall: Common Hardware Troubleshooting Pattern

When hardware “isn’t working,” the order of checks is: is it detected at all (lsusb/lspci/dmesg)? If detected, is the right driver/module loaded (lsmod, modinfo)? If loaded, is there a udev rule misconfiguring its permissions or naming? Working top-down through that chain — bus, driver, udev — resolves the large majority of “device not working” tickets faster than guessing.


🧠 Knowledge Check

1. You run insmod on a module that depends on another module which isn't currently loaded. What happens?

2. Where should a custom, administrator-authored udev rule live so it takes precedence over the distribution's defaults?

3. A USB device plugged into a Linux system doesn't appear to work. What's the correct first diagnostic step?


What’s Next

Module 7 moves up a layer: system-wide configuration, the graphical stack, and how software actually gets installed.