It is really interesting to understand booting process of computer. How does your dead computer get life and how does it open its eyes?
When a computer starts up (obviously by pressing the power button), the first thing that occurs is it sends a signal to motherboard which in turn starts the power supply. After supplying the correct amount of power to each device, it sends a signal called "Power OK" to BIOS which resides on motherboard.
Microprocessor sets it's registers CS:IP to linear address FFFFFFF0h, usually pointing to the BIOS entry point inside the ROM.
This memory location typically contains a jump instruction that transfers execution to the location of the BIOS start-up program.
About BIOS :
- BIOS stands for Basic Input/Output System.
- Performs some system integrity checks (POST).
- Searches, loads, and executes the boot loader program.
- It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
This program runs a power-on self-test (POST) to check and initialize required devices such as DRAM and the PCI bus (including running embedded ROMs).
After initializing required hardware, the BIOS goes through a pre-configured list of non-volatile storage devices ("boot device sequence") until it finds one that is bootable.
A bootable device is defined as one that can be read from, and where the last two bytes of the first sector contain the little-endian word AA55h (also known as the MBR boot signature).
Last job of BIOS is to load the boot sector to linear address 7C00h (usually Segment:Offset 0000h:7C00h) and transfers execution to the boot code. In the case of a hard disk, this is referred to as the Master Boot Record (MBR) and is by definition not operating-system specific.
About MBR :
- It is located in the 1st sector of the bootable disk.
- MBR is less than 512 bytes in size.
- This has three components
- Primary boot loader info in 1st 446 bytes
- Partition table info in next 64 bytes
- MBR validation check in last 2 bytes.
What happens in DOS :
- One of the primary partition is marked as an active partition.
- Program control is then transfered to starting address of that partition.
- Code written at starting of that partition is gets loaded in main memory at 7C00h and computer start executing it.
What happens in Linux :
- Ideally boot loader should fit in 446 bytes. But GRUB is much more than it. So, GRUB is divided into 2 stages.
- MBR contain 1st stage of GRUB.
- Task of stage 1 of GRUB is just to load the stage 2 which resides in "/boot" with the help of partition table.
GRUB stands for Grand Unified Bootloader. GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
In general, GRUB can do two things :
- It can load the image of Kernel in main memory.
- It can pass the program control to another bootloader. You can make the chain of such bootloaders, it is called as chain loading.