The job of adding Linux kernel modules is a crucial job for any Linux server system administrator. This article will give you a basis to understand the concepts and tools involved. The official terminology is "loadable kernel modules"; however they are often referred to as simply "kernel modules" or "modules".
On all modern Linux operating systems, a modular kernel model is employed, allowing for additional functionality to be added when needed. This is the opposite of the monolithic kernel model, which requires all functionality to be compiled into the kernel prior to loading the operating system. A monolithic kernel is more efficient with regards the amount of memory it consumes, however most kernel modules consume very little memory in relation to modern computing standards where gigabytes of memory are normally available. Being able to dynamically load kernel modules when required far outweighs any disadvantages of using slightly more memory.
So what is a kernel module? Well, it is very similar to a Windows device driver Modules often provide hardware specific software functionality. For example:
- DVD players
- delivering access to hard drives
- serial devices
- video adapters
The loading of kernel modules is often done during the boot process, however modules can also be loaded after the system has booted. A number of commands are available to the administrator for loading, unloading and finding out further information about a module.
The most basic commands for loading and unloading modules are the "insmod" and "rmmod". The insmod command inserts a module in the kernel, the rmmod command removes a module from your kernel. There are a variety of other commands which can be necessary to know when dealing with kernel modules. They're:
- depmod - ascertain any dependencies a module has
- lsmod - lists all actively loaded modules
- modinfo - displays the .modinfo section of the module object file (i.e. a file with a .ko or .o file)
It is important hat to have a thorough understanding of each of the above commands when loading and unloading kernel modules. The modinfo command offers detailed information and facts concerning the module, including the kernel version which the module was compiled for, which can be critical when troubleshooting any problems encountered when trying to load a kernel module. A higher level module administration command exists for dealing with kernel modules. It is:
- modprobe - intelligently inserts or removes a Linux kernel module and any dependencies.
The modprobe command is basically a wrapper around insmod, rmmod and depmod, supplying a single, user-friendly command. It is recommended that you look at the help manual for modprobe if you are thinking of doing any work with loading or unloading Linux kernel modules.
Linux kernel modules are typically located under /lib/modules/[kernel-version] where by [kernel-version] is the kernel version number you are interested in. It is likely that you will see many different kernel versions in this directory and you should make sure that any modules you compile are placed in the directory corresponding to the kernel version you are working on.