Skip to main content

Booting Procedure in Linux

 

Booting


Linux is a popular operating system that runs on a variety of devices, from desktops and laptops to servers and embedded systems. But how does Linux start up and load the operating system? In this post, we will explore the six stages of the Linux booting process, from the moment you turn on your device to the moment you see the login prompt.

1. BIOS

BIOS stands for Basic Input/Output System, and it is the first program that runs when you power on your device. BIOS is stored in a ROM chip on the motherboard, and it is responsible for initializing the hardware components and peripherals, such as the keyboard, display, disk drives, and serial communications. BIOS also performs a power-on self-test (POST) to check the integrity and functionality of the hardware.

After the POST, BIOS looks for a bootable device, such as a hard drive, a USB drive, or a CD-ROM, depending on the boot order configured in the BIOS settings. BIOS then reads the first sector of the boot device, which is called the Master Boot Record (MBR), and loads it into memory. The MBR contains the boot loader program, which is the next stage of the booting process.

2. MBR

MBR stands for Master Boot Record, and it is the first 512 bytes of the boot device. The MBR contains three parts: a boot code, a partition table, and a boot signature. The boot code is a small program that locates and loads the boot loader, such as GRUB or LILO. The partition table contains information about the partitions on the disk, such as their size, type, and location. The boot signature is a 2-byte value that identifies the MBR as a valid boot sector.

The boot code in the MBR executes and scans the partition table for an active partition, which is the partition that contains the boot loader. The boot code then reads the first sector of the active partition, which is called the boot sector, and loads it into memory. The boot sector contains the second stage of the boot loader, which is the next stage of the booting process.

3. GRUB

GRUB stands for GNU GRand Unified Bootloader, and it is the most common boot loader for Linux systems. GRUB consists of two stages: the first stage is stored in the boot sector, and the second stage is stored in a file system. The first stage of GRUB loads the second stage, which is a larger program that can access multiple file systems and display a graphical menu. The menu allows the user to select a kernel image to boot, or to edit the boot options. If the user does not select anything, GRUB loads the default kernel image after a timeout.

GRUB can also chain-load other boot loaders, such as Windows Boot Manager, by loading their boot sector instead of a kernel image. GRUB can also load an initial RAM disk (initrd) image, which is a temporary file system that contains drivers and modules needed by the kernel. GRUB then passes control to the kernel, which is the next stage of the booting process.

4. Kernel

The kernel is the core of the Linux operating system, and it is responsible for managing the system resources, such as memory, CPU, disk, network, and devices. The kernel also provides an interface for user programs to access the system services, such as system calls, signals, and interrupts. The kernel is stored in a file, usually named vmlinuz, in the /boot directory.

When GRUB loads the kernel, it decompresses it and copies it into memory. The kernel then initializes itself and the hardware devices, using the information passed by GRUB and the initrd image. The kernel also sets up the virtual memory, the scheduler, the network stack, and the security framework. The kernel then mounts the root file system, which is the main file system that contains the operating system files. The kernel then executes the first user program, which is /sbin/init, and passes control to it. This is the next stage of the booting process.

5. Systemd / init

Systemd and init are programs that initialize and manage the user space, which is the environment where user programs run. Systemd and init are also called init systems, and they are responsible for starting and stopping services, such as network, logging, graphical interface, and user login. Systemd and init are also called process 1, because they have the process ID of 1, and they are the parent of all other processes.

Systemd and init are configured by files that specify the dependencies and order of the services. Systemd uses unit files, which are located in /etc/systemd/system or /usr/lib/systemd/system directories. Init uses init scripts, which are located in /etc/init.d or /etc/rc.d directories. Systemd and init also use runlevels or targets, which are modes of operation that define the set of services to run. For example, runlevel 3 or multi-user.target is the mode for text-based login, and runlevel 5 or graphical.target is the mode for graphical login.

Systemd and init start the services according to the runlevel or target specified by the kernel or the user. Systemd and init also monitor the services and restart them if they fail. Systemd and init also allow the user to change the runlevel or target, and to start or stop services manually. Systemd and init then start the last service, which is the login prompt, which is the final stage of the booting process.

6. Runlevels [0-6]

Runlevels are modes of operation that define the set of services to run on a Linux system. There are seven standard runlevels, numbered from 0 to 6, and each runlevel has a different purpose and functionality. The runlevels are:

  • 0: Halt. This runlevel shuts down the system and turns off the power.
  • 1: Single-user mode. This runlevel allows the user to perform maintenance tasks, such as repairing the file system or changing the password. Only the root user can log in, and no network or graphical interface is available.
  • 2: Multi-user mode without network. This runlevel allows multiple users to log in, but no network or graphical interface is available. This runlevel is rarely used, and it is similar to runlevel 3.
  • 3: Multi-user mode with network. This runlevel allows multiple users to log in, and the network is available. However, no graphical interface is available, and the user can only use the text-based console.
  • 4: User-defined. This runlevel is not used by default, and it can be customized by the user or the system administrator.
  • 5: Multi-user mode with network and graphical interface. This runlevel allows multiple users to log in, and the network and the graphical interface are available. This is the default runlevel for most desktop Linux systems, and it provides the full functionality of the system.
  • 6: Reboot. This runlevel restarts the system and boots into the default runlevel.

The user can change the runlevel by using the init or systemctl command, or by editing the /etc/inittab or /etc/systemd/system/default.target file. The user can also see the current runlevel by using the runlevel or systemctl get-default command.

Conclusion

In this post, we have learned about the six stages of the Linux booting process, from BIOS to runlevels. We have seen how each stage performs a specific task and passes control to the next stage, until the system is fully operational and ready for the user. We have also learned about the configuration files and commands that control the booting process and the services. We hope that this post has given you a better understanding of how Linux boots and works.

Comments

Popular posts from this blog

Cockpit vs. Webmin: A Detailed Comparison for Linux Administration

  Introduction In the realm of Linux system administration, having efficient tools for managing and monitoring servers is crucial. Two popular tools that system administrators often use are  Cockpit  and  Webmin . Both of these tools provide a graphical interface accessible via a web browser, simplifying the management of Linux systems. This blog post will explore what Cockpit and Webmin are, their purposes, a comparison table, and additional information to help you choose the right tool for your needs. What is Cockpit? Overview Cockpit is a web-based graphical interface for managing Linux systems. It is designed to be easy to use, enabling both experienced and novice administrators to manage their systems effectively. Cockpit integrates seamlessly with the system’s existing infrastructure, providing real-time monitoring and management capabilities. Purpose Cockpit is primarily used for: Monitoring system performance and resource usage Managing system services Handli...

How to Set Up Custom Screen Resolution on Fedora 38 Permanently

  If you are using Fedora 38 as your operating system, you may have encountered some issues with the screen resolution. The default resolution may not be suitable for your monitor or your preferences, and you may want to change it to a higher or lower value. However, changing the resolution from the Settings menu may not work properly, or it may not persist after a reboot. In this blog post, I will show you how to set up a custom screen resolution on Fedora 38 permanently using some simple commands and configuration files. The first step is to disable the Wayland display server, which is the default display server for Fedora 38. Wayland is a modern and secure display server, but it may not support some custom resolutions or drivers. To disable Wayland, you need to edit the /etc/gdm/custom.conf file as root. You can use any text editor of your choice, such as nano, vim, or gedit. To open the file with nano, for example, you can type the following command in the terminal: sudo nano ...

Key Concepts and Tools for a Linux System Administrator

  A Linux System Administrator needs to have a comprehensive understanding of various concepts and tools to manage, configure, and maintain Linux systems effectively. Below is a categorized list of essential skills and tools with brief descriptions. Category Key Concepts & Tools Description Operating System Linux Distributions (e.g., Fedora, Ubuntu, CentOS) Knowledge of different Linux distributions, their package management systems, and unique features. Kernel Configuration and Management Understanding how to configure and optimize the Linux kernel for different workloads. System Boot Process (GRUB, systemd) Familiarity with the boot process, bootloaders, and system initialization processes. Command Line Skills Bash Shell Scripting Ability to write and debug shell scripts for automation of tasks. Core Commands (ls, cp, mv, rm, find, grep, awk, sed) Proficiency in using basic and advanced command-line utilities for system management. File System File System Hierarchy Standard (...