Drivers and kernel modules
Drivers are the kernel code that knows how to operate each piece of hardware. Linux includes thousands of them, most built as modules loaded only when needed.
What drivers do
A device driver translates generic kernel requests, such as 'read these blocks' or 'send this packet', into the specific register writes, commands, and interrupt handling a particular device needs. Drivers register with kernel subsystems such as the block layer, networking stack, input layer, or graphics framework, which present uniform interfaces to user space.
Drivers in the kernel tree
Most Linux drivers live in the main kernel source tree, maintained alongside the rest of the kernel; drivers make up the majority of its tens of millions of lines of code. In-tree drivers are updated whenever internal interfaces change. Out-of-tree drivers, such as some proprietary graphics drivers, must be rebuilt for each kernel, often automatically with DKMS.
Modules
Drivers are usually compiled as loadable modules stored under /lib/modules/<kernel-version>/. lsmod lists loaded modules with their sizes and users; modinfo shows a module's description, parameters, firmware files, and supported device IDs; modprobe loads a module and its dependencies, and modprobe -r unloads it. depmod computes the dependency information modprobe uses.
Module parameters and blacklisting
Modules accept parameters, set at load time with modprobe module param=value, persistently in /etc/modprobe.d/*.conf with options lines, or on the kernel command line as module.param=value. Current values often appear under /sys/module/<name>/parameters/. A blacklist line in modprobe.d stops a module from loading automatically, for example to prevent a conflicting driver.
Firmware
Many devices, especially Wi-Fi cards, GPUs, and Bluetooth chips, need firmware: code that runs on the device itself, loaded by the driver at start-up from /lib/firmware. Firmware is usually distributed by vendors in packages such as linux-firmware. A missing firmware file is a common reason a device is detected but does not work, and the kernel log reports which file it could not find.
Bus enumeration
Devices sit on buses such as PCI Express, USB, I2C, and SPI. The kernel enumerates buses and reads each device's identifiers, such as PCI vendor and device IDs or USB vendor and product IDs. Modules declare which IDs they support, so the kernel and udev can load the right driver automatically. lspci and lsusb list devices with their IDs; lspci -k shows which driver each uses.
Device trees and ACPI
On PCs, ACPI tables provided by firmware describe devices that cannot be discovered by enumeration, along with power management. On many ARM systems, such as Raspberry Pi boards and phones, a device tree, a data structure describing the hardware, is passed to the kernel at boot so it knows which devices exist and how they are connected.
Worked example
A USB serial adapter is plugged in. dmesg shows: usb 1-2: new full-speed USB device; ch341 1-2:1.0: ch341-uart converter detected; usb 1-2: ch341-uart converter now attached to ttyUSB0. lsusb lists it with its vendor and product ID; lsmod shows ch341 and usbserial loaded automatically; and ls -l /dev/ttyUSB0 shows group dialout, so a user in that group can open it with a terminal program.
Key takeaways
Drivers translate generic kernel requests into device-specific operations and register with subsystems that present uniform interfaces. Most drivers live in the kernel tree; out-of-tree drivers are rebuilt per kernel, often with DKMS. Modules under /lib/modules are managed with lsmod, modinfo, modprobe, and depmod; parameters and blacklists live in /etc/modprobe.d. Devices often need firmware from /lib/firmware, and missing firmware is a frequent fault. Buses such as PCIe and USB are enumerated by ID, letting the right modules load automatically; lspci -k and lsusb show devices and drivers. ACPI on PCs and device trees on ARM describe non-discoverable hardware.
Flashcard
Kernel code operating specific hardware
Check your understanding
A new Wi-Fi card shows up in lspci, but no wireless interface appears and dmesg mentions a failed firmware load. What is the most likely fix?
