How does an x86 machine boot?

From switching on the system to the stage where control is transferred to the kernel's main() routine.

  1. Switch on.

  2. To perform BIOS’ functions it needs RAM.

  3. For that it must identify RAM.

  4. Instruction Pointer Register is hardcoded to the value 0xFFFFFFF0.

  5. Execution begins at the physical address 0xFFFFFFF0.

  6. 0xFFFFFFF0 is mapped to a certain part of the BIOS.

  7. BIOS copies itself to RAM for faster access. (Read: Shadowing)

  8. The address in 0xFFFFFFF0 will contain just a JUMP instruction to the location where BIOS has copied itself to the memory.

  9. BIOS code starts execution.

  10. BIOS searches for a bootable device.

  11. Bootable device - The BIOS transfers 512 bytes of data from each device that exists, into physical memory starting at address 0x7c00. If the last two bytes transferred are 0x55, and then 0xAA, then the BIOS considers this to be a valid boot sector, and starts running the code that now begins at 0x7c00.

  12. BIOS copies the contents of the first sector into RAM starting from the first address 0x7c00.

  13. The code in this address is executed. (Read: Bootloader)

  14. Bootloader then loads the kernel at the physical address 0x100000.

Linux Booting Process

Linux boot process is divided into 6 high level stages :

  1. BIOS - Basic Input/Output system executes MBR

  2. MBR - Master Boot Record executes GRUB

  3. GRUB - Grand Unified Bootloader executes Kernel

  4. Kernel - Kernel execute /sbin/init

  5. Init - Init executes runlevel programs

  6. Runlevel - Runlevel programs are executed from /etc/rc.d/rc*.d/

BIOS Stage - BIOS locates & executes the bootloader (grub). It searches for, loads and runs the bootloader program stored in MBR (Master Boot Record). The boot loader is loaded into the memory & given control of computer.

MBR Stage - MBR loads & runs Grub boot loader. MBR is present in first sector of bootable drive. /dev/sda or /dev/hda. MBR is 512 bytes in size & consists of 3 components.

GRUB Stage - It contains information about the OS image that will be loaded & executed. In case, someone has multiple OS installations the GRUB lists out all of them and we select which OS to load. GRUB config file can be found in /boot/grub/grub.conf

Kernel Stage - Of course, the heart of OS. Kernel mounts the root file system defined in the grub.conf file. Then it runs /sbin/init program. This is the first program ran, to confirm just check its process id - it should be 1.

There are 7 run levels - 0 (halt), 1 (single-user mode), 2 (multiuser, without NFS), 3(full multiuser mode), 4 (unused), 5 (x11), 6(reboot)

Init Stage - Now the system executes runlevel applications. To determine Linux run level, it looks for an init file - typically found at /etc/inittab

Further Reading: BIOS vs UEFI

Last updated