Boot_Grub

download Boot_Grub

of 31

Transcript of Boot_Grub

  • 7/31/2019 Boot_Grub

    1/31

    Booting

    booting (booting up) is a bootstrapping process that starts

    operating systems when the user turns on a computer system.

    Boot sequence: The initial set of operations that the computer

    performs when power is switched on .

    Bootloader: typically loads the main operating system for the

    computer.

  • 7/31/2019 Boot_Grub

    2/31

    Boot Sequence

    Power is turned ON (It takes some time until it generates reliable

    power after that it sends Power Good signal to processor) Processor always look to BIOS at the same place in the system

    BIOS ROM for the start of the BIOS boot program. This isnormally location FFFF0h, right at the end of the systemmemory.

    BIOS performs POST BIOS looks for vide card etc for their built in BIOS program and

    runs it to initialize devices

    BIOS displays its start up screen

    BIOS performs some tests for RAM count and to check what kind

    of hardware is in the system. BIOS will also check logicaldevices such as LPT & COM

    If the BIOS supports the Plug and Play standard, it will detectand configure Plug and Play devices at this time and display amessage on the screen for each one it finds.

    contd.

    http://www.pcguide.com/ref/mbsys/bios/bootSequence-c.htmlhttp://www.pcguide.com/ref/mbsys/bios/bootSequence-c.htmlhttp://www.pcguide.com/ref/mbsys/bios/bootSequence-c.htmlhttp://www.pcguide.com/ref/mbsys/bios/bootSequence-c.html
  • 7/31/2019 Boot_Grub

    3/31

    The BIOS will display a summary screen about your system'sconfiguration.

    The BIOS begins the search for a drive to boot from.

    If the first device that the system tries (floppy, hard disk, etc.) is notfound, the BIOS will then try the next device in the boot sequence, andcontinue until it finds a bootable device.

    If it finds what it is looking for, the BIOS looks for boot information tostart the operating system boot process. If it is searching a hard disk, itlooks for a master boot record at cylinder 0, head 0, sector 1 (the firstsector on the disk).

    The BIOS starts the process of booting the operating system, using theinformation in the boot sector.

    If no boot device at all can be found, the system will normally display

    an error message and then freeze up the system.This process is called a "cold boot" (since the machine was off, or cold,when it started). A "warm boot" is the same thing except it occurs whenthe machine is rebooted using {Ctrl}+{Alt}+{Delete} or similar. In thiscase the POST is skipped

    Rest of the process in O.S. dependent

    http://www.pcguide.com/ref/mbsys/bios/bootSummary-c.htmlhttp://www.pcguide.com/ref/mbsys/bios/bootSummary-c.htmlhttp://www.pcguide.com/ref/hdd/file/struct_MBR.htmhttp://www.pcguide.com/ref/mbsys/bios/bootSequence-c.htmlhttp://www.pcguide.com/ref/mbsys/bios/bootSequence-c.htmlhttp://www.pcguide.com/ref/hdd/file/struct_MBR.htmhttp://www.pcguide.com/ref/mbsys/bios/bootSummary-c.htmlhttp://www.pcguide.com/ref/mbsys/bios/bootSummary-c.html
  • 7/31/2019 Boot_Grub

    4/31

    Bootloader:

    CPU can only execute program code found in Read-OnlyMemory (ROM) and Random Access Memory (RAM).

    Modern operating systems and application program codeand data are stored on nonvolatile data storage devices,such as hard disk drives.

    When a computer is first powered on, it does not have anoperating system in ROM or RAM.

    The computer must initially execute a small program storedin ROM along with the bare minimum of data needed toaccess the nonvolatile devices from which the operatingsystem programs and data are loaded into RAM .

  • 7/31/2019 Boot_Grub

    5/31

    Bootloader:

    The small program that starts this sequence of loading into RAM,

    is known as a bootstrap loader, bootstrap or boot loader

    Boot loader program's only job is to load other data and programswhich are then executed from RAM .

    The small program is most often not itself an operating system, butonly a second-stage boot loader, such as GRUB, BOOTMGR,

    LILO or NTLDR.

  • 7/31/2019 Boot_Grub

    6/31

    Bootloader:

    It will then be able to load the operating system properly, and

    finally transfer execution to it.

    The Operating system will initialize itself, and may load devicedrivers and other programs that are needed for the normal operation

    of the OS.

    Many boot loaders (like GRUB, BOOTMGR, LILO, and NTLDR)can be configured to give the user multiple booting choices.

    These choices can include different operating systems (for dual ormulti-booting from different partitions or drives).

  • 7/31/2019 Boot_Grub

    7/31

    Salient features of GRUB LILO does not understand file systems whereas GRUB

    understands. The currently supported filesystem types are BSD

    FFS, DOS FAT16 and FAT32, Minix fs, Linux ext2fs, ReiserFS,JFS, XFSetc.

    GRUB supports both direct loading and chain loading, allowingyou to use almost any operating system, most popular filesystems, and almost any hard disk your BIOS recognize.

    GRUBs configuration file is read from the disk every time thesystem boots preventing you from having to write over the MBRevery time you change the boot options.

    GRUB provides a true command based pre-OS environment onx86 m/c to provide maximum flexiblity

    GRUB supports logical block addressing mode, needed toaccess many IDE and all SCSI hard disks.

    Support automatic decompression . Can decompress files whichwere compressed by gzip.

    Support n/w booting, logical block address mode, remoteterminals.

  • 7/31/2019 Boot_Grub

    8/31

    Anatomy of MBR (Master Boot Record)

  • 7/31/2019 Boot_Grub

    9/31

    Top view of Booting Linux

  • 7/31/2019 Boot_Grub

    10/31

    Booting sequence of linux

    The kernel when it is loaded, finds init in sbin and executes it.

    When init starts it becomes the parent or grand parent of all theprocesses that startup automatically on your linux system.

    Init reads an initialization configuration script for the environmentwhich sets the path, start swapping, checks the file system,

    setting the clock, initializing serial port and so on and so on. After deciding the default run level (run level 1 is single user

    mode, run level 2 is multi user run level and so on) for yoursystem init starts all of the background processes necessary forthe system to run by looking in the appropriate rc directory for

    that run level. After that it runs all kill scripts and then start scriptsso that all

    services and applications are started correctly

  • 7/31/2019 Boot_Grub

    11/31

    Booting XP using NTLDR

    NTLDR is located at the Boot Sector (The first sector of theactive partition). That is where NTLDR is located

    NTLDR will allow memory addressing, initiate the file system,read boot.ini and load the boot menu.

    NTLDR has to be in root of the active partition as doNTDETECT.COM, BOOT.INI, BOOTSECT.DOS (for multi OSbooting) and NTBOOTD.SYS (if u have SCSI adopter)

    Once XP is selected from the boot menu, NTLDR will runNTDETECT.COM, BOOT.INI and BOOTSECT.DOS to getproper OS selected and loaded

    The system starts in 16 bit real mode and then moves to 32-bitprotected mode.

    NTLDR will then load NTOSKRNL.EXE and HAL.DLL (effectivelythese 2 files are windows XP)

    NTLDR reads the registry, chooses a h/w profile and authorizesdevice drivers.

    At this point NTOSKRNL.EXE takes over. It starts

    WINLOGON.EXE that in turn starts LSASS.EXE.

  • 7/31/2019 Boot_Grub

    12/31

    A Modern Computer System

  • 7/31/2019 Boot_Grub

    13/31

    Computer-System Operation

    I/O devices and the CPU can execute concurrently

    Each device controller is in charge of a particular device

    type

    Each device controller has a local buffer

    CPU moves data from/to main memory to/from localbuffers

    I/O is from the device to local buffer of controller

    Device controller informs CPU that it has finished its

    operation by causing an interrupt

  • 7/31/2019 Boot_Grub

    14/31

    Traps and Interrupts

    Interrupts

    An interrupt is a signal sent to the CPU, either from

    Hardware or software.

    Hardware may trigger an interrupt at any time by sending a

    signal to CPU and S/W may trigger an interrupt by executing

    a special operations called System calls.

    An Interrupt Service routine is provided for dealing with the

    interrupt.

  • 7/31/2019 Boot_Grub

    15/31

    Common Functions of Interrupts

    Interrupt transfers control to the interrupt service routine

    generally, through the interrupt vector, which contains theaddresses of all the service routines

    Interrupt architecture must save the address of the interrupted

    instruction

    Incoming interrupts are disabled while another interrupt is

    being processed to prevent a lost interrupt

    An operating system is interruptdriven

  • 7/31/2019 Boot_Grub

    16/31

    Traps and Interrupts

    Interrupts

    When the CPU is interrupted it stops what it is doing andimmediately transfers execution to fixed location.

    The fixed location usually contains the starting address

    where the service routine for interrupt is located.

    The interrupt service routine executes; on completion, CPU

    resumes the interrupted computation.

  • 7/31/2019 Boot_Grub

    17/31

    Traps and Interrupts

    Traps

    Abnormal Condition detected by the CPU that usually is

    indicative of an error. For example

    Dividing by zero

    Accessing memory that does not exist or for which

    the program has not access to.

    Executing an instruction with an undefined opcode or

    trying to access a non existent I/O device.

  • 7/31/2019 Boot_Grub

    18/31

    Direct Memory Access Controller

    Used for high-speed I/O devices able to transmit

    information at close to memory speeds

    Device controller transfers blocks of data from bufferstorage directly to main memory without CPUintervention

    While the DMA controller is busy in data transfer the CPUis busy to perform other task.

    Only one interrupt is generated per block, rather than the

    one interrupt per byte

  • 7/31/2019 Boot_Grub

    19/31

    Storage Structure

    Main memoryonly large storage media that the CPU can

    access directly

    Secondary storage extension of main memory that

    provides large nonvolatile storage capacity e.g. magnetic

    disks.

    Magnetic disks rigid metal or glass platters covered with

    magnetic recording material

    Disk surface is logically divided into tracks, which are

    subdivided into sectors

    The disk controller determines the logical interaction

    between the device and the computer

  • 7/31/2019 Boot_Grub

    20/31

    Hardware Protection

    Dual-Mode Operation

    I/O Protection

    Memory Protection

    CPU Protection

  • 7/31/2019 Boot_Grub

    21/31

    Dual-Mode Operation

    Sharing system resources requires operating system to ensure

    that an incorrect program or poorly behaving human cannot

    cause other programs to execute incorrectly

    OS must provide hardware support to differentiate betweenat least two modes of operations

    1.User modeexecution done on behalf of a user

    2. Monitor mode (also kernel mode or system mode)

    execution done on behalf of operating system

  • 7/31/2019 Boot_Grub

    22/31

    Dual-Mode Operation (Cont.)

    Mode bitadded to computer hardware to indicate the current

    mode: monitor (0) or user (1)

    When an interrupt or fault occurs hardware switches to

    monitor mode

    monitor user

    Interrupt/fault

    set user mode

  • 7/31/2019 Boot_Grub

    23/31

    I/O Protection

    To prevent users from performing illegal I/O, all I/O

    instructions are defined to be privileged instructions.

    Thus users can not issue I/O instruction directly, they must

    do it through the OS.

    Must ensure that a user program could never gain control of

    the computer in monitor mode (I.e., a user program that, as

    part of its execution, stores a new address in the interrupt

    vector)

  • 7/31/2019 Boot_Grub

    24/31

    Use of A System Call to Perform I/O

  • 7/31/2019 Boot_Grub

    25/31

    Memory Protection

    Must provide memory protection at least for the interrupt

    vector and the interrupt service routines

    In order to have memory protection, at a minimum add two

    registers that determine the range of legal addresses a

    program may access:

    Base register holds the smallest legal physical

    memory address

    Limit register

    contains the size of the range

    Memory outside the defined range is protected

  • 7/31/2019 Boot_Grub

    26/31

    Use of A Base and Limit Register

  • 7/31/2019 Boot_Grub

    27/31

    Hardware Address Protection

  • 7/31/2019 Boot_Grub

    28/31

    Hardware Protection

    When executing in monitor mode, the operating

    system has unrestricted access to both monitor andusers memory

    The load instructions for the base and limit registers

    are privileged instructions

  • 7/31/2019 Boot_Grub

    29/31

    CPU Protection

    Timer interrupts computer after specified period to ensure

    operating system maintains control

    Timer is decremented every clock tick

    When timer reaches the value 0, an interrupt occurs

    Timer commonly used to implement time sharing

    Timer also used to compute the current time

  • 7/31/2019 Boot_Grub

    30/31

    Some GRUB commands

    Geometry

    Root

    Boot

    Kernel

    Initrd

    Rootnoverify

    Chainloader

    Find

    Setup

    lock

  • 7/31/2019 Boot_Grub

    31/31

    Naming convention

    (hd0,1) Here, `hd' means it is a hard disk drive. The first integer

    `0' indicates the drive number, that is, the first hard disk, whilethe second integer, `1', indicates the partition number .

    fd (floo[pydisk) cd (cd rom) fd0-> first floppy disk

    (hd0,0)/vmlinuzThis specifies the file named `vmlinuz', found onthe first partition of the first hard disk