Linux boot process explained (a detailed thread)π§Άβ
When you turn on your Linux computer, it goes through a series of phases before presenting a login screen that prompts you for your username or password.
Every Linux distribution goes through four distinct stages during the boot-up process.
The booting process consists of four steps, which we will go over in this thread:
β’ BIOS and UEFI Integrity check (POST)
β’ Loading of the Boot loader (GRUB2)
β’ Kernel initialization
β’ Starting systemd, the parent of all processes
1. BIOS and UEFI Integrity check (POST)
First, when the system boots, the BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface) program launches and performs a Power On Self Test (POST).
This is an integrity check that runs a slew of diagnostic tests.
The POST process validates the hardware components and peripherals such as the HDD or SSD, keyboard, RAM, USB ports, and any other hardware. It also runs tests to ensure that the computer is in good condition.
Furthermore, if this test detects an error, it will typically display an error message on the screen, requesting your intervention.
If the test fails to detect the RAM, POST produces a beeping sound; otherwise, if the expected hardware is present and functioning properly, the booting process advances to the next stage.
BIOS and UEFI are firmware interfaces used by computers to start the operating system (OS). However, the two programs differ in their approach to storing metadata on and about the drive:
β’ BIOS uses the Master Boot Record (MBR)
β’ UEFI uses the GUID Partition Table (GPT)
[2] Loading of the Boot loader (GRUB2)
The BIOS or UEFI has now run the POST to check the machine's status. The BIOS then searches the MBR (Master Boot Record) for information about the bootloader and disk partitioning.
The boot loader in a BIOS system is located in the first sector of the boot device; this is the MBR.
It occupies the first 512 bytes of disk space which is typically /dev/sda or /dev/hda depending on the architecture of your drive.
A UEFI system, on the other hand, stores all startup data in an.efi file. The file is located on the EFI System Partition, which also houses the boot loader.
It should be noted, however, that the MBR can sometimes be found on a Live USB or DVD installation of Linux.
The boot loader, in particular, is a small program that loads the operating system. The boot loader's primary function is to locate the kernel on the disk, insert it into memory, and execute it with the supplied options.
In Linux, there are four main types of bootloaders: LILO, SYSLINUX, GRUB, and GRUB2.
[+] LILO
LILO (Linux Loader) was once one of the most popular Linux boot loaders. However, it has fallen out of favor due to its lack of support for multi-boot environments and UEFI.
It also provides limited support for new filesystems.
LILO's developers officially ceased development and support in December 2015. As a result, the Linux Loader is outdated.
[+] SYSLINUX
Similarly, SYSLINUX is a boot loader for the Linux operating system that runs on a FAT filesystem, similar to that of a Windows system.
In a nutshell, its goal is to make the process of installing Linux for the first time as simple as possible.
Furthermore, SYSLINUX supports the following major filesystems:
β’ ext2
β’ ext3
β’ ext4
β’ FAT
With some limitations, SYSLINUX can also support the Btrfs and XFS filesystems.
[+] GRUB2
GRUB2 stands for GRand Unified Bootloader version 2, it is the most recent and primary bootloader in modern Linux distributions.
GRUB2 is a choice for many modern Linux distributions because of:
β’ the ability to boot several operating systems
β’ network-based diskless
β’ allows ease of use over a serial cable
β’ powerful command line interface for interactive configuration
β’ booting both a graphical and a text-based interface
GRUB2 has now replaced its predecessor (GRUB), which is now known as GRUB Legacy.
When the BIOS finds the grub2 bootloader, it executes it and loads it into the main memory (RAM).
You can do a few things with the grub2 menu. It lets you choose the Linux kernel version you want to use.
If you've upgraded your system a few times, you might notice that different kernel versions are listed.
It also allows you to edit some kernel parameters by pressing a combination of keyboard keys.
In addition, in a dual-boot setup with multiple OS installations, the grub menu allows you to choose which OS to boot into. The grub2 configuration file is located in /boot/grub2/grub2.cfg.
The primary goal of GRUB is to load the Linux kernel into main memory.
[3] Kernel Initialization
The operating system now controls access to our computer resources after passing through BIOS or UEFI, POST, and using a boot loader to start the kernel.
The Linux kernel follows a set procedure in this case:
β’ decompress itself from its compressed version before undertaking any task
β’ perform hardware checks
β’ gain access to vital peripheral hardware
β’ initializes the /sbin/init program, also known as init.
Init is always the first program to be executed and is assigned the process ID or PID of 1. Itβs the init process that spawns various daemons & mounts all partitions that are specified in the /etc/fstab file.
The kernel then mounts the initial RAM disk (initrd) which is a temporary root filesystem until the real root filesystem is mounted.
All kernels are located in the `/boot` directory together with the initial RAM disk image.
[4] Starting Systemd
Finally, the kernel loads Systemd, which replaces the old SysV init. Systemd is the mother of all Linux processes, managing tasks such as mounting file systems and starting and stopping services, to name a few.
The /etc/systemd/system/default.target file is used by Systemd to determine the state or target into which the Linux system should boot.
β’ The default target value for a desktop workstation (with a graphical user interface) is 5, which corresponds to run level 5 in the old SystemV init.
β’ The default target for a server is , which corresponds to run level 3 in SysV init.multi-user.target
The systemd targets are broken down as follows:
β’ (runlevel 0) - Poweroff or Shutdown the system.
Note, the run level in Linux represents the current state of the operating system. Run levels specify which system services are active. SysVinit previously identified run levels by number.
In Systemd, however,.target files have replaced run levels.
Run the following command to determine the current target on your system:
$ systemctl get-default
You can change targets by entering the following command into the terminal:
$ init runlevel-value
Init 3, for example, configures the system to be non-graphical.
The init 6 command reboots your system, while init 0 turns it off. When switching between these two targets, make sure to use the sudo command.
The boot process is complete when systemd loads all daemons and sets the target or run level value. At this point, you will be prompted for your username and password, after which you will gain access to your Linux system.
This information should be sufficient to help you understand the Linux booting process.
That's all! Thank you for getting this far. I hope you find this thread helpful.
If you found this thread valuable:
1. Toss us a follow for more daily threads on Linux, sysadmin, and DevOps β @sysxplore
2. Like and RT the first tweet so other Linux folks can find it too.
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
24+ Linux terminal shortcuts every power Linux user should know β π§΅
The Linux terminal interface may be difficult for a new Linux user to grasp, especially because it relies heavily on the arrow keys to move around. Furthermore, it can be tiresome to constantly retype the commands, each with a slight variation.
Bash, on the other hand, comes with a plethora of simple keyboard shortcuts and history functions to ensure efficient terminal use.
Git cherry-picking refers to the process of selecting individual commits from any branch and applying them to the current HEAD branch
Learn more in this guide:
Unlike git rebase and git merge, which involve taking all the commits in an entire branch, cherry-pick allows you to choose specific changes and apply them to another branch:
When You should use git cherry-pick
git cherry-pick is a handy tool but should be used sparingly, as it can result in duplicate commits.
24 Basic Git commands you will use 99% of the time as a sysadmin or DevOps engineer π β
1. git add
Used to add files to the staging area. Before a file is available to commit to a repository, the file needs to be added to the staging area also know as git index.
$ git add < file or directory>
To add all unstaged files use:
$ git add .
This allows you to prepare a snapshot before committing it to the official history.
As a Linux super user understanding the /etc/shadow file is very crucial for managing Linux users.
/etc/shadow is a plain text file that stores information about the passwords of the system's users. It has 640 permissions and is owned by user root and group shadow
This file is only readable by the root user, so you must be root or have root privileges to view its contents.
Any file viewer on Linux can be used to view the contents of this file, such as cat, more, less, etc. Alternatively, you can use the getent:
1. When a user types a URL () into a web browser, the browser first checks its local DNS cache and operating system cache for the IP address of .sysxplore.com sysxplore.com
2. If the IP address is not cached locally, the browser sends a DNS query to the user's Internet Service Provider's (ISP) recursive DNS server to resolve the domain name into an IP address.
Linux user management - how to add users in Linux π§΅β
The useradd command is the main tool for adding new users to a Linux system. This command allows you to quickly create a new user account and configure the user's $HOME directory structure.
The useradd command creates a user account by combining system default settings and command-line parameters.
To see the system default values on your Linux distribution, use the useradd command with the -D option: