LPI Linux Certification/Kernel Runtime Management & Query
Weight: 4
Description:
Candidates should be able to manage and/or query a kernel and kernel loadable modules.
- Key knowledge area(s):
- Use command-line utilities to get information about the currently running kernel and kernel modules.
- Manually load and unload kernel modules.
- Determine when modules can be unloaded.
- Determine what parameters a module accepts.
- Configure the system to load modules by names other than their file name.
- The following is a partial list of the used files, terms and utilities:
- /lib/modules/kernel-version/modules.dep
- /etc/modules.conf
- /etc/modprobe.conf
- depmod
- insmod
- lsmod
- rmmod
- modinfo
- modprobe
- uname
Obtain information about kernel and modules
[edit | edit source]To display version of currently running kernel use uname command:
uname -r uname -v
lsmod command can be used to display currently loaded kernel modules:
$ lsmod Module Size Used by nls_iso8859_1 3261 0 nls_cp437 4931 0 vfat 9201 0 fat 48240 1 vfat usb_storage 40172 0 .............
Used by column shows how many modules are dependent on a given one. In example above vfat depends on fat which has to be loaded first.
Loading and Unloading Modules
[edit | edit source]To load and unload kernel modules you need superuser privileges.
insmod - this command can be used to load kernel module (however use of modprobe is recommended). It is automatically located by the tool but this command works at low level and does not resolve module dependencies. Command below fails because vfat module requires fat to be loaded first:
# insmod /lib/modules/2.6.35-22-generic/kernel/fs/fat/vfat.ko insmod: error inserting '/lib/modules/2.6.35-22-generic/kernel/fs/fat/vfat.ko': -1 Unknown symbol in module
When we load fat module first everything works fine:
# insmod /lib/modules/2.6.35-22-generic/kernel/fs/fat/fat.ko # insmod /lib/modules/2.6.35-22-generic/kernel/fs/fat/vfat.ko
rmmod - this command can be used to remove modules from running kernel. As insmod it will not resolve dependencies:
# rmmod fat ERROR: Module fat is in use by vfat # rmmod vfat # rmmod fat
modprobe - this command allows to load and unload modules and automatically resolves dependencies using System.map file (ie. /lib/modules/2.6.31-21-generic/modules.dep). To load module use command with module name as parameter. It will make sure all required modules are loaded as well:
# modprobe vfat
To remove module using modprobe command use -r switch:
# modprobe -r vfat
To list all available modules for currently running kernel use -l switch:
# modprobe -l .................. kernel/drivers/net/ne2k-pci.ko kernel/drivers/net/8390.ko kernel/drivers/net/pcnet32.ko kernel/drivers/net/e100.ko kernel/drivers/net/tlan.ko kernel/drivers/net/epic100.ko kernel/drivers/net/smsc9420.ko kernel/drivers/net/sis190.ko kernel/drivers/net/sis900.ko ..................
To determine whether a module can be safely removed use lsmod command described above. You have to make sure that number in the last column is 0 (so that no modules are using the one you are removing)
Getting Information About Modules
[edit | edit source]modinfo - can be used to display information about a module. Common switches are -a to display author information, -d to display description and -p to display options (parameters) a module accepts:
$ modinfo bonding filename: /lib/modules/2.6.35-22-generic/kernel/drivers/net/bonding/bonding.ko alias: rtnl-link-bond author: Thomas Davis, tadavis@lbl.gov and many others description: Ethernet Channel Bonding Driver, v3.6.0 version: 3.6.0 license: GPL srcversion: EC8FCCE4D57BF7B3823F70F depends: vermagic: 2.6.35-22-generic SMP mod_unload modversions 686 parm: max_bonds:Max number of bonded devices (int) parm: num_grat_arp:Number of gratuitous ARP packets to send on failover event (int) parm: num_unsol_na:Number of unsolicited IPv6 Neighbor Advertisements packets to send on failover event (int) parm: miimon:Link check interval in milliseconds (int) .....................
Creating Name Aliases
[edit | edit source]To create an alias which used by modprobe command it needs to be added to one of its configuration files. It could be either /etc/modprobe.conf or a file in /etc/modprobe.d/ directory. Sample entries below define eth0 as an alias for bnx2 network card driver and scsi_hostadapter will be an alias for mptbase. Once entries are added one can use modprobe eth0 to load bnx2 network card module.
alias eth0 bnx2 alias scsi_hostadapter mptbase