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.
CommandPurpose
uname -rRunning kernel version
lsmodList loaded modules
modinfo <mod>Details about a module
modprobe <mod>Load a module and its dependencies
modprobe -r <mod>Unload a module
insmod / rmmodLow-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: modprobe and insmod sound interchangeable but aren't. modprobe looks up a dependency map (built by depmod, stored in modules.dep) and automatically loads anything the requested module needs first. insmod loads 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. Prefer modprobe unless you have a specific low-level reason not to.