Kernel
Kernel Modules
Many components of the kernel can be compiled as dynamically loadable modules. This allows for increased kernel functionality without increasing the size of the kernel image loaded at the boot time.
Good candidates for modularization are
- Components that need not be resident in the kernel for all configurations and hardware
- peripheral device drivers
- supplementary filesystems
The kernel modules reside in /lib/modules/<kernel_version> directory
Controlling modules
- lsmod lists the modules currently resident in the kernel
- insmod is used to load a particular module
- rmmod unloads a module if it is idle
Controlling modules intelligently
Many modules depends on other module to be present.
- A database of module dependencies can be generated using depmod command
- modinfo shows the information about a linux kernel module
- modprobe can be used to load kernel modules
The advandage of using modprobe over insmod are:
- modprobe will load any underlying modules required by a given module
- modprobe will consult /etc/modprobe.conf (/etc/modules.conf in old systems) for default module configurations
modprobe -v module_name
Module configuration
Many modules accept parameters that can be specified at the load time. Default values for various parameters can be specifield in /etc/modprobe.conf (/etc/modules.conf in old systems). When modprobe loads a module, it will consult this file for appropriate defaults.
Examples:
# lsmod Module Size Used by md5 4161 1 ipv6 268865 14 sunrpc 168453 1 dm_mod 58613 0 uhci_hcd 35281 0 i2c_piix4 8913 0 i2c_core 21825 1 i2c_piix4 ...... ...... # modinfo md5 filename: /lib/modules/2.6.12-1.1447_FC4/kernel/crypto/md5.ko license: GPL description: MD5 Message Digest Algorithm vermagic: 2.6.12-1.1447_FC4 686 REGPARM 4KSTACKS gcc-4.0 depends: srcversion: 70F89E71D506DA03F4BDCA3 # cat /etc/modprobe.conf alias eth0 e100 alias eth1 3c59x alias snd-card-0 snd-cs4236 options snd-card-0 index=0 options snd-cs4236 index=0
Tips: If a kernel module is not loading (test it using lsmod), run depmod command first. It will create all the dependents for all the modules. Then load the module using modprobe -v <module_name> command.
The /proc filesystem
- /proc is a virtual filesystem containing information about the running kernel
- It is a map to the running kernel
- Contens of “files” under /proc can be viewed using ‘cat’ commnad
- Provides information on system hardware, networking settings and activity, memory usage and more.
- /proc has number of subdirectories
- The /proc/sys subdirectory allows administrators to modify certain parameters of a running kernel
Some of the key files in top-level directory include:
/proc/interrupts, /proc/dma, /proc/ioports - IRQ, DMA and I/O settings
/proc/cpuinfo - Information about the system CPUs
/proc/meminfo - Information on availabel, free memory, swap, cached memory
/proc/version - Information on Kernel version, build host, build date, etc.
Some important subdirectories include:
/proc/scsi, /proc/ide -- information about SCSI and IDE devices
/proc/net -- Network activity and configuration
/proc/sys -- Kernel configuration parameters
/proc/<PID> -- information about process ID
The /proc/sys subdirectory allows administrators to modify certain parameters of a running kernel.
echo “1” > /proc/sys/net/ipv4/ip_forward # Turn on IP forwarding.
Changing Kernel Parameters (/proc/sys configuration) using sysctl :
- /proc/sys modifications are temporary and not saved at system shutdown
- The sysctl command manages such settings in a static and centralized fashion using /etc/sysctl.conf file
- sysctl is called at boot time by rc.sysinit and uses settings in /etc/sysctl.conf
With the sysctl, you specify a path to the variable, with /proc/sys being the base.
For example, to view /proc/sys/net/ipv4/ip_forward, use the following command:
# sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 1
To then update this variable temporarily, use the -w (write) option:
# sysctl -w net.ipv4.ip_forward="0" net.ipv4.ip_forward = 0
The same thing can be done by modifying /proc/sys/net/ipv4/ip_forward file
# echo "0" > /proc/sys/net/ipv4/ip_forward
To make it permanent, edit /etc/sysctl.conf file. Add or modify the "net.ipv4.ip_forward" line
net.ipv4.ip_forward=0
To re-read (make the changes to take effect) the /etc/sysctl.conf file, use the -p option
# sysctl -p net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1