Booting is a process when a computer system initializes itself and loads the operating system(OS).
So what happens during a boot process on a Linux machine (this post is relevant to Ubuntu, however most systems would do similar steps) ?
- When you push the power on button, the BIOS (Basic Input/Output System) loads from the ROM present on the motherboard
- It launches the Power On Self test (POST) which involves starting the hardware specifically the screen and the keyboard and testing of the RAM i.e. main memory
- Boot Loader
- Once the POST completes, the boot loader takes over. The boot loader is present on the hard disk and for Linux systems the common ones are GRUB and ISOLINUX. Depending on the type of system i.e BIOS/MBR or EFI/UEFI the location of the boot loader varies. For the former it is present at the boot sector and for the latter it is in EFI partition
- Common boot loaders for Linux are GRUB and ISOLINUX.The boot loader is responsible for loading the kernel as well as initramfs and it does this in two stages
- For BIOS/MBR systems the boot loader is located at the Master Boot Record which is the first sector of the hard disk. The bootloader finds a bootable partition after reading the partition table. It then searches for the stage two bootloader e.g. GRUB and loads it in the main memory. For EFI/UEFI systems, the UEFI firmware reads the data from the Boot Manager looking for an entry named GRUB (UEFI location) and determines its location (partition etc.). The GRUB is located at /boot. Incase the system has multiple OS a screen is provided for a choice. After a selection is made, the boot loader loads the respective kernel in RAM. The kernel takes over and uncompresses itself, it analyzes the hardware (processors, I/O subsystems, storage devices) and loads the device drivers present in the kernel and certain necessary user space applications
- The bootloader also loads the initramfs (Initial RAM Disk) which is a filesystem image containing programs,binary files which help to mount the proper root filesystem. It must also contain drivers which are necessary for accessing the hard disk etc.It uses a component called udev (for User 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 has been found, it is checked for errors and mounted on the mount point.
- At this stage the file system is mounted and after this the init (/sbin/init) program is then executed after clearing the initramfs from the RAM. The init process launches other processes except the kernel processes required for the internal working of the OS. It launches the text login prompts i.e shell using getty.
- The X Window System is loaded as the final step in the boot process. Sometimes the process stops at the text login in that case we can use startx command to launch the X Window System.(Usually Alt + (F1-F6) are text logins and Alt + F7 is the GUI login). The X Window System consists of a display manager to track the displays and load X server, load the appropriate desktop login. The desktop environment has a session manager, which is responsible for starting and maintaining the components of the graphical session. It also has the window manager, which controls the placement and movement of windows, window title-bars, and controls.
- And now you have your GUI login ready.