Behind the scenes: From Pressing the power button to Getting to the Login Screen
Tags: beginners, linux, bootup, tutorial
Published: 2022-05-03 19:40:51

# Introduction
Ever wondered how your modern PC get to the Login screen with a mere press of a button? Are you curious of what happens behind the scenes of bootup or do you want to get called up by your friends when they face an error while booting up their PC? If yes, you're at the right place.

`Boot up` is not just a short-hand for `Powering on a PC`, it's actually a long and vital process. It's involves an extensive list of things that takes place to get a **fully-functional session** of an operating system. In this blog, we'll look upon the entire boot process from **BIOS** to **Bootloader**.



### 1) Pressing the Power button

![CPU](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mf6atn3sw2vejbubxzyp.jpg)
When you press the Power button, the `Power supply` in the CPU cabinet supplies the power to it's units like-Hard disks, motherboard and SSDs to name a few. 

Once, all the units gets power, CPU looks for a program called **BIOS** or **UEFI**(in modern systems).

### 2) BIOS/UEFI and Performing POST


![BIOS screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1jzswftf5x7iwjd12at.jpg)
> **BIOS** stands for `Basic Input and Output System`. Even though it hasn't evolved much, it has certainly changed it's residence many time from `CMOS SRAM` to `NOR flash`. It resided in `CMOS SRAM` in it early days but as SRAM was _volatile_, it's contents got flushed after turning OFF the computer.
> BIOS then took it's place in `PROM`(non-erasable), `UV-ROM`(erasable by UV rays) and finally ended up in `flash memory` backed up by a **CMOS battery**.

BIOS performs `POST`(_Power-on self-test_) wherein it sends a signal to all devices and check's if they're up and running. If there's some error, it _beeps_ and shows an error. The number of times it beeps signals the type of error. For example, if there's a **RAM failure** in a certain _Dell laptop_, it will beep **3 times** signaling the error. You can know more about beep codes and corresponding errors [here](https://www.computerhope.com/beep.htm).

Now, once the BIOS is done testing the hardware, it hands over the control to the Operating system's `bootloader`.

### 3) Stage-1 Bootloader(Primary Bootloader)

![Bootloader](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7q9pqcy5akdjlnjv7os8.jpg)

BIOS looks for the Operating System to boot and load for which it has to select a `Boot Device`. This can be HDD, SSD, USB, CD or DVD drive.

For `MBR partitioning` system, we have the bootloader in the first sector of the hard disk called `MBR Sector`.
> MBR sector is 512 bytes long and has primarily 3 partitions: 

> 1) **446 byte** for `Primary Bootloader`
> 2) **64 byte** for `Partition Table` (4 tables of 16 bytes each)
> 3) **2 byte** for `Magic Number` (Validation of MBR)

The **main task** of 446-byte long primary bootloader, also referred to as the stage-1 bootloader, is to **find the** `secondary bootloader`. It finds it by looking through the partition table.

 
### 4) Stage-2 bootloader(Secondary bootloader)


![Bootloader](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sr9aotm60mfo30m54upz.png)

Now, once the Stage-2 bootloader is loaded, it actually loads the **operating system**.


It does this by loading the `kernel` and `optional initial RAM disk`(initramfs). The kernel starts the `init system`(systemd mostly) which starts other **services** leading all the way to login screen.


![Ubuntu login screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w88whueiondg07areqvv.png)

For Linux, we have `GRUB bootloader`, Windows uses `Windows Boot Manager` and Macs use `boot.efi`.

> **UEFI/GPT-based** systems use something called `EFI executable` which doesn't have to be present in the first sector of the disk.



All these processes hardly take a few seconds. The evolution in the tech-world has made the computer boot up process lightning fast!