Skip to main content

Command Palette

Search for a command to run...

Booting Process

Updated
16 min readView as Markdown

We now work almost all day on our computers. A decade ago it took more than a minute or two to start your computer & now we live in a world where almost all devices take less than 30 seconds to boot up, ever wondered how many things need to go right just to get our mega systems fitted in tiny sizes to start up. Let's get started with a definition.

What is Booting? As per Wikipedia, in computing, booting is the process of starting a computer. It can be initiated by hardware such as a button press, or by a software command. After it is switched on, a computer's central processing unit (CPU) has no software in its main memory, so some process must load software into memory before it can be executed. This may be done by hardware or firmware in the CPU, or by a separate processor in the computer system.

As stated above booting can be initiated by either hardware or by software. This article will focus mostly on hardware initiated booting of personal computers so as to relate & understand our daily used systems better.

A quick right-click on the Start button on the Windows machine & then the 5th option from top 'System' will tell you that your OS is 64-bit OS & you've got an x64 based processor. The 64 in x64 indicates the number of bits of register that your CPU i.e. your Microprocessor is made of. Today almost all CPUs have 64-bit microprocessors. But in past for a long period of time 32-bit microprocessors were prominently used. Now keep this in mind.

Hereafter our discussion will only be limited to 64-bit based CPUs

Part 1: You press the Power On button to start booting

As soon as you press the power-on button, the electric energy stored in the battery of the PC starts to flow towards Motherboard through dedicated data lines & power-ups a part of Motherboard. These data lines are physically printed on the board while manufacturing for such purposes.

Part 2: Electricity comes to Motherboard

When the electricity comes to the motherboard, it directs this electric current to a small part of itself, this part is called as CPU Socket/CPU Slot.

In computer hardware, a CPU socket or CPU slot contains one or more mechanical components providing mechanical and electrical connections between a microprocessor and a printed circuit board (PCB). This allows for placing and replacing the central processing unit (CPU) without soldering.

If you go to the Performance tab in Windows Task Manager you'll be able to see how many sockets does your motherboard has. One socket on any system Motherboard means that it can hold 1 CPU in its slot. It is possible to have multiple sockets on a single Motherboard & hence possible to have multiple CPUs but usually modern personal computers have only 1 socket & 1 CPU.

So more precisely, when the electricity comes to the motherboard, it directs this electric current to a socket through physically present data lines & wakes up or initializes at least 1 CPU.

Part 3: That electric energy now arrives at the CPU. CPU wakes up.

The electric current coming from specific dedicated physical data lines to wake up the CPU enables the CPU to recognize & identify that this electric current is meant to start the initialization of the Booting process.

A CPU has physical connections through different types of buses to almost all internal & external subsystems & components of the system through printed lines connected to the Motherboard socket. By recognizing that the current received is for System Booting process, after waking/starting up for the new first time CPU as its default hard-coded behavior like a reflex action goes to another place called as Boot ROM.

Hardcoded means fix & embedding data directly into source code manually, to not make it easy to alter that data. So in a way the starting memory address of Boot ROM is hardcoded or preconfigured permanently if the process is Booting process & CPU initializes for the first time. This hard-coded memory location for the CPU is called as Reset Vector.

Now as the CPU awakens, through physical dedicated lines it accesses a physical Boot ROM situated in some other place on Motherboard.

Part 4: Boot ROM

Boot ROM is a special purpose Read-Only Memory specifically used for the Booting process. It is a physical small piece of mask ROM or Write Protected Flash embedded on the Motherboard, directly in touch with the CPU through physical data lines. Usually, there are multiple ROMs on a single motherboard having unique functionality, each for a different purpose. The true ROM is replaced by EEPROM & nowadays by NOR Flash memory.

Boot ROM contains the very first code or program called as Firmware. This firmware program is called as BIOS program which is executed by the CPU/processor as its first thing to do.

Now using Reset Vector as soon as the CPU accesses the memory locations of Boot ROM that has a firmware program called BIOS, it immediately fetches it & starts executing the instructions of the BIOS program one by one from these locations.

BIOS firmware program comes preinstalled in our PC these days but can be modified & updated. It is the first software executed by CPU & runs on our system when powered on.

One thing to note, every code, program, software, application, etc. that you run by double click, is turned into a process by Operating System by actually copying the necessary code in the primary memory i.e. RAM & is executed on the CPU using this copy from RAM.

Now as of now the CPU is executing the BIOS firmware program/software/code instructions copied into RAM from the Boot ROM, which it accesses from the memory locations hard-coded in the CPU itself.

Part 5 : BIOS

Now buckle up, this is gonna be a ride as we dive a little bit deeper into hardware. Remember everything connects at the end.

When the system starts for the first time as soon as you press the Power On button, the CPU starts & executes in Real Mode (Real Addressing Mode). When a processor is in Real Mode, all the address locations that it accesses or addresses correspond to Real Address locations in physical memory.

When the system starts, the CPU (aka Processor) starts up in Real Mode & in this mode, even if the CPU is a 64-bit processor it can access only a 20-bit memory address space giving exactly 2^20 = 1 MiB of addressable memory.

The memory location in Boot ROM from which the CPU started executing the first instruction code for the first time as soon as it is able to execute was:

For 16-bit (x86) Processors: FFF0h For 32-bit, 64-bit (x86) Processors: FFFFFFF0h

This memory address location is called as Reset Vector, this Reset Vector memory address is considered as the Entry Point pointing to the first instruction of the BIOS program inside the ROM. These addresses are decided by the OEMs of these processors. The memory location of FFFFFFF0h is actually the end of the BIOS program in ROM & contains a jump instruction to a location of the BIOS that contains the BIOS start-up code & from where the actual BIOS program actually starts.

As the BIOS program starts executing, it performs the Power On Self Test. We can say that POST is a set of multiple small functions. Some of them are given below.

  1. Display the BIOS startup screen

  2. Give error codes or beep sounds if something goes wrong with any hardware.

  3. Detect video card, audio card, or any other chips or hardware devices present & initialize their BIOS if present. These are called Option ROM Modules or BIOS Extension ROMs or Add On ROM procedures.

  4. Perform a brief Memory Test, identify how much RAM memory is in the system.

  5. Set memory & drive parameters.

  6. Configure Plug & Play devices like PCI bus & other types of buses.

  7. Assigns resources like DMA channels & IRQ lines.

  8. Identify the Boot Device

  9. Initialize a small library of basic input & output functions to operate peripheral devices like keyboard, mouse, text/graphics display functions.

Points to note at this moment, a. All the instructions of these functions of the BIOS program were in Boot ROM but were copied by CPU into RAM & now all these functions are executing on RAM. b. At this moment, the CPU is still executing all this in Real Mode, so it has access to only 20-bit memory address space i.e. only 1 MiB of RAM memory is accessible right now.

Now out of this 1 MiB addressable memory space, IBM (one of the prominent & earliest companies to develop a BIOS program) in old times reserved the upper 384 KiB for holding BIOS program, some Boot ROM data & other Option ROM modules. This area of 384 KiB memory is called Upper Memory Area/Block (UMA/UMB). The area below UMA consists of 640 KiB memory & is called Conventional Memory. The very next 65520 bytes above the UMA is called High Memory Area (HMA/HMB) & the memory above this is referred to as Extended Memory.

Now the BIOS program after the POST test scans the UMA for Option ROM Modules & runs each ROM found in order, while scanning all different ROMs it also scans the Real Mode address space from 0x0C0000 to 0x0F0000 to discover memory-mapped Industry Standard Architecture (ISA) based Option ROMs like PC/AT bus used by Intel 8086 & 8088 on IBM computers in the 1980s to identify Floppy Disk or Hard Disk Controller. In modern BIOS & processors, the addresses may have changed. The actual addresses can be found in respective processor manuals.

After scanning all option ROMs & all detected ROM modules with valid checksums have been called, the BIOS calls BIOS Interrupt CallINT 19h to start the OS Boot process.

When INT 19h is called, the BIOS attempts to locate the 'Boot Loader or Boot Software or Loader' program on a 'Boot Device' such as hard disk drive, floppy disk, CD, DVD, Pendrive, etc. It loads & executes the first boot software or boot loader it finds & gives it the controls of the computer.

After initializing all the hardware devices the BIOS firmware checks the Boot Device in BIOS settings which are stored in a non-volatile BIOS memory backed by CMOS battery (nowadays UEFI uses Flash Memory & NVRAMs here) & goes through a pre-configured list of non-volatile storage devices like hard disk drive, floppy disk, CD, DVD, Pendrive, etc one by one in order until it finds one that is bootable. This sequence of hardware devices BIOS goes through to find a boot device is called as Boot Device Sequence or Boot Order.

The BIOS checks each device in order to see if it is bootable by attempting to load the first sector called as Boot Sector of each bootable device.

After initializing all hardware & POST test, calling the Interrupt 19 (INT 19) is the last action performed by POST. You can invoke this interrupt manually by using Ctrl-Alt-Del, if you use this key combination it is called as Warm Boot, otherwise, if the interrupt is called in order automatically by BIOS, it is called as Cold Boot. The major difference between Warm & Cold Boot is that in Warm Boot RAM is not tested, else everything is same.

Once this interrupt is invoked the BIOS attempts to locate the boot devices and load the first sector at head 0, track/cylinder 0, sector 1 on the first boot device, or diskette (floppy drive in old times) into memory at 0:7C00h. I explain what actually is the head, track/cylinder, sector & address 0:7C00h on hardware level further below in the article. If it is unable to load it then moves to the next boot device identified, let's say here it's connected to a hard disk or pen drive or CD or DVD. It then attempts to load the sector at head 0, track/cylinder 0, sector 1 of that next identified boot device into memory at 0:7C00h again. This process continues until the right boot device is found. If it fails or is unable to load from any boot device it calls INT 18h, which calls optionally ROM BASIC & gives the error No Boot Device Found.

If INT 19h is successful & a sector is loaded on memory from either of the boot devices the control is transferred to the first byte of the sector, which has been read in at memory location 0:7C00h that is code segment CS is set to 0 & instruction pointer is set to IP = 7C00h. The boot sector read from the boot device, in turn, reads in the rest of the Operating System in memory. A fixed disk that is a hard disk will read in the partition table if there are multiple drive partitions on the hard disk, which will then read in the correct operating system if multiple OSes are installed on multiple partitions. The scan for boot devices usually starts from Removable Media like CD, DVD, USB sticks, external HDD followed by hardcoded drives.

Below I elaborate on the above point in more detail.

Now after the POST Test, after calling INT 19h, as the BIOS goes on checking each non-volatile storage device to which the system is connected, it goes on attempting to load the first sector that is the first 512 bytes of each device until it finds a bootable boot device.

If sector read is unsuccessful, it moves to the next device. If the sector is read successfully into memory, before accepting that boot sector & considering that device as Boot Device or bootable, BIOS checks & verifies the Boot Sector/ ROM/ MBR Boot Signature of 0x55 followed by 0xAA in the last two bytes of the 512 bytes long 1st sector of that non-volatile storage device.

A Boot Sector / ROM / MBR Boot Signature is just to identify or recognize that the sector of the device is safe to execute. Having 2-byte hexadecimal sequence 0x55 followed by 0xAA at the end of the 1st sector (i.e Boot Sector) of any storage device indicates & is considered that the Boot Sector has IBM PC compatible Boot Loader for x86 CPUs.The use of the booth sector sign was introduced by IBM PC/AT to easily identify if the read sector is bootable or not.

The presence of Signature on a boot sector indicates the presence of at least a Dummy Boot Loader, which is safe to be executed, even if it may not actually load the OS. It doesn't indicate the presence of any particular file system or OS. This sign check is utilized by most system BIOSes since the time of IBM PC/AT computer & also by MBR Boot Loaders before passing the control to the boot sector. If BIOS doesn't detect a valid booth sector as previously discussed it moves to the next non-volatile storage device in the row. If all fails INT 18h is invoked displaying an error message & starts an optional resident software program in ROM called as ROM BASIC or the system gets rebooted after calling INT 19h after user confirmation or cause the system to halt the bootstrapping process until the next power-up.

If BIOS detects a valid boot sector with valid Boot Sector/ ROM/ MBR Boot sign & INT 19h is successful. BIOS selects the device & its first sector (Boot Sector) as Bootable Device or Boot Device & transfers the control to the loaded sector. The BIOS doesn't interpret the contents of the whole booth sector except the last two bytes to check Boot Sector Signature.

Once BIOS finds the bootable device it loads the first sector boot sector that is first initial 512 bytes of that storage device at address 0:7C00h, Code Segment (CS) register set to 0, Instruction Pointer (IP) register set to 7C00h & transfers the control to this boot code & CPU starts executing the instruction from the first byte of booth sector loaded in the memory.

Good To Know: If the Boot Sector of any HDD is physically damaged, HDD will no longer be bootable since partitioning data of disk is also stored in the Boot Sector. The HDD will become entirely unusable except when used in conjunction with custom software and custom BIOS to define a non damaged sector as Boot Sector.

Now at this point, BIOS has loaded Boot Sector i.e first 512 bytes from bootable Boot Device (e.g HDD or Pen Drive of let's say 16GB or 64GB or 2TB) into the memory at a location 0:7C00h. CPU is about to start executing the instruction from the first byte of this 512 bytes sector & thus transferring the execution control to this code (aka Boot Code). This boot sector and its 512 bytes once loaded in memory are now referred to as Master Boot Record.

Let's talk about Hard Disk Drives more

In a hard disk drive or any storage device of let's say 4 GB, 64 GB to 4 TB the actual storage space at the down most physical level is divided into sectors of 512 bytes each. So in a 10TB hard disk, there can be millions or billions of sectors & each sector size is fixed at 512 bytes by the OEM companies of the many magnetic hard disks or any other such storage devices while manufacturing the actual physical hard disk drives.

A Sector in computer disk storage is a subdivision of a track on a magnetic or optical disk. Each sector can store a fixed amount of user-accessible data traditionally 512 bytes for HDD and 2048 bytes for CD drive and DVD ROM. Newer HDD have 4096 bytes or 4 KiB size sectors which are known as Advanced Format. A Sector is the minimum storage unit of hard disk drives.

Good to know: In NAND flash memory storage devices like pen drives, memory cards, SSDs, there are no Sectors on the hardware level. Instead due to the architecture of NAND flash memory, there are Pages of size to 2 KiB, 4 KiB, or 16 KiB instead of Sectors that are conceptually analogous to each other.

When you want to store some data on each sector of a hard disk drive, you'll have to use some Operating System (OS) because only the operating systems have hard disk drivers & other code utilities that enable a user to write on each sector of the hard disk drive. Most disk partitioning schemes of different OSes are designed to have files occupy an integral number of sectors regardless of the actual file size (i.e a File is required to occupy 1 or 2 or 26 or n sectors completely. Not 2 & half sectors or 16 & 1/3rd sectors). Files that do not fill a whole sector will have the remainder of their last sector filled with zeros. Now in practice, for larger memory space access & better management of so many sectors, OS abstracts these sectors & operates on its own logical minimum storage unit called as File System Block. File System Block (OS) vs Disk Sector (Physical HDD)

One of the most important reasons why OS introduces this logical block unit of storage & not directly use the physical sector unit of storage is to achieve the goal of 'Maximum Throughput In Minimum Hardware Movement', if you use sector as a unit to access the storage addresses then to access large files of let's say 1-2 GB from 512 GB or 1 TB hard disk you'll have to move the disk arm of physical hard disk drive hardware for millions or billions of times to access each sector. This can wear out the hard disk drive very quickly.

The operating system's logical block unit of storage spans through multiple sectors for each block. Thus now when we read one block of memory storage, we actually read more than one or multiple of sectors in one go i.e in multiples of 512 bytes in a single physical arm movement in one time read thus achieving our goal. So if an OS considers its block size as 4 KiB then it is equal to reading 8 physical sectors of 512 bytes each in one disk arm movement. Likewise, 8 KiB block size is equaled to reading 512 bytes X 16 sectors in one disk arm movement. Such big disk arm movements are achieved using HDD Drivers through OS.

Different types of OSes have different types of file systems that are required to be installed on hard disk drives & different types of file systems have different logical block sizes. For e.g UNIX logical block size is 1024 bytes, for BSD it is 8 Kib (8192 bytes), for Windows it is 4 Kib (4096 bytes), for Linux it is 4 KiB.

Good To Know: For USB and SSDs, NAND flash memory there's a common block size for Read, Write or Erase operations among all OSes, this OS-level logical block size is of 128 KiB (which is further divided into Pages of 2 KiB).