linux boot loader

Upload: ramakrishna-mannem

Post on 29-May-2018

239 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Linux Boot Loader

    1/35

    LINUX BOOTLOADER

    Presented By

    Abhiram AnnangiUSC

  • 8/8/2019 Linux Boot Loader

    2/35

    TOPICS AT A GLANCE

    Brief introduction to Linux kernel

    Linux executable format (ELF) Linux boot process

    Linux bootloader (GRUB) Linux kernel compile procedure

  • 8/8/2019 Linux Boot Loader

    3/35

    LINUX OS (SYSTEM PROGRAMMERS VIEW)

    Any Operating System is implemented as two modulesat a macro level.

    Module 1- User interface functionality (Shell) Module 2- Request Processing functionality (kernel)

    Shell is responsible for interaction with the user, which

    collects user requests and forward it to the kernel toprocess.

    Shell scripting/programming is customizing the user

    interface of an OS and nothing to do with the kernel. Kernel itself is a module, which has different sub

    modules

  • 8/8/2019 Linux Boot Loader

    4/35

    LINUX KERNEL (OVERVIEW)

    Process management Access IPC

    LOADER

    Memory management

    KERNEL

    HARDWARE PERIPHERALS

    ARCHITECTURESPECIFIC (AS)

    NETWORK SERVICESI/O File System andDevice Drivers

  • 8/8/2019 Linux Boot Loader

    5/35

    CONTD..

    Architecture Specific (AS) , Kernel and Loader are thekey units which together are called the Engine of an OS

    Architecture Specific AS layer contains the CPU initialization , Board

    initialization code.

    In Embedded Systems terminology, it is referred to asthe Board Support Package (BSP)

    AS of Linux is very much specific to the hardware

    architecture. AS has all the startup drivers which initialize the MMU

    and on board devices.

  • 8/8/2019 Linux Boot Loader

    6/35

    KERNEL

    Within Kernel, there is a layer called In-Kernel which is thecore of the kernel.

    In-Kernel is responsible for the boot process. When system is initialized and ready to use, Loader starts

    up. Loader is started by the Linux Kernel.

    The rest of the boxes in the figure are just used to provideServices, called Service Layers.

    For a general purpose OS, all the services needed, where asfor a RT-OS, depending on the requirement the services are

    provided. Hence because of this modular nature of the Linux kernel,

    the size of Linux kernel varies a lot making it highly scalable.

  • 8/8/2019 Linux Boot Loader

    7/35

    KERNEL CONTD..

    Loader contains routines to receive requests from the shell andprocess them by forwarding to the respective service layers.

    Kernel processes include :- Process Management

    Access

    IPC

    Memory Management

    N/W services

    I/O file system

    Device drivers (High level drivers, as Initial drivers initialized by AS) File system

  • 8/8/2019 Linux Boot Loader

    8/35

    KERNEL CONTD..

    At start up time, memory is divided into two parts, userspace and kernel space.

    Shell and applications are resided on the user space. Shell and applications cannot access the K space where

    as kernel space can access the whole of memory,

    including the user space. Windows being a user-friendly OS puts the shell as

    one of the kernel service.

    But the disadvantage is that both the shell and kernelcannot be upgraded/customized independently.

    It also saves kernel from many application level bugs,making the kernel more safe.

  • 8/8/2019 Linux Boot Loader

    9/35

    KERNEL INTEGRATION

    Kernel is an aggregation of many source codes (Loader, Services etc..)which have to be compiled and built to convert to an executable imagein order to use it. This is called Kernel Integration.

    There are two types of Kernel Integration

    Monolithic integration

    Micro integration

    In Monolithic integration, the entire kernel including the services arecompiled and built into the memory.

    In Micro integration, only the kernel, AS and the loader are compiled andbuilt into the memory where as the services are installed only whenrequired.

    Hence Monolithic kernels occupy more memory but are much faster asthey avoid the compiling and loading time where as micro kernelsoccupy less memory but have high response time.

    What does Linux kernel support??

  • 8/8/2019 Linux Boot Loader

    10/35

    MODULAR INTEGRATION

    Linux defines Modular integration. It gathers the

    components which are needed frequently and makesthem Static and keeps rest as modules.

    In Linux the static ones are the Loader, BSP and some

    services like Process and memory management, Rest of the dynamic modules/processes can also be

    made Static depending on the environment. This

    flexibility gives Linux to be used as embedded and

    RTOS.

  • 8/8/2019 Linux Boot Loader

    11/35

    EXECUTABLES IN LINUX

    Any executable file when formed consists of two parts: Functionality

    and Runtime.

    When an executable gets loaded into memory (process addressspace), it requires key resource allocation to support the execution of

    functionality. Runtime code is responsible to acquire such resources.

    Runtime code involves making system calls to acquire resources, assystem calls are OS specific, this makes Runtime and hence the

    executable to be OS specific.

    Runtime code in Linux is called GNU runtime, which consists of three

    functions: Init, Start and Fini.

    Any application starts with an Init which does the required resource

    allocation. Functionality of an executable is triggered with Start. Fini

    is called after the execution of application for freeing up resources.

  • 8/8/2019 Linux Boot Loader

    12/35

    CONTD..

    Format is a standard to organize data with in a file. Binary file format specifies how binary code is to be organized and

    saved on disk. Assembler and linker should make use of this fileformat to create an executable.

    Binary file format is platform specific. Linux follows ELF 32 fileformat.

    The combination of Binary file format and Runtime called ApplicationBinary Interface (ABI) makes an executable platform dependent. Hence Linux ABI is a combination of GNU runtime plus ELF 32.

    There are 3 types of ELF files:

    shared objects (loadables) - .so Executables (runnables)

    Relocatables (linkables) - .o

  • 8/8/2019 Linux Boot Loader

    13/35

  • 8/8/2019 Linux Boot Loader

    14/35

    LINUX BOOT PROCESS (OVERVIEW)

    System boot up

    BIOS/Boot monitor

    Stage 1 boot loader

    MBR

    Stage 2 boot loader LILO/GRUB

    Kernel - Linux

    Init user space

    Gettys trigger

    Power

    up/reset

    Linux

    LILO/GRUB

    MBR

    BIOS/Bootmonitor

    operation

    User-space

  • 8/8/2019 Linux Boot Loader

    15/35

    SYSTEM BOOT UP

    There is a slight difference in the start up between PCand embedded platform.

    Embedded platform Embedded platforms have a bootstrap environment

    used when system is powered on or reset.

    Embedded platforms also have something called BootMonitor. It is a small interactive computer programwhich supports an interaction for the user to select a listof Oss, do system test and also cover abilities of firstand second level boot loaders.

    This boot monitor loads the Linux (strip down) kernel toflash and execute it.

  • 8/8/2019 Linux Boot Loader

    16/35

    SYSTEM BOOT UP - PC

    BIOS begins at address 0xFFFF0 and performs POST (Poweron Self Test) which includes the following

    Initialization of CPU ( checking CPU type, speed etc.) andprobing the CPU to real mode.

    Probe the memory. Allocate real mode address space i.earchitecture specific segments. No paging and virtualmemory.

    Initialize basic I/O ( standard I/O,O/P, IDE controllers, harddisk, graphic cards)

    Jump to sector 0 of configured boot device. Commonly, Linux is booted from a hard disk, where the

    Master Boot Record (MBR) contains the primary boot loader.

  • 8/8/2019 Linux Boot Loader

    17/35

    MBR

    446

    bytes

    64

    bytes

    2

    bytes

  • 8/8/2019 Linux Boot Loader

    18/35

    MBR

    The primary boot loader that resides in the MBR is a 512-byte image containing both program code and a small

    partition table The first 446 bytes are the primary boot loader, which

    contains both executable code and error message text.

    The next sixty-four bytes are the partition table, whichcontains a record for each of four partitions (sixteen byteseach).

    The job of the primary boot loader is to find and load the

    secondary boot loader (GRUB). It does this by looking through the partition table for an active partition.

    When it finds an active partition, it scans the remainingpartitions in the table to ensure that they're all inactive.

  • 8/8/2019 Linux Boot Loader

    19/35

    GRUB ( GRAND UNIFIED BOOTLOADER)

    When MBR calls GRUB, it reads the target of the bzimage from

    /boot/grub, pulls it from there and loads into memory.

    Bzimage is a compressed kernel image. Bzimage is a

    combination of vmlinuz and bootstrap code.

    BZIMAGEBOOTSTRAP

    VMLINUZ

  • 8/8/2019 Linux Boot Loader

    20/35

    CONTD..

    When kernel image (bzimage) is loaded, first the bootstrapcode is loaded.

    Bootstrap performs the following functions Puts the CPU to protected mode

    Sets up page tables

    Uncompresses Vmlinuz Calls start_kernel function

    With the call to start_kernel, a long list of initializationfunctions are called to set up interrupts, perform furthermemory configuration.

    Vmlinuz starts executing. This is the process 0, also calledSwapper.

  • 8/8/2019 Linux Boot Loader

    21/35

    WHAT IS VMLINUZ

    Vmlinuz is the name of the Linux kernelexecutable.

    It is a compressed kernel image which is in thebootable form which means it has the capability toload OS into the memory.

    Vmlinux on the other hand is the non-compressedversion of Vmlinuz, a non bootable form. It is anintermediate step to produce Vmlinuz.

    Vmlinuz is located in/boot directory which is thedirectory required that needs files needed to beginbooting the system.

  • 8/8/2019 Linux Boot Loader

    22/35

    SWAPPER

    Swapper does the following

    Initializes CPU and probes BOGOMIPS Initializes the onboard controllers, timers, and the

    start up drivers (called BSP drivers in embedded

    systems lexicon) Initialize interrupt descriptor tables

    Initialize the file system

    Swapper finally starts a kernel thread called Init,seen in/bin/init.

  • 8/8/2019 Linux Boot Loader

    23/35

    INIT

    Init runs as a daemon with PID as 1.

    Init then runs the Inittab file present in/etc/init.d Inittab file describes which process should be started

    at boot up and during the normal operation.

    Finally, the idle task is started and the scheduler can

    now take control (after the call to cpu_idle). With

    interrupts enabled, the pre-emptive scheduler

    periodically takes control to provide multitasking.

  • 8/8/2019 Linux Boot Loader

    24/35

    GETTYS

    Init then runs the mingetty application ( the

    one which shows the login prompt). Now mingetty validates by running a task called

    passwd present in/etc/passwd. If it fails, it

    then respawns the login prompt. If it validates,it execs the shell.

    All the steps of Linux boot process can be seenusing the command dmesg|more, rightimmediately after boot up.

  • 8/8/2019 Linux Boot Loader

    25/35

    STEPS TO COMPILE/RECOMPILE KERNEL Configuring the kernel

    Build dependencies Build the kernel

    Build the modules Store it in the boot folder

    Grub configuration

  • 8/8/2019 Linux Boot Loader

    26/35

    CONFIGURING THE KERNEL (2.6.X VERSIONS)

    On the 2.6.x kernels there are three main frontend programs: config,menuconfig, andxconfig.

    config is the least user-friendly option as it merely presents a seriesof questions that must be answered sequentially. menuconfig is an ncurses based frontend. The system must have the

    ncurses-devel libraries installed in order to use this utility.

    Y for static and include it during the kernel compile, N for notincluding in the kernel and M for making it as module.

    In the kernel source tree, use either of these, preferrably [2] and [3]

    1) make config

    2) make menuconfig3) make xconfig

    Make mproper should be done on the source tree beforeperforming kernel recompile.

  • 8/8/2019 Linux Boot Loader

    27/35

    MENUCONFIG

  • 8/8/2019 Linux Boot Loader

    28/35

    XCONFIG

  • 8/8/2019 Linux Boot Loader

    29/35

    BUILD DEPENDENCIES

    The next step is to create the necessary includefiles and generate dependency information. This

    step is only required for the 2.4.x kernel tree. make dep (only for 2.4.x kernel versions)

    Lots of messages will scroll by. Depending on thespeed of your machine and on what options youchose, this may take several minutes to complete.

    Once the dependency information is created wecan clean up some miscellaneous object files. Thisstep is required for all versions of the kernel.

    make clean (for all versions)

  • 8/8/2019 Linux Boot Loader

    30/35

    BUILD THE KERNEL

    (finally) ready to start the actual kernel build. At

    the prompt type: make bzimage Some computers do not work with make

    bzimage either due to some hardware

    incompatibilities or due to older versions ofbootloaders or due to smaller kernel images.Use make zimage or make zdisk

    If everything went correctly then the new kernelshould exist in ./arch/$ARCH/boot.

  • 8/8/2019 Linux Boot Loader

    31/35

    BUILD THE MODULES

    There is one more step needed for the build process i.e tocreate all the loadable modules if we have them configured.

    make modules Once the modules are built they can be installed. If we were

    building as a non-privileged user you will now need to switchto root to complete this next step:

    $ su password:

    $ make modules_install The freshly baked modules will be copied into

    /lib/modules/KERNEL_VERSION.

  • 8/8/2019 Linux Boot Loader

    32/35

    CHANGING LOCATION

    Once your kernel is created, we can prepare it foruse. From the ./linux directory, copy the kernel andSystem.map file to /boot. In the followingexamples change KERNEL_VERSION to the versionof the new kernel.

    $ cp arch/i386/boot/bzImage /boot/bzImage-KERNEL_VERSION $ cp System.map /boot/System.map-KERNEL_VERSION The next step is to configure our bootloader.

  • 8/8/2019 Linux Boot Loader

    33/35

    CONFIGURING THE BOOTLOADER

    This forms the final step in the Linux compile procedure.The bootloader is the first program that runs when a

    computer is booted. Once we have copied the bzImage and System.map to

    /boot, edit the grub configuration file located in/boot/grub/menu.lst. On some distributions/etc/grub.conf is a symbolic link to this file.

    # Note that we do not have to rerun grub after makingchanges to this file

    title Test Kernel (2.6.0)root (hd0,1) kernel /boot/bzImage-2.6.0 roroot=LABEL=/ initrd /boot/initrd-2.6.0.img

  • 8/8/2019 Linux Boot Loader

    34/35

    REFERENCES

    Links:

    1. http://www.ibm.com/developerworks/linux/library/l-

    linuxboot/2. http://www.linfo.org/vmlinuz.html

    3. http://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.html

    4. http://www.digitalhermit.com/linux/Kernel-Build-HOWTO.html#BUILDING

    Books:

    1. Understanding the Linux Kernel, by Daniel. P. Bovet andMarco Cesati, OReilly third edition.

    2. Running Linux by Matt Wesh, OReilly fourth edition.

    http://www.ibm.com/developerworks/linux/library/l-linuxboot/http://www.ibm.com/developerworks/linux/library/l-linuxboot/http://www.linfo.org/vmlinuz.htmlhttp://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.htmlhttp://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.htmlhttp://www.digitalhermit.com/linux/Kernel-Build-HOWTO.htmlhttp://www.digitalhermit.com/linux/Kernel-Build-HOWTO.htmlhttp://www.digitalhermit.com/linux/Kernel-Build-HOWTO.htmlhttp://www.digitalhermit.com/linux/Kernel-Build-HOWTO.htmlhttp://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.htmlhttp://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.htmlhttp://www.linfo.org/vmlinuz.htmlhttp://www.ibm.com/developerworks/linux/library/l-linuxboot/http://www.ibm.com/developerworks/linux/library/l-linuxboot/
  • 8/8/2019 Linux Boot Loader

    35/35

    THANK YOU