Home >Operation and Maintenance >Linux Operation and Maintenance >What are the stages of the Linux system startup process?
Five stages of the system startup process: 1. Kernel boot stage; when the computer is turned on, the first is the BIOS power-on self-test. According to the startup device (usually the hard disk) set in the BIOS ) to start. During the system startup phase, the init process runs as the starting point for all processes. Without this process, no process in the system can start. 3. System initialization phase; call rc to complete some system initialization work. 4. Establish the terminal stage. 5. User logs into the system.
The startup process of the Linux system is not as complicated as everyone thinks. The process can be divided into 5 stages:
(1) Kernel boot.
(2) Run init.
(3) System initialization.
(4) Create a terminal.
(5) User logs in to the system.
1. Kernel boot
After the computer is turned on, it will first perform a BIOS power-on self-test, and then proceed according to the preset boot device (usually a hard disk) in the BIOS. to start. When the operating system takes control of the hardware, its first task is to load the core files in the /boot directory.
2. Run init
(1) The init process is the starting point of all processes in the system. You can compare it to the system The ancestor of all processes, without this process, no process in the system will start. The init program needs to read the configuration file /etc/inittab first.
(2) Run level: Many programs need to be started at boot. They are called "services" in Windows and "daemons" in Linux.
A major task of the init process is to run these programs that are started at boot. On different occasions, specific programs need to be started. For example, when used as a server, Apache needs to be started, but when used as a desktop, it is not required.
Linux allows different boot programs to be allocated for different occasions, which is called "runlevel". In other words, the runlevel determines which programs need to be run at startup.
(3) The Linux system has 7 runlevels (runlevel):
Runlevel 0: System shutdown state, system The default run level cannot be set to 0, otherwise it will not start normally.
Run level 1: single-user working state, root authority, used for system maintenance, remote login is prohibited
Run level 2: Multi-user state (without NFS)
Run level 3: Complete multi-user state (with NFS), enter the console command line after logging in Mode
Run level 4: The system is not used, reserved
Run level 5: X11 console, enter the graphical GUI mode after logging in
Run level 6: The system shuts down and restarts normally. The default run level cannot be set to 6, otherwise it cannot start normally.
3. System Initialization
There is such a line in the init configuration file: si::sysinit:/etc/rc.d/rc.sysinit It calls and executes /etc/rc.d/rc.sysinit. rc.sysinit is a bash shell script, which mainly completes some system initialization work. rc.sysinit is an important script that must be run first at every run level.
The main tasks it completes are: activating the swap partition, checking the disk, loading hardware modules and other tasks that need to be performed first.
4. Establish a terminal:
After rc is executed, return to init. At this time, the basic system environment has been set up and various daemon processes have been started. init will then open 6 terminals so that users can log in to the system.
5. User login system:
3 types: command line login, ssh login, graphical interface login
1. The correct shutdown process is: sync > shutdown > reboot > halt
2. The shutdown command is: shutdown, you can take a look at man shutdown Help documentation.
3. Example:
<code>sync # 将数据由内存同步到硬盘中。<br/><br/>shutdown –h 10 ‘This server will shutdown after 10 mins’ <br/>#这个命令告诉大家,计算机将在10分钟后关机,并且会显示在登陆用户的当前屏幕中。<br/><br/>shutdown –h now # 立马关机<br/>shutdown –h 20:25 # 系统会在今天20:25关机<br/>shutdown –h +10 # 十分钟后关机<br/>shutdown –r now #系统立马重启<br/>shutdown –r +10 #系统十分钟后重启<br/>reboot # 就是重启,等同于 shutdown –r now<br/><br/>halt # 关闭系统,等同于shutdown –h now 和 poweroff<br/></code>
4. Whether you restart the system or shut down the system, you must first run the sync command to write the data in the memory to the disk.
The commands for shutting down include shutdown –h now, halt, poweroff and init 0, and the commands for restarting the system include shutdown –r now, reboot and init 6.
5. Shutdown will schedule a time for the system to shut down. It can be used to stop, shut down, and restart the machine.
shutdown -p now # 关闭机器 shutdown -H now # 停止机器 shutdown -r 09:35 # 在 09:35am 重启机器
To cancel an upcoming shutdown, just enter the following command:
shutdown -c
使用 halt 命令能够让 CPU 停止运行,但仍然保持通电状态。你可以用它使系统处于低层维护状态。注意在有些情况会它会完全关闭系统。
# halt ### 停止机器 # halt -p ### 关闭机器、关闭电源 # halt --reboot ### 重启机器
poweroff 会发送一个 ACPI 信号来通知系统关机。
# poweroff ### 关闭机器、关闭电源 # poweroff --halt ### 停止机器 # poweroff --reboot ### 重启机器
reboot 命令 reboot 通知系统重启。
# reboot ### 重启机器 # reboot --halt ### 停止机器 # reboot -p ### 关闭机器
The above is the detailed content of What are the stages of the Linux system startup process?. For more information, please follow other related articles on the PHP Chinese website!