My notes on system boot process. Computer initialization is a process, not an event. In general, a computer system life cycle consists of:

  • Booting
  • Kernel initialization
  • Device initialization
  • Operation mode
  • Shut down or restart

Applying power

PC initialization starts when we turn on the system.
When all the input voltages from a power supply are valid, the supply generates a PowerGood (PG) logic signal.
When the motherboard timer chip receives the PG signal, the timer stops forcing a Reset signal to the CPU.
At this point the CPU starts processing.

Bootstrap

Bootstrap loader is the program that loads the kernel.
Bootstrap loader is an example of an absolute loader.
The very first operation performed by the CPU is to fetch an instruction from address FFFF:000h.
Since this address is almost at the end of the available ROM space, the instruction is always a jump command (JMP) followed by the actual BIOS ROM starting address.
By making all the CPUs start at the same point, the BIOS ROM can send program control anywhere in the particular ROM (and each ROM is usually different).
This initial search of address FFFF:000h and the subsequent redirection of the CPU is traditionally referred to as the bootstrap.
A boot manager lets to choose the first program to execute.

There are generally three things that a BIOS does in chronological order:

  • A POST (Power On Self Test): It checks whether or not the hardware connected to the system is working fine.

  • Hardware devices are then initialized.

  • It then searches for an operating system; boot sectors for different media are searched; if a valid sector is found then its executed.

Core Tests

Core test are the part of the power on self test sequence, which is the most important use of the system BIOS during initialization.
To ensure integrity a set of hardware-specific self-test routines check the major motherboard components and identifies the presence of any specialized BIOS chip in the system (driver controller BIOS, video BIOS, SCSI BIOS, and so on).
If an error is detected in the early phase of testing, a series of beeps (or beep codes) are produced. By knowing the BIOS manufacturer and the beep code we can determine the problem.
Next, the BIOS looks for the presence of a video ROM from memory location C000:000h through C780:00h. In just about all the systems, the search will reveal a video BIOS ROM on a video adapter board plugged into an available expansion slot.
If the test is successful the control is transferred to the video BIOS which loads and initializes the video adapter.
When no external video adapter BIOS is located, the system BIOS provides an initialization routine for the motherboard's video adapter and the cursor appears.
Now that the video system is ready , system BIOS will scan memory from C800:0000h through DF80:0000h in 2KB increments to the search for other ROMS that might be on the adapter card on the system. If found their contents are tested and run.

POST

BIOS then checks the memory location at 0000:0472h. This address contains a flag that determines whether the initialization is a cold start (power first applied) or a warm start (reset button or a CTRL+ALT+DEL key combination).
A value of 1234h indicates a warm starts in which the POST routine is skipped. If any other value is found at that location, a cold start is assumed, and the full POST routine will be executed.
The full POST routine checks many other high level functions on the motherboard, memory, keyboard, video adapter, floppy drive, math coprocessor, printer port, serial port, hard drive, and other sub-systems.
If the POST completes successfully, the system will respond with a single beep, else it displays an error message and the system initialization halts.

Finding the Operating System

The system now needs to load an operating system (let us consider DOS, since it is more simple). The first step is to have the BIOS search for a DOS VBS on the media. BIOS will load sector 1 (head 0 cylinder 0) from the disk's DOS VBS into the memory starting at 000:7C00h.
The BIOS loads the sector from the disk's master partition boot sector (called the master boot sector; MBS), into memory starting at 0000:7C00h, and the last two bytes of the partition are checked.
If the last two bytes of the master boot sector is not 55h and AAh, respectively, the boot sector is invalid and a "No boot device available" message is displayed, and the system initialization will halt.

The disk will search for and identify any extended partitions. Once its found the drive's original boot sector will search for a boot indicator byte marking a partition as active and bootable. If non or more than one is marked as bootable a disk error message will be displayed such as "Invalid partition table".

When an active partition is found in the master boot sector, the DOS VBS from the bootable partition is loaded into memory and tested. If the DOS VBS cannot be read the message "Error loading operating system" will be displayed. If signature bytes are missing it shows an error.
After identifying the signature bits, the DOS VBS (now in memory) is executed as if it were a program.

Loading the OS

If no problem is detected in the disk's DOS VBS, IO.SYS is loaded and executed. Next MSDOS.SYS executed.

Establishing the environment

If a CONFIG.SYS is present, it is opened and read by IO.SYS.
The device statements are processed in the order they appear.
A SHELL statement is handled next.
If no shell statement is present the COMMAND.COM processor is loaded.
It overwrites the initialization code leftover from IO.SYS.
Under windows COMMAND.COM is loaded only if an AUTOEXEC.BAT file is present to execute the AUTOEXEC.BAT statements.
When an AUTOEXEC.BAT file is present COMMAND.COM (which has now control of the system) will load and execute the batch file. After batch file processing is complete, the DOS Prompt will appear.
If no AUTOEXEC.BAT file is present in the root directory, COMMAND.COM will request the current date and time, and then show the dos prompt.
Now applications can be launched by using OS command. AUTOEXEC.BAT may also call a shell or start an application.

More on the Boot loader

A sector has a length of 512 bytes. It becomes a boot sector because of its location and the hex value 0xaa55 in the final two byte. The BIOS look this value when scanning a potential boot media. Generally the hard disk has its boot sector in its first sector, which is called master boot record (MBR).

There is a primary boot loader as well as a secondary boot loader.
Boot loaders may face peculiar constraints, especially in size, for instance, on the IBM PC, and compatible the first stage of the boot loaders must fit into the first 446 bytes of the MBR in order to leave room for the 64-byte partition table and two byte AA55h 'signature' which the BIOS requires for a proper boot loader.
In the second stage, boot loader load the operating system. Second stage loader include LILO( LInux LOader), GRUB (GRand Unified Bootloader), (these two are used on linux extensively); NTLDR (Windows); BSD Bootloader etc.