What is a Kernel Module =========================== Traditional way of adding code to the kernel was to recompile the kernel and reboot the system Kernel Modules are piece of code that can be loaded/inserted and unloaded/removed from the kernel as per the demand/need. Other Names =============== 1. Loadable Kernel Modules (LKM) 2. Modules Extension: .ko (Kernel Object) Standard Location for Kernel Modules ==================================== Modules are installed in the /lib/modules/ directory of the rootfs by default. Device Driver vs Kernel Modules =============================== A kernel module may not be a device driver at all. A driver is like a sub-class of module. Modules are used for the below: 1. Device Drivers. 2. File System 3. System Calls 4. Network drivers: Drivers implementing a network protocol (TCP/IP) 5. TTY line disciplines: For terminal devices Advantages of Kernel Modules ============================= 1. All parts of the base kernel stay loaded all the time. Modules can save you memory, because you have to have them loaded only when you're actually using them 2. Users would need to rebuild and reboot the kernel every time they would require a new functionality. 3. A bug in driver which is compiled as a part of kernel will stop system from loading, whereas module allows systems to load. 4. Faster to maintain and debug 5. Makes it easier to maintain multiple machines on a single kernel base. Disadvantages of Kernel Modules =============================== 1. Size: Module management consumes unpageable kernel memory. a basic kernel with a number of modules loaded will consume more memory than an equivalent kernel with the drivers compiled into the kernel image itself This can be a very significant issue on machines with limited physical memory 2. As the kernel modules are loaded very late in the boot process, hence core functionality has to go in the base kernel (E.g. Memory Management) 3. Security: If you build your kernel statically and disable Linux's dynamic module loading feature, you prevent run-time modification of the kernel code. Configuration ================= In order to support modules, the kernel must have been built with the following option enabled: CONFIG_MODULES=y