160 likes | 322 Views
by Mahendra M Mahendra_M@infosys.com http://www.infosys.com/. Recompiling the Linux Kernel. Traditional Kernel Architectures. Micro Kernels Macro Kernels Modular. Micro Kernel Architecture. A Core Kernel All functionalities in User Space e.g. : File-system, Sound driver, video
E N D
by Mahendra M Mahendra_M@infosys.com http://www.infosys.com/ Recompiling the Linux Kernel
Traditional Kernel Architectures • Micro Kernels • Macro Kernels • Modular
Micro Kernel Architecture • A Core Kernel • All functionalities in User Space • e.g. : File-system, Sound driver, video • Communication Using Message Passing • Fast in Theory & Experimental Setups • Practically Slow & Less Efficient • A crash in a subsystem doesn’t bring down the whole system • e.g. : Minix, QNX, GNU/Hurd (??)
Macro Kernel Architecture • A single monolithic kernel • Everything in Kernel Space • Communication using function calls • Practically fast • Easy to implement • Crash in any region can bring down the whole system • e.g. : DOS
Linux ( The Kernel ) • Modular, Monolithic Kernel • Modules can be compiled and dynamically linked into kernel address space. • Useful for device drivers that need not always be resident until needed. • Keeps core kernel "footprint" small. • Can be used to "extend" functionality of kernel too! • Modules are loaded into kernel address space and unresolved symbols in the module are linked to the symbol table of running kernel.
Linux ( The Kernel ) contd... • Advantages • Footprint of running kernel is small • Unused modules are flushed out. Increases efficiency • Flexibility - Dynamically add new features • Disadvantages • A faulty module can bring down the system • Slight overhead in loading the modules • Advantages outweigh Disadvantages • Murphy’s law : If it ain’t broken, don’t fix it
Precautions • Compulsory non-modular cases • Hard Disk support • will prevent loading of any module, since the hard-disk cannot be probed to access modules • Filesystem of root partition • Diskless clients : ethernet drivers / NFS root filesystem • will prevent booting up of the system, since the kernel image cannot be obtained over the network. • Maybe even TCP/IP support.
Module Handling Tools • insmod - link a module into the running kernel by resolving all symbols from the kernel’s exported symbol table. • -root option for enhanced security • depmod - creates module dependency file - modules.dep • modprobe - loads all relevant modules from above • rmmod - removes unused modules • kmod - kernel thread • replacement for kerneld ( does not remove modules ) • kmod calls modprobe • together they can loop (if modules.dep is absent). Handled by a compile time option. • "kmod: runaway modprobe loop assumed and stopped” • eg : modprobe started with ‘syslog’ option. ( needs unix sockets )
Steps in loading a module • Kernel notices a feature request not resident in the kernel • Sends a message to kmod with a “symbolic description” of the feature • ‘kmod’ asks ‘modprobe’ to load a module • ‘modprobe’ looks into it’s internal “alias translation table” for a match • ‘insmod’ is asked to insert all modules needed • configured accroding to the ‘options’ in /etc/modules.conf • ‘kernel’ uses the freshly installed feature as if it was configured as a resident part
Recompiling the kernel • Why recompile ? • Feel like owning a custom made BMW. • Highly optimized than kernels in distros ( eg : i386 compilation ) • Reduce kernel footprint. • Increase efficiency. Higher performance • Notice : If you get it correct first time, contact Torvalds. • Notes ….
Notes • "Processor type" is set higher than 386 - • Will not work on a 386 • A kernel with math-emulation compiled in will still use the coprocessor if one is present • The math emulation will just never get used in that case. • Having unnecessary drivers will make the kernel bigger • Can lead to problems • It is *YOUR* call. • Enable “Magic System Request Key Hacks” • Have *FUN* !!!
The Five steps to Freedom • make config ( or gconfig/menuconfig… ) • select resident & modular parts • make dep • make bzImage • build the actual image • make modules • builds all modules • make module_install • installs the modules in /lib/modules/2.6…./
Compilation • Dependence on gcc • Work in progress • ‘-j’ option for ‘make’ • -jN ( N = Num of Processors + 1 ) • EXTRAVERSION • To protect your working modules/kernel • Don’t change VERSION, PATCHLEVEL or SUBLEVEL • Applications may refer to these
Finally • Extensive Documentation • The Kernel Source Tree • Demo . . .
Links • http://infylug/kernel • http://kernel.org • http://www.kernelnewbies.org • http://www.sudolinux.com/kernel_links.htm • Lots of Kernel related links • http://www.digitalhermit.com/linux/kernel.html • Excellent Document on Recompiling the kernel • http://www.linux.it/kerneldocs/kconf/ • Reconfiguring the Linux Kernel