Linux Booting

Document Sample
Linux Booting Powered By Docstoc
					            Linux Booting
• The booting procedure.
• Logging in to the machine.
• Control flow in the machine.
            Linux Booting
• The booting procedure.
• Logging in to the machine.
• Control flow in the machine.
      The booting procedure.
• Every computer has sequence of
  instructions that are executed when
  computer is powered up.
  – determined by the hardware designers
• Every OS has a sequence of instructions
  that it executes prior to normal operation.
      The booting procedure.
• i386 machines incorporate the Basic
  Input/Output System (BIOS)
  – stored at a prespecified location in system ROM.
  – when computer started, begins executing BIOS code
  – BIOS code executes the Power-On Self Test (POST)
  – POST performs various diagnostic tests to check
    memory and devices for their presence and correct
    operation.
  – when POST is completed, machine ready to load and
    start OS.
      The booting procedure.
• The boot sector.
  – OS loaded from the system’s boot disk.
  – i386 treats A: as default disk if it contains a diskette.
  – Otherwise depends on how you’ve set the BIOS.
            The booting procedure.
• The boot disk
  – must contain a boot record at the disk’s first logical sector.
  – The boot record fits onto a single 512-byte disk sector (called the
    boot sector):

  0x000      0x002          <a jump instr to 0x0XX>
  0x003      ….             Disk parameters (used by BIOS) program
  0x0XX      0x1fd          Bootstrap program
  0x1fe      0x1ff          0xaa55 (the magic number for BIOS)
     The booting procedure.
• After POST BIOS copies the boot record
  from disk into memory
• Bios then reads boot record parameters:
  – Boot record contains parameters that describe
    disk’s physical layout
  – Parameters are stored in well-know locations in
    boot record
  – Parameters include number of tracks and
    number of sectors per track.
       The booting procedure.
• After parameters read BIOS branches to the first
  location in program
   – then immediately branches to location 0x0XX
   – the value XX for Linux is 3e
   – the value XX for MS-DOS is 1e
• The small program at address 0x0XX loads a more
  sophisticated loader from other sectors on the disk
• The sophisticated loader loads the OS
      The booting procedure.
• Disk partitioning
  – can have up to 4 primary partitions on one
    physical disk
     • each primary disk can have logical sub-partitions
  – each partition treated like a physical disk below
    the abstract machine that accesses the physical
    disk (eg, BIOS in MS-DOS)
  – if partition is bootable then its logical sector
    number 0 will be a boot sector.
       The booting procedure.
• Disk partitioning
   – when hardware is powered up goes to head 0, track 0,
     sector 1 and begins executing code.
   – an unpartitioned disk has a jump instruction at head 0,
     track 0, sector 1 which jumps to location 0x0XX and
     starts the execution of the boot program
   – in a partitioned disk, physical head 0, track 0, sector 1
     (first logical disk sector) describes how hard disk is
     partitioned into logical disks.
    The booting procedure.
– A partitioned disk has a 446-byte bootstrap program
  starting at first byte in the sector.
– next is a 65-byte partition table for the disk
– Table contains the 4 partition entries, each of which
  describes the portion of the physical disk that is used
  for its partition (starting sector of the partition, ending
  sector, number of sectors, etc.)
– last 2 bytes of partition sector contain a magic number,
  0xaa55 to identify the partition sector.
            Partitioned Disk
                                      head 0 track 0 sector 1




    446-byte bootstrap program



                                           4 partition entries, each
                                           describes the portion of
    65-byte partition table                the physical disk
                                           used for its partition
2 bytes: magic number, 0xaa55 for MS-DOS
      The booting procedure.
• Partitioning with different OS’s
  – i386 can be booted with Linux from boot
    floppy.
  – contains a Linux boot program.
  – Can have different OS in different partitions
  – Windows handles by designating one partition
    as an active partition. System always boots
    from this partition.
      The booting procedure.
• Partitioning with different OS’s
  – can have a special program, Linux Loader
    (LILO) in system boot record.
  – program allows user to choose at boot time
    which partition is to be the active partition.
  – LILO is loaded in the boot record so that BIOS
    runs it after the POST.
            Starting the Kernel
• machine is powered up
    – hardware fetch-decode-execute cycle begins.
    – called the “hardware process”
    – this is not a Linux process; Linux has not yet started.
•   POST is completed
•   boot record read
•   loader places OS into primary memory
•   the booting procedure begins to run kernel code to
    initialize the computer’s hardware.
             Starting the Kernel
• Computer then starts kernel by setting supervisor
  mode and branching to main entry point in kernel.
• main entry point is not a C program.
• kernel initializes
   –   trap table
   –   interrupt handler
   –   scheduler
   –   clock
   –   modules
   –   etc.
           Starting the Kernel
• near end of kernel initialization start process manager
   – now ready for normal process abstraction
   – PM starts the initial process
   – initial process is first entry in kernel’s process descriptor
     table
   – referred to as process 0, task[0], or INIT_TASK
   – initial process then creates first useful Linux process to run:
     the init program
   – after init runs it executes an idle loop
   – only other duties of init is to use idle CPU time….runs
     when no other process wants CPU.
           Starting the Kernel
• init process initializes system
  –   starts daemons
  –   starts file manager
  –   creates system console
  –   runs other init programs from /etc, /bin and/or
      /sbin, and runs /etc/rc
       Logging in to the machine
• during initialization kernel creates one process on
  each communication port that can be used to
  support user logins
   – uses the getty program
• getty
   –   waits for a user to begin using the port
   –   then runs login program
   –   login expects user id on first line, passwd on next
   –   login verifies user by looking in /etc/passwd file
      Logging in to the machine
• getty
  – /etc/passwd file. Each entry separated by colon
  jbarr:eNcrYpt123:3348:35:John Barr:/home/barr:/bin/bash
  – jbarr              account name
  –   eNcrYpt123       encrypted password
  –   3348 and 35      user ID and group ID
  –   John Barr                 real name
  –   /home/barr       user’s home directory
  –   /bin/bash        path to shell command preferred by user
     Logging in to the machine
• getty
  – once login verifies it changes current directory to user’s
    home directory
  – and executes the specified shell program
  – now user interacts directly with login process via shell.
  – user who logs in is using a process that was created
    when the machine was started
  – starting shell is complicated; data and stack segments
    created etc.
  – data includes user’s environmental variables (eg, PATH)
  – when user logs off, return from shell call to the login process
 Logging in to the machine
                    26
Serial Port A                login
                                          1
Serial Port B                login
                                         getty

Serial Port C                login

                5        4           3


Serial Port Z                login
                                     /etc/passwd
                /bin/bash
                           Control Flow
 hardware process starts

               Idle Proc     kernel   ISRs   Proc i   Proc j




program



hardware
process



context
switch