January 01, 2019
When you turn on your computer the system goes throgh different stages in order to initialize the hardware and then pass over the control to the OS (in particular this scheme is based on an x86 processor and linux).
The first step is carried out by the instructions placed in the motherboards ROM chip or flash memory, the BIOS firmware (
Basic Input Output System).
POST - power on self test takes place at this time: Ram, Screen, keyboard are checked,
Starting an x86 based linux system involves many steps.
When a computer is powered on the
Basic Input Output System initializes the hardware, including screen and keyboard, and tests the main memory. This process is also called POST (Power on self test).
The Bios software is stored in a rom chip on the motherboard.
After this step the boot process is delegated to the OS.
After POST is completed the system control passes to the bootloader.
The bootloader is usually stored on one of the hard disks in the system,
either in the boot sector (for traditional BIOS/MBR) or the EFI/ESP (for more recent UEFI systems).
Up to this stage the machine does not have access to any mass storage media. Thereafter, information on the date, time and the most important peripherics are loaded from the CMOS values (after a technology used to for the battery-powered memory storage which allows to keep track of the date and time even when it’s powered off). When booting linux the bootloader is responsabile for loading the kernel image and the initial ram disk/filesystem onto memory.
The bootloader has 2 distinct stages
The initramfs filesystem iamge contains programs and binary files that perform all actions needed to mount the proper root filesystem, like providing kernel functionality for the needed filesystem, and device drivers for mass storage controllers with a facility called udev (u for user, dev for device), which is responsible for figuring out which devices are present, locating the drivers they need to operate properly, and loading them. After the root filesystem is found it is checked for errors and mounted.
The mount program instructs the OS that a filesystem is ready for use, and associates it with a particular point in the overall hierarchy of the filesystem (the mount point). If this is successful, the initramfs is cleared from RAM and the init program on the root filesystem (/sbin/init) is executed.
Init handles the mounting and pivoting over to the final real root filesystem. If special hardware drivers are needed before the mass storage can be accessed, they must be in the initramfs image.
Near the end of the boot process, init starts a number of login prompts. Init has runlevels that corresponding to the different phases in which functionalities are started:
Runlevels are valid both in SysVinit and SystemD, while booting through grub it is possible insert an option that defines which runlevel is being targeted.
The booting process is something that I’ve always seen with a big deal of admiration, each stage builds upon the stage before and getting a complete OS up and running has quite a lot of steps; and all this is being done every time you turn on your pc.
Think about it the next time you press the power button.
Francesco Calo developing on linux in La Spezia.
Just a programming journey.