1. Context 1.105.1 2 1 Context Topic 105 Kernel [7] 1.105.1 Manage/Query kernel and kernel modules at runtime Weight 4 Linux Professional Institute Certification — 102 1.105.1 Manage/Query kernel and kernel modules at runtime [4] 1.105.2 Reconfigure, build, and install a custom kernel and kernel [3] 2 Objectives Angus Lees gus@inodes.org Nick Urbanik nicku@nicku.org This document Licensed under GPL—see section 8 2005 July Outline Description of Objective Candidates should be able to manage and/or query a kernel and kernel loadable modules. This objective includes using command-line utilities to get information about the currently running kernel and kernel modules. It also includes manually loading and unloading modules as appropriate. It also includes being able to determine when modules can be unloaded and what parameters a module accepts. Candidates should be able to configure the system to load modules by names other than their file name. Key files, terms, and utilities include: /lib/modules/kernel-version/modules.dep — the file built by depmod showing which module depends on what other modules /etc/modules.conf & /etc/conf.modules — configuration file for modprobe 2 2 2 3 3 3 3 4 4 4 5 5 depmod — determines module dependencies and rebuilds modules.dep insmod — low level command to insert a module into running kernel lsmod — list modules loaded into kernel rmmod — low level command to remove a module from kernel modinfo — shows details about a particular module Contents 1 2 3 4 5 Context Objectives Documentation Kernel Modules Utilities 5.1 uname . . 5.2 lsmod . . . 5.3 modprobe 5.4 modinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . modprobe — the tool for inserting and removing modules into/from the running kernel uname — shows information about the system, including the kernel version info. 6 7 8 /etc/modules.conf Low level commands License 3 Documentation • linux-source /Documentation/ Manage/Query Kernel and kernel modules at runtime 4. Kernel Modules 1.105.1 3 5.3 modprobe 174400 34088 10560 40552 1.105.1 0 1 0 2 parport_pc,lp 4 4 Kernel Modules • Kernel modules are chunks of kernel code which can get loaded and unloaded at runtime. • Some modules depend on code in other modules. • Good for shipping pre-built kernels – but not loading all available code; good for changing between conflicting modules (eg. OSS and ALSA), etc. Kernel Module Basics irda parport_pc lp parport 5.3 modprobe modprobe – Loading and removing modules Load a module and its dependencies: $ sudo modprobe modulename [ module options ] ← eg: $ sudo modprobe ftape ft_fdc_base=0x123 ← Unload a module if it’s unused: $ sudo modprobe -r modulename ← eg: $ sudo modprobe -r ftape ← 5 Utilities 5.1 uname uname – Who the kernel thinks it is Modules are stored in /lib/modules/$(uname -r)/kernel/ -a print all information -s kernel name (“Linux”) -n “node name” (hostname) -r kernel release (“2.4.20-3-686”) -v kernel version (compile time) -m machine hardware name (“i686”) -o operating system (“GNU/Linux”) 5.4 modinfo modinfo – Module options “modinfo ftape” gives: parm: parm: parm: parm: . . . author: description: license: ft_fdc_base:Base address of FDC controller. ft_fdc_irq:IRQ (interrupt channel) to use. ft_fdc_dma:DMA channel to use. ft_fdc_threshold:Threshold of the FDC Fifo. (c) 1993-1996 Bas Laarhoven (bas@vimec.nl), (c) 1995-1996 Kai Harrekil QIC-117 driver for QIC-40/80/3010/3020 floppy tape drives. GPL 5.2 lsmod lsmod – Currently loaded modules lsmod uses /proc/modules to show you which kernel modules are currently loaded. Module bsd_comp ppp_async ppp_generic slhc ipv6 ds pcmcia_core Size 5888 10624 29072 7040 230624 14596 62688 Used by 1 1 6 bsd_comp,ppp_async 1 ppp_generic 10 0 1 ds 6 /etc/modules.conf modprobe maintenance Configuration in /etc/modules.conf (aka /etc/conf.modules). # bogus example options ftape ft_fdc_base=0x123 fg_fdc_irq=5 ft_fdc_dma=1 alias char-major-27 ftape depmod builds modules.dep, describing module dependencies. 7. Low level commands 1.105.1 5 7 Low level commands Loading modules - low-level Low level commands to actually insert or remove a module: insmod filename module options rmmod modulename You will probably never use these directly; use modprobe or modprobe -r instead. 8 License License Of This Document Copyright c 2005, 2003 Angus Lees and Nick Urbanik . Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation—either version 2 of the License or (at your option) any later version.