Loadable Kernel Modules in linux Kernel 2.6
Learning Objectives
- Discuss History of Loadable Kernel Modules (LKM).
- Describe advantages of Using LKMs
- Describe what LKMs can do.
- Discuss LKM Utilities
- Installing and removing
- Loadable Kernel Modules in Kernel 2.6
Reference
- Module-HOWTO
- /usr/share/doc/howto/en/html/Module-HOWTO
History of Loadable Module
- Loadable Kernel Modules did not exist in Linux in the beginning.
- Loadable Kernel Modules have been around at least since Linux1.2 (1995).
- Device drivers were always quite modular, and only small amount of work was needed to make them Loadable Kernel Module.
- Since about 2000 everything that make sense as an LKM had the option of being LKM.
Advantages of using LKMs
- Don’t have to rebuild Kernel Often
- Helps you diagnose system problem
- Saves Memory because only required modules will be loaded in the memory.
- Faster to maintain and debug.
- Gives same performance as Kernel built-in code.
What LKMs can Do
- Device drivers
- File System Drivers
- System Calls
- Network Drivers
- TTY line disciplines
- Executable interpreters
Building Kernel Modules
- Loadable Kernel Modules are also know as Kernel Modules.
- After building the Kernel image issue following commands: make modules Above command compiles the source code and creates module object files
- Then issue the following commandsmake modules_installAbove command will copy all modules over to the conventional locations
Loadable kernel Module Utilities
- insmod Insert an LKM into the kernel.
- rmmod Remove an LKM from the kernel.
- depmod Determine interdependencies between LKMs.
- lsmod List currently loaded LKMs.
- modinfo Display contents of .modinfo section in an LKM object file.
- modprobe Insert or remove an LKM or set of LKMs intelligently. For example, if load A before loading B, Modprobe will automatically load A when you tell it to load B.
Inserting kernel Modules
- Basic program for inserting LKMs is insmod.
- Try to load the modules “msdos” and “ntfs”.
- Try following commands to load the modules msdos, the path for module may change depending on your Kernel Version:
# cd /lib/modules/2.6.18-53el5/kernel/fs
# insmod msdos/msdos.ko
Listing the loaded modules
- Loaded modules may be listed by using the “lsmod” command.
- You may also get information about modules from “/proc/modules”cat /proc/modules
- You may also get information about “devices” and “interrupts” from “/proc/devices” and “/proc/interrupts”
Removing Modules
- Modules may be removed by using “rmmod” command.
- All these commands must be executed by superuser.
Using modprobe
- Using modprobe is a better way of loading modules. Modprobe checks dependencies and also loads the modules needed to support the module being loaded.
- Many modules such as some CDROM Drivers and Networks Drivers require certain parameters to be passed with the modules.
- The files “/etc/modprobe.conf”, “/etc/modprobe.conf.local” and the directory “/etc/modprobe.d” contains parameters for modules that directly access the hardware. As modprobe can use information from these files it is a better method to load modules.
- There are no standard module parameters, drivers may have their own set of parameters. To find out parameters of a driver read the documentation for that module in the directory “/usr/src/linux/documentation”.
Kmod – The Kernel Module Loader
- Kmod automates the process of loading Kernel Module.
- Kmod keeps on running in the background and automatically loads a kernel Module using “modprobe” whenever a desired feature is needed in the Kernel.
- Kmod does not unload the modules if not required in feature but with Amount of RAM available this is not a big issue.
Modules in Linux kernel 2.6
- The Linux 2.6 kernel introduces a new, unified framework for device drivers, which requires changes to custom device drivers developed to run under earlier versions of the Linux kernel.
- The new driver model provides a framework for full and complete support for
- device Plug and Play
- power management
- Defines the interfaces that these subsystems can use when communicating with individual drivers.
- The new driver framework provides a much cleaner separation of responsibilities between buses and drivers.
- The 2.6 Linux kernel also introduces the sysfs filesystem to provide a hierarchical view of each system's device tree (and to prevent further overloading of the proc filesystem).
- A new naming convention for loadable kernel modules, using the .ko extension (kernel object) rather than the standard .o (object) extension used in all previous stable releases of the Linux kernel.
Summary
- Kernel loadable module reduce the size of Kernel.
- It is easier to debug your system when using Kernel Modules.
- New drivers can be added to system without recompiling the Kernel.
- A set of utilities is available to manage Kernel Modules.