1 / 20

Operating Systems Lab. (#2)

Operating Systems Lab. (#2). University of Tehran – ECE Dept. Fall 2005 Reza Shokri shokri@ece.ut.ac.ir. Outline. Obtaining Kernel Source Compiling the Kernel Installing a New Linux Kernel Kernel Source Structure Kernel Debugging. Obtaining Kernel Source. Obtain Kernel Source form

hop-langley
Download Presentation

Operating Systems Lab. (#2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Lab.(#2) University of Tehran – ECE Dept. Fall 2005 Reza Shokri shokri@ece.ut.ac.ir

  2. Outline • Obtaining Kernel Source • Compiling the Kernel • Installing a New Linux Kernel • Kernel Source Structure • Kernel Debugging Operating Systems Lab - UT ECE Dept Fall 2005

  3. Obtaining Kernel Source • Obtain Kernel Source form • The official kernel site: http://www.kernel.org • While installing RedHat, select the installer to include kernel source • Source, normally is in bz2 or tgz format • linux-<kernel number>.tar.gz • Open the archive • tar –xzvf linux-<kernel number>.tar.gz Operating Systems Lab - UT ECE Dept Fall 2005

  4. Compiling the Kernel • Overview of kernel compilation • Configuring the kernel • dep, clean and mrproper • make bzImage - build the kernel image • make modules - build the modules • make modules_install and final installation • Problem solving Operating Systems Lab - UT ECE Dept Fall 2005

  5. Overview • Compiling the kernel is composed of three stages: • Configuration • building (compiling) • installing • It’s really quite simpler than it appears, and it’s very hard to cause damage and end with a non booting system • We will go over the steps together, configuring, building and installing the latest kernel Operating Systems Lab - UT ECE Dept Fall 2005

  6. Configuration • Configuring the kernel can be non trivial, since you have to include support for your hardware for things to work • If you’ve done it before and saved the .config, just do ’make oldconfig’. ’make oldconfig’ will only asked about new configuration choices and use your old choices for everything else • Otherwise, run ’make menuconfig’ or ’make xconfig’, and start going through the options, based on your computer’s hardware • Alternatives include ’make defconfig’, for a “default” configuration, and copying a distribution’s .config for a configuration that should fit almost everything Operating Systems Lab - UT ECE Dept Fall 2005

  7. dep, clean, and mrproper • After configuring the kernel, you need to do ’make dep’, in order to generate dependency information and cause various build magic to occur. • Occasionally, you might want or need to clean up the sources before beginning from scratch. ’make clean’ will delete object files, ’make mrproper’ will delete everything except the sources, including your .config! be sure to save it elsewhere, not in the kernel source directory, as ’make mrproper’ will delete all files matching .config* • Neither ’make clean’ nor ’make mrproper’ are needed if this is the first time compiling the kernel from pristine sources, only ’make dep’. Operating Systems Lab - UT ECE Dept Fall 2005

  8. Cleaning Cleaning is done on three levels. • make clean Delete most generated files, Leave enough to build external modules • make mrproper Delete the current configuration, and all generated files • make distclean Remove editor backup files, patch leftover files and the like Operating Systems Lab - UT ECE Dept Fall 2005

  9. make bzImage • Not much to say here, really... ’make bzImage’ will build a compressed, ready to be installed kernel image. Alternatives include ’make vmlinux’, which will create a debuggable (but not runnable) kernel image. Operating Systems Lab - UT ECE Dept Fall 2005

  10. make modules ’make modules’ will built the various components which we chose to build as modules. Why would we want to build something as a module? • To save space in the kernel image (for embedded systems) • For easier debugging of drivers and kernel code • To support new peripherals without requiring a kernel reboot. Operating Systems Lab - UT ECE Dept Fall 2005

  11. make install, andmake modules_install • ’make modules_install’, which must be run as root, will create /lib/modules/‘uname -r‘ and copy the modules there. • The bzImage file, found at arch/i386/boot/bzImage, needs to be copied somewhere the boot loader will find it. The System.map file should be copied along with it, for debugging later, if necessary. • The boot loader (lilo, grub, else) should be updated to reflect the old kernel. Never replace a working kernel with a newly compiled one without verifying that it works first! Operating Systems Lab - UT ECE Dept Fall 2005

  12. Problem Solving So you compiled your first kernel, and it doesn’t work. Congratulations! you aren’t the first one, and certainly won’t be the last one. • Did you install the bzImage and modules properly? Did you update the boot loader? • If hardware that used to work no longer works, check the .config for appropriate support. • If you compiled your disk drivers as modules, you need to create an initrd (initial ram disk). Read the documentation for more information. Operating Systems Lab - UT ECE Dept Fall 2005

  13. Linux Source Layout Operating Systems Lab - UT ECE Dept Fall 2005

  14. Linux Code Layout • Linux/arch • Architecture dependent code. • Highly-optimized common utility routines such as memcpy • Linux/drivers • Largest amount of code • Device, bus, platform and general directories • Character and block devices , network, video • Buses – pci, agp, usb, pcmcia, scsi, etc • Linux/fs • Virtual file system (VFS) framework. • Actual file systems: • Disk format: ext2, ext3, fat, RAID, journaling, etc • But also in-memory file systems: RAM, Flash, ROM Operating Systems Lab - UT ECE Dept Fall 2005

  15. Linux Code Layout • Linux/include • Architecture-dependent include subdirectories. • Need to be included to compile your driver code: • gcc … -I/<kernel-source-tree>/include … • Kernel-only portions are guarded by #ifdefs #ifdef __KERNEL__/* kernel stuff */ #endif • Specific directories: asm, math-emu, net, pcmcia, scsi, video. Operating Systems Lab - UT ECE Dept Fall 2005

  16. Kernel Source Structure • mm • Architecture-independent memory management code • Architecture-dependent: arch/*/mm • ipc • Kernel inter-process communications • init • The initialization code for the kernel • Very good place to start looking at how the kernel works • modules • Holds built-in modules Operating Systems Lab - UT ECE Dept Fall 2005

  17. Kernel Source Structure • net • The kernel networking code • lib • The kernel’s library code • Architecture-dependent: arch/*/lib • Scripts • Awk and tk scripts for kernel configuration Operating Systems Lab - UT ECE Dept Fall 2005

  18. Kernel Debugging printk approach • printk is a printf like function • it prints the output in the text console • you can not see the output from X Operating Systems Lab - UT ECE Dept Fall 2005

  19. Kernel Debugging • To print the output to a file • printk (KERN_DEBUG “message”, vars) • Edit /etc/syslog.conf to add • kern.debug /dev/console • kern.debug /var/log/’filename’ • This option prints all debug level information into the specified file • In addition to printk, there are number of usefull printing functions like • sprintf Operating Systems Lab - UT ECE Dept Fall 2005

  20. Kernel Debugging • use ‘gdb’ • to use ‘gdb’, it is required to modify Makefile. • CFLAGS = -Wall -Wstrict-prototypes -02 -fomit-frame-pointer • => CFLAGS = -Wall -Wstrict-prototypes -02 -g • ‘gdb’ enables all data structures in the kernel to be just read, but no local variables. • ‘gdb’ can’t change values or call kernel functions Operating Systems Lab - UT ECE Dept Fall 2005

More Related