Thursday, January 5, 2012

Installing Linux Server Modules Within The Command Line

The task of adding Linux kernel modules is a vital task for any Linux server system administrator. This article will provide a basis to understand the concepts and tools concerned. There are a number of terms used to refer to these modules, the formal phrase being "loadable kernel modules". However, you will commonly see them referred to as "modules" or "kernel modules".

Modular Kernel

The modern day Linux kernel uses a modular model allowing users to add additional functionality to the core of the operating system as and when required. In other operating systems a monolithic kernel model is used, requiring all functionality to be compiled into the kernel prior to this system being booted. In the past a monolithic kernel was preferred, as it is more efficient with regards the usage of memory resources, however nowadays most computers have multiple gigabytes of RAM available, so this is less of an issue. Being able to dynamically load kernel modules when required far outweighs any disadvantages of using slightly more memory.

So what is a kernel module? A kernel module is similar to a windows driver. A module will more often than not, provide software to handle a specific hardware device or type of device. Examples include:
  • video adapters
  • providing access to hard drives
  • DVD players
  • serial devices

Linux Kernel Tools

It is normal for kernel modules to be loaded at boot time, however due to their dynamic nature they can also be loaded at any time. A number of commands are available to the administrator for loading, unloading and finding out further information about a module.
The simplest commands for loading and unloading modules consist of "insmod" and "rmmod". The insmod command inserts a module in to the kernel, the rmmod command removes a module from your kernel. You will find a number of other commands which can be useful to understand when dealing with kernel modules. These are:
  • lsmod - lists all currently loaded modules
  • depmod - determine any dependencies a module has
  • 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 provides detailed information about the module, such as the kernel version that the module was compiled for, which can be critical when troubleshooting any problems found when attempting 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 all dependencies.
The modprobe command is basically a wrapper around insmod, rmmod and depmod, providing a single, user-friendly command. It is recommended for you to look at the help manual for modprobe if you're thinking of doing any work with loading or unloading Linux kernel modules.

Linux kernel modules are typically found under /lib/modules/[kernel-version] where by [kernel-version] is the kernel version number you are looking at. It is likely that you will see many different kernel versions in this directory and you should ensure that any modules you compile are placed in the directory matching to the kernel version you are doing work on.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.