Skip to content
Advertisement

PC bootstrap process step by step

The bootstrapping process is a bit confusing, I hope I understand it correctly. I will try to describe my understandings and hopefully can be corrected. As this is an extremely important and I want to dive into the small details.

BIOS:
It sets up an interrupt descriptor table and initializes various devices. After initializing all the important devices the BIOS knows about, it searches for a bootable device such as a floppy, hard drive, or CD-ROM.
Hard disks are divided into 512 bytes regions called sectors and the first sector is known as boot-sector. Once the BIOS finds a bootable floppy or hard disk, it loads the 512-byte boot sector into memory, then passes control to the boot loader.

Boot-loader:
1. The boot loader switches the processor from real mode to 32-bit protected mode, because it is only in this mode that software can access all the memory above 1MB in the processor’s physical address space. 2. The boot loader reads the kernel from the hard disk

Kernel:
The kernel begins with some assembly language code that sets things up so that C language code can execute properly. And enables paging.

Memory layout

|---------|
|         |
|   boat  | Sector 0
|  loader |
|         |
|---------|
|         |
|         |
|         | Sector 1
     .
     .
     .

My questions:

  1. How does the boot-loader know where is the kernel found ?
    From what I remember, an ELF header contains the number of sectors the boatloader should load. But how does it find this ELF header ? What structures does it use to find these details ?

  2. The Bios is located on an EEPROM chip, yet some books like to show that BIOS is on the first sector in hard disk and bootloader is on second. This confuses me a bit.

  3. Is the Kernel always brought into the same address in main-memory ? if so who/what determines this address ?

  4. Is the boot-loader always brought to 0x0000 - 0x7c00 block of memory ?

Any additional information about the flow will be welcomed. And I am sure I missed some responsibilities of these 3.

Advertisement

Answer

How does the boot-loader know where is the kernel found ?

Actually, the 512 bytes boot-loader does not load the OS kernel itself but the second boot-loader stage. This second stage is what is usually known as the boot-loader. It may be the Windows bootmgt or grub or lilo or a bunch of others. This boot-loader is usually located in a fixed place in the disk, sometimes the second sector, sometimes the second cylincer…

Then, the details vary, but usually that bigger boot-loader loads a configuration file that tells them where the real kernel is. Sometimes it even includes code to read a full filesystem.

The Bios is located on an EEPROM chip, yet some books like to show that BIOS is on the first sector.

Maybe they are mixing the first stage boot-sector in the first sector with the second stage boot-loader in the next few sectors?

Is the Kernel always brought into the same address in main-memory? Is the boot-loader always brought to 0x0000 – 0x7c00 block of memory ?

In a standard 32-bit PC, the boot sector is always loaded at address 0000:7C00, still in real-mode. That is a standard PC convention, from the IBM-PC days. Then, it will load the second stage in whatever memory it will decide and pass on. That’s why every time you install a boot-loader you have to rewrite the boot-sector too. Some boot-loaders will switch to protected mode and load the OS directly, while others will work in real-mode and the OS kernel will switch to protected mode and move itself to upper memory.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement