Kernel module

From LQWiki
(Redirected from Kernel modules)
Jump to: navigation, search

A Kernel Module is a program that is not actually compiled into the Linux kernel but is loaded separately. Kernel modules enable you to extend the capabilities of the kernel without the need to build extra functionality directly into the kernel image. A good example is the device driver.

There are certain advantages with using kernel modules as opposed to having the drivers compiled into the kernel. They can be unloaded (rmmod) and reloaded (modprobe, insmod) at any time, allowing you to pass different parameters to them rather than specify them once on bootup as kernel parameters or update them without rebooting. The fewer drivers you need, the fewer modules you need to load and the less memory Linux needs to operate. Also, to upgrade a modularized driver you just need to recompile the module, whereas if the driver is part of the kernel then you have to recompile the kernel. For hotpluggable buses like USB, the modules can be loaded on demand rather than all at once.

Some drivers, like disk drivers and file system drivers, aren't normally used as modules since the kernel requires them to load modules in the first place. But by using initrd even these can be a module.

Information like author, license, version, dependencies and parameters can be found by using the modinfo command. Here's an example how you can do this:

$ lsmod
Module                  Size  Used by
ip6table_mangle         6528  0
iptable_mangle          7040  0
iptable_nat            11524  0
ip_nat                 21804  1 iptable_nat
...
$ modinfo ip_nat
filename:       /lib/modules/2.6.18.8-0.1-default/kernel/net/ipv4/netfilter/ip_nat.ko
license:        GPL
vermagic:       2.6.18.8-0.1-default SMP mod_unload 586 REGPARM gcc-4.1
supported:      yes
depends:        ip_conntrack,nfnetlink
srcversion:     48A7F287EB608F3BCDE5A68

See also