Kernel & Modules
Kernel & Kernel Modules
The kernel needs to know how to talk to thousands of different pieces of hardware - graphics cards, network cards, filesystems, USB controllers - but no single machine has all of them installed at once. Compiling drivers for every possible device permanently into the kernel would make it enormous and slow to load.
The solution is kernel modules: small pieces of kernel code (files ending in .ko, for "kernel object") that can be loaded into the running kernel on demand and unloaded again when not needed - without rebooting.
Analogy: Think of the kernel as a phone with a fixed set of built-in apps, and modules as apps you install afterward. You don't ship every possible app pre-installed - you install the ones the device actually needs, and you can add or remove them while the phone keeps running.
| Command | Purpose |
|---|---|
uname -r | Running kernel version |
lsmod | List loaded modules |
modinfo <mod> | Details about a module |
modprobe <mod> | Load a module and its dependencies |
modprobe -r <mod> | Unload a module |
insmod / rmmod | Low-level load/unload (no deps) |
Module config lives in /etc/modprobe.d/ (options, blacklists) and the modules themselves are stored under /lib/modules/$(uname -r)/ - note that path includes the exact running kernel version, because modules built for one kernel version generally won't load into a different one.
$ uname -r
5.15.0-91-generic
$ lsmod | head -3
Module Size Used by
xt_conntrack 16384 1
Reading that lsmod output: each row is one loaded module, its size in memory, and how many other things depend on it (Used by) - a module with dependents can't be unloaded until they're gone.
Warning:modprobeandinsmodsound interchangeable but aren't.modprobelooks up a dependency map (built bydepmod, stored inmodules.dep) and automatically loads anything the requested module needs first.insmodloads exactly the one file you give it and nothing else - if it depends on another module that isn't already loaded, it simply fails with an unhelpful error. Prefermodprobeunless you have a specific low-level reason not to.