13.  Advanced Topics - Linux Boot Process

This section may not be interesting for 'average Joe home PC user' but will be more directed towards someone with computer science background.

The chain of events at boot are: CPU-> VGA-> Power-On-Self-Test-> SCSI-> Boot Manager-> Lilo boot loader-> kernel-> init-> bash. The firmware and software programs output various messages as the computer and Linux come to life.

A guided tour of a Linux Boot process:

  1. The Motherboard BIOS Triggers the Video Display Card BIOS Initialization

  2. Motherboard BIOS Initializes Itself

  3. SCSI Controller BIOS Initializes

  4. Hardware Summary: The motherboard BIOS then displays the following summary of its hardware inventory. And runs its Virus checking code that looks for changed boot sectors.

  5. BootManager Menu : The Master Boot Record (MBR) on the first hard disk is read, by DOS tradition, into address 0x00007c00, and the processor starts executing instructions there. This MBR boot code loads the first sector of code on the active DOS partition.

  6. Lilo is started: If the Linux selection is chosen and if Linux has been installed with Lilo, Lilo is loaded into address 0x00007c00. Lilo prints LILO with its progress revealed by individually printing the letters. The first "L" is printed after Lilo moves itself to a better location at 0x0009A000. The "I" is printed just before it starts its secondary boot loader code. Lilo's secondary boot loader prints the next "L", loads descriptors pointing to parts of the kernel, and then prints the final "O". The descriptors are placed at 0x0009d200. The boot message and a prompt line, if specified, are printed. The pressing "Tab" at the prompt, allows the user to specify a system and to provide command-line specifications to the Linux Kernel, its drivers, and the "init" program. Also, environment variables may be defined at this point.

    The following line is from /boot/message:
    >
    >
    >
     Press  to list available boot image labels.
    The following line is the prompt from /sbin/lilo:
    boot:
    Note: If Lilo is not used, then the boot code built into the head 
          of the Linux kernel, linux/arch/i386/boot/bootsect.S 
    	  prints "Loading" and continues.
    Lilo displays the following as it loads the kernel code. It gets the 
    text "Linux-2.2.12" from the "label=..." specification in lilo.conf.
    Loading linux-2.2.12..........
    		  	

  7. The kernel code in /linux/arch/i386/boot/setup.S arranges the transition from the processor running in real mode (DOS mode) to protected mode (full 32-bit mode). Blocks of code named Trampoline.S and Trampoline32.S help with the transition. Small kernel images (zImage) are decompressed and loaded at 0x00010000. Large kernel images (bzImage) are loaded instead at 0x00100000. This code sets up the registers, decompresses the compressed kernel (which has linux/arch/i386/head.S at its start), printing the following 2 lines from linux/arch/i386/boot/compressed/misc.c Uncompressing Linux... Ok. Booting the kernel. The i386-specific setup.S code has now completed its job and it jumps to 0x00010000 (or 0x00100000) to start the generic Linux kernel code.

    • Processor, Console, and Memory Initialization : This runs linux/arch/i386/head.S which in turn jumps to start_kernel(void) in linux/init/main.c where the interrupts are redefined. linux/kernel/module.c then loads the drivers for the console and pci bus. From this point on the kernel messages are also saved in memory and available using /bin/dmesg. They are then usually transferred to /var/log/message for a permanent record.

    • PCI Bus Initialization : mpci_init() in linux/init/main.c causes the following lines from linux/arch/i386/kernel/bios32.c to be printed:

    • Network Initialization: socket_init() in linux/init/main.c causes the following network initializations:

      linux/net/socket.c prints:
      Linux NET4.0 for Linux 2.2
      Based upon Swansea University Computer Society NET3.039
      linux/net/unix/af_unix.c prints:
      NET4: Unix domain sockets 1.0 for Linux NET4.0.
      linux/net/ipv4/af_inet.c prints:
      NET4: Linux TCP/IP 1.0 for NET4.0
      IP Protocols: ICMP, UDP, TCP
      linux/net/ipv4/ip_gre.c prints:
      GRE over IPv4 tunneling driver
      linux/net/core/dev.c prints:
      early initialization of device gre0 is deferred
      linux/net/core/rtnetlink.c prints:
      Initializing RT netlink socket
      					

    • The Kernel Idle Thread (Process 0) is Started : At this point a kernel thread is started running init() which is one of the routines defined in linux/init/main.c. This init() must not be confused with the program /sbin/init that will be run after the Linux kernel is up and running. mkswapd_setup() in linux/init/main.c causes the following line from linux/mm/vmscan.c to be printed: Starting kswapd v 1.5

    • Device Driver Initialization : The kernel routine linux/arch/i386/kernel/setup.c then initializes devices and file systems (built into the kernel??). It produces the following lines and then forks to run /sbin/init:

      • Generic Parallel Port Initialization : The parallel port initialization routine linux/drivers/misc/parport_pc.c prints the following:

      • Character Device Initializations : The following 3 lines are from linux/drivers/char/serial.c:

      • Block Device Initializations : linux/drivers/block/rd.c prints: RAM disk driver initialized: 16 RAM disks of 8192K size linux/drivers/block/loop.c prints: loop: registered device at major 7 linux/drivers/block/floppy.c prints: Floppy drive(s): fd0 is 1.44M, fd1 is 1.44M FDC 0 is a post-1991 82077

      • SCSI Bus Initialization: The following lines are from aic7xxx.c, scsi.c, sg.c, sd.c or sr.c in the subdirectory linux/drivers/scsi:

    • Initialization of Kernel Support for Point-to-Point Protocol : The following initialization is done by linux/drivers/net/ppp.c.

    • Examination of Fixed Disk Arrangement : The following lines are from linux/drivers/block/genhd.c:

  8. Init Program (Process 1) Startup : The program /sbin/init is started by the "idle" process (Process 0) code in linux/init/main.c and becomes process 1. /sbin/init then completes the initialization by running scripts and forking additional processes as specified in /etc/inittab. It starts by printing: INIT: version 2.76 booting and reads /etc/inittab.

  9. The Bash Shell is Started : The bash shell, /bin/bash is then started up. Bash initialization begins by executing script in /etc/profile which set the system-wide environment variables:

13.1.  References for Boot Process

Refer to following resources :