search
HomeSystem TutorialLINUXAnalyze the boot process of Linux system startup

Analyze the boot process of Linux system startup

Feb 13, 2024 am 11:18 AM
linuxlinux tutoriallinux systemlinux commandshell scriptSystem installationembeddedlinuxGetting started with linuxlinux learning

Linux system is a widely used open source operating system with powerful functions and flexible configuration. However, have you ever thought about how the Linux system gradually starts up from darkness when you press the power button? The boot process of Linux system startup is a complex and delicate process, which involves multiple levels and components such as hardware, firmware, boot loader, kernel and user space. This article will analyze in detail the boot process of Linux system startup, including BIOS, MBR, GRUB, initrd, init, etc.

The following takes CentOS5.5 version as an example to introduce the boot process of LINUX. The specific process is as follows:

Analyze the boot process of Linux system startup

The following is a detailed introduction to each step:

1) The first step is firmware self-test, which mainly performs CMOS/BIOS POST power-on self-test on the hardware to check whether the hardware is normal at the physical level. For example, check whether the hard disk is plugged in properly, etc.
2) The second step is to read the BootLoader of the MBR in the hard disk and the self-starting program. The commonly used self-starting program under Linux is GRUB. The main function of this step is to load the kernel. The kernel is stored in the /boot directory
3) The third step is the process of loading the kernel Kernel,
The main functions are: 1. Drive hardware. Kernel contains a large number of drivers. 2. Start the init process.
4) The init process mainly reads the /etc/inittab file and executes the default run level to continue booting. It should be noted that the PID of init is always 1, which is the parent process of all processes, while the background process of init process is 0, which is the kernel scheduler.
5)/etc/inittab defines initialization operations.
Analyze the boot process of Linux system startup

The main format of the command is: id: runlevels: action: process
Among them, as shown in the red box in the above picture
1. There are 7 run-levels, 0-6 are as follows:
0 —— halt shutdown
1 ——Single user mode Single user mode
2 - Multiuser, withoutNFS multi-user mode without network (text mode)
3——Full multiuser mode Full-featured multi-user mode (text mode)
4——unused reserved
5 ——X11 graphical multi-user mode
6——reboot
You can switch according to these 7 running levels
The commands are: view the current running level #runlevel, switch the running level #init[0 |1 |2 |3 |4 |5 |6]

2. There are also several important values ​​in acion:

1 initdefault: Specify the default startup run level of the system, as marked in the above figure, usually used for repair. For example, if we want to enter single-user mode, we can set it to 1. The default cannot be set to 0 or 6. Otherwise it cannot be started.

2sysinit: The system starts executing the command specified in the process
Analyze the boot process of Linux system startup

It can be seen from the content of the inittab file that there is no run level set, which means that no matter which run level it is, /etc/rc.d/rc.sysinit will be executed

6) initdefault, as mentioned in the fifth step, mainly reads the information in /etc/inittab to determine what the default running level is.
7)/etc/rc.d/rc.sysinit
Run to line 21 in the inittab file to start the script. Complete the startup of the system service program, such as setting system environment variables, setting the system clock, loading fonts, checking the loaded file system, generating system startup information log files, etc. Because it is a basic service, its run-level is set to empty: that is, any level, and the action is set to sysinit. That is, the script must be started at any run level to complete the startup of the basic service
8) After the basic service is started, the script /etc/rc.d/rc will be executed
After loading the basic service, you need to start the corresponding directory according to different running levels. Its working principle is to first determine the default running level of the system, which is what is in step 6, and then execute the corresponding rcN. The service startup script in the d directory is as shown
Analyze the boot process of Linux system startup

9) Execute the service startup script in the /etc/rc.d/rcN.d directory

Look at the contents of this directory:
Analyze the boot process of Linux system startup

where S represents the script to be started and K represents the script to be closed
The numbers indicate the startup sequence, with smaller values ​​given priority. Mainly for the management of some services
In this step, you need to explain the directory /etc/rc.d/init.d. The scripts placed in this directory are real scripts, while the scripts placed in rcN.d are soft links in the init.d directory. In other words, all files in rcN.d will eventually need to find the real script in init.d
Take a look at the specific details:
Analyze the boot process of Linux system startup

Analyze the boot process of Linux system startup

After executing this step, the interface will prompt you to enter the user name and password, which means that the system has started. The process of entering the user name and password will be discussed later. This time the boot process is over

The last thing to note is that the idea of ​​​​the LINUX boot process is roughly the same, but the details are different due to version issues, in the name or location of the configuration file. This time I used the CentOS version, and the Ubuntu version There is no inittab file and grup.conf file, so if you are interested, you can follow this idea to explore.

PS: About GRUB

GNU GRUB ("GRUB" for short) is a bootloader from the GNU project. GRUB is an implementation of the multi-boot specification, which allows users to have multiple operating systems in the computer at the same time and select the operating system they want to run when the computer starts. GRUB can be used to select different kernels on an operating system partition and can also be used to pass boot parameters to these kernels.

The predecessor of GNU GRUB is Grand Unified Bootloader. It is mainly used in Unix-like systems; like most Linux distributions, GNU systems also use GNU GRUB as its launcher. Starting from version 10 1/06, Solaris also uses GNU GRUB as the launcher on x86 systems.

GRUB is dynamically configurable; it loads configuration information at startup and allows modification at startup, such as selecting a different kernel and initrd. For this purpose, GRUB provides a simple Bash-like command line interface, which allows users to write new startup sequences.

GRUB is very lightweight. It supports a variety of executable formats; in addition to being applicable to operating systems that support multi-boot, it also supports operating systems such as Windows and OS/2 that do not support multi-boot through the chain boot function. GRUB supports all Unix file systems, as well as FAT and NTFS file systems for Windows, and also supports LBA mode. GRUB allows users to view the contents of files in the file systems it supports.

GRUB has a variety of user interfaces. Most Linux distributions take advantage of GRUB's support for graphical interfaces to provide customized boot menus with background patterns, and sometimes also support mouse. By setting the GRUB text interface, remote terminal startup can be achieved through the serial port.

GRUB can download operating system images from the network, so it can support diskless systems. GRUB supports decompressing the image of the operating system before booting it.

Unlike other launchers, GRUB can interact directly with users through the GRUB prompt. Before loading the operating system, type the c key in the GRUB text mode screen to enter the GRUB command line. On systems without an operating system or with an operating system but no "menu.lst" file, you can also enter the GRUB prompt. The GRUB prompt allows users to manually boot any operating system through bash-like commands. Record the appropriate commands in the "menu.lst" file to automatically start an operating system.

GRUB has a rich set of terminal commands. Using these commands from the command line, users can view the details of hard disk partitions, modify partition settings, temporarily remap the disk order, boot from any user-defined configuration file, and view what GRUB supports. Configuration of other launchers on the file system. Therefore, it is possible to boot an operating system from an external device without knowing what is installed on a computer.

GRUB uses a scrolling screen to select the operating system you want to start. By adding relevant information to the "menu.lst" file, GRUB can control 150 or more startup options, which can be selected with the arrow keys at startup.

With chain startup, one starter can start another starter. GRUB can be started from DOS, Windows, Linux, BSD and Solaris systems with 2 to 3 lines of commands.

Although GRUB is compiled and packaged for Unix-like systems, there is also GRUB for DOS and Windows. GRUB can also be installed as an isolated system without any operating system. Using GRUB requires 1 file when booting from a CD, and 2 files when booting from a floppy disk, hard disk, and USB device. These files can be found on any Linux CD that supports GRUB, and users can easily find them.

This article analyzes in detail the boot process of Linux system startup, including BIOS, MBR, GRUB, initrd, init, etc. By understanding and mastering this knowledge, we can better understand the inner workings of the Linux system, and thus better use and optimize the Linux system. Of course, there are many details and changes in the boot process of Linux system startup, which require us to continue to learn and explore.

The above is the detailed content of Analyze the boot process of Linux system startup. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
Top 5 Linux Tools for Monitoring Disk I/O PerformanceTop 5 Linux Tools for Monitoring Disk I/O PerformanceApr 27, 2025 pm 04:45 PM

This guide explores essential Linux tools for monitoring and troubleshooting disk I/O performance, a crucial metric impacting server speed and application responsiveness. Disk I/O performance directly affects how quickly data is read from and written

4 Ways to Find Plugged USB Device Name in Linux4 Ways to Find Plugged USB Device Name in LinuxApr 27, 2025 pm 04:44 PM

For new Linux users, identifying connected devices is crucial, especially USB drives. This guide provides several command-line methods to determine a USB device's name, essential for tasks like formatting. While USB drives often auto-mount (e.g., /

How to Fix 'No Space Left on Device” on Root (/) PartitionHow to Fix 'No Space Left on Device” on Root (/) PartitionApr 27, 2025 pm 04:43 PM

One of the most common problems with Linux systems, especially those with limited disk space, is the exhaustion of root partition (/) space. When this problem occurs, you may encounter the following error: No space left on device Don’t panic! This just means that your root directory (/partition) is full, which is a common problem, especially on systems with limited disk space or servers running 24/7. When this happens, you may encounter the following problems: The package cannot be installed or upgraded. System startup failed. The service cannot be started. Unable to write to logs or temporary files. This article walks you through practical steps to identify problems, clean up space safely, and prevent them from happening again. These instructions are suitable for beginners

Top 16 Notepad   Replacements for Linux in 2025Top 16 Notepad Replacements for Linux in 2025Apr 27, 2025 pm 04:42 PM

This article explores top-notch Notepad alternatives for Linux users. Notepad , while excellent on Windows, lacks a Linux version. This guide offers a diverse range of options to suit various needs and preferences. Top Notepad Alternatives for

How to Create and Run New Service Units in SystemdHow to Create and Run New Service Units in SystemdApr 27, 2025 pm 04:41 PM

Several days ago, I encountered a 32-bit CentOS 8 distribution and decided to test it on an older 32-bit system. Post-boot, I discovered a network connectivity issue; the connection would drop, requiring manual restoration after each reboot. This pr

How to Check for Bad Sectors on a Hard Disk in LinuxHow to Check for Bad Sectors on a Hard Disk in LinuxApr 27, 2025 pm 04:40 PM

Let's clarify what constitutes a bad sector or bad block: it's a portion of a hard drive or flash memory that's become unreadable or unwritable, typically due to physical damage to the disk surface or malfunctioning flash memory transistors. Accumul

How to Force cp Command to Overwrite Files Without PromptHow to Force cp Command to Overwrite Files Without PromptApr 27, 2025 pm 04:39 PM

The cp command, short for "copy," is a fundamental tool in Linux and other Unix-like systems for duplicating files and directories. While efficient for local file transfers, for network-based copies, scp (secure copy) is preferred due to i

Fix 'rm: Cannot Remove File – Device or Resource Busy” ErrorFix 'rm: Cannot Remove File – Device or Resource Busy” ErrorApr 27, 2025 pm 04:38 PM

When using the rm command to delete a file or directory in Linux system, if you encounter the following error: rm: cannot remove 'file-or-directory': Device or resource busy Don't worry, this is a common problem, which means that the file or directory you are trying to delete is currently being used by the system or running process. Cause of error The "Device or Resource Busy" message indicates that the file or directory is in use. To avoid damaging the system or causing data loss, Linux prevents deleting files in use. Common reasons include: Your terminal is currently in the directory you want to delete. The program or process is using the file or directory.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software