In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "the analysis of the startup process of Linux system after boot". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The startup process of Linux is actually very similar to that of windows, but we cannot see the startup information for windows. When linux starts, we will see a lot of startup information, such as whether a service is started or not.
Generally speaking, the startup process of Linux system can be divided into five parts: kernel boot; running init; system initialization; establishing terminal; user login system.
A kernel boot
When the computer is powered on, the first is the BIOS post, which starts according to the boot device (usually the hard drive) set up in BIOS. Then the grub program on the boot device starts to boot the linux. When the bootstrap successfully completes the boot task, the Linux takes over the control of the CPU from them, and then the CPU starts to execute the core image code of the Linux and starts the Linux startup process. That is, the so-called kernel boot starts, in fact, the kernel boot process is very complicated, we just regard it as a black box, anyway, the linux kernel does some work, and finally the kernel calls load the init program, and the kernel boot work is completed. To the next protagonist, init.
B run init
The init process is the starting point of all processes in the system. You can compare it to the ancestors of all processes in the system. Without this process, no process in the system will start. The init program first needs to read the configuration file / etc/inittab. Inittab is a non-executable text file that consists of several lines of instructions. The details are as follows: (you can get it by executing the command cat / etc/inittab on your linux)
The code is as follows:
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0-halt (Do NOT set initdefault to this)
# 1-Single user mode
# 2-Multiuser, without NFS (The same as 3, if you do not havenetworking)
# 3-Full multiuser mode
# 4-unused
# 5-X11
# 6-reboot (Do NOT set initdefault to this)
#
# indicates that the default runlevel is 5 (initdefault)
Id:5:initdefault:
# automatically execute / etc/rc.d/rc.sysinit script (sysinit) at startup
# System initialization.
Si::sysinit:/etc/rc.d/rc.sysinit
L0:0:wait:/etc/rc.d/rc 0
L1:1:wait:/etc/rc.d/rc 1
L2:2:wait:/etc/rc.d/rc 2
L3:3:wait:/etc/rc.d/rc 3
L4:4:wait:/etc/rc.d/rc 4
# when the run level is 5, run the / etc/rc.d/rc script with 5 as the parameter, and init will wait for it to return (wait)
L5:5:wait:/etc/rc.d/rc 5
L6:6:wait:/etc/rc.d/rc 6
# restart the system by pressing CTRL-ALT-DELETE during startup
# Trap CTRL-ALT-DELETE
Ca::ctrlaltdel:/sbin/shutdown-T3-r now
# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
Pf::powerfail:/sbin/shutdown-f-h + 2 "Power Failure; System Shutting Down"
# If power was restored before the shutdown kicked in, cancel it.
Pr:12345:powerokwait:/sbin/shutdown-c "Power Restored; Shutdown Cancelled"
# execute / sbin/mingetty program with ttyX as parameter at levels 2, 3, 4 and 5, and open ttyX terminal for user login
# if the process exits, run the mingetty program (respawn) again
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
# run the xdm program at level 5, provide a xdm graphical login interface, and re-execute (respawn) when you exit
# Run xdm in runlevel 5
X:5:respawn:/etc/X11/prefdm-nodaemon
Take the above inittab file as an example to illustrate the format of inittab. The line that begins with # is a comment line, and except for the comment line, each line has the following format:
The code is as follows:
Id:runlevel:action:process
The above items are explained in detail as follows:
1. Id
Id refers to the entry identifier, which is a string. For other login program items such as getty or mingetty, id is required to have the same number as tty, otherwise the getty program will not work properly.
2. Runlevel
Runlevel is the identification of the running level at which init is located, generally using 0Mel 6 and S or S. The 0, 1, and 6 run levels are retained by the system: 0 as a shutdown action, 1 as a restart to single-user mode, 6 as a restart; S and s have the same meaning, indicating single-user mode, and do not require inittab files, so they do not appear in inittab. In fact, when entering single-user mode, init runs / sbin/sulogin directly on the console (/ dev/console). In the general system implementation, levels 2, 3, 4 and 5 are used. In CentOS system, 2 represents multi-user mode without NFS support, 3 represents complete multi-user mode (which is also the most commonly used level), 4 is reserved for user customization, and 5 represents XDM graphical login mode. 7Mel 9 levels are also available, which are not defined in traditional Unix systems. Runlevel can be multiple values juxtaposed to match multiple runlevels, and for most action, it is executed only if the runlevel matches the current runlevel successfully.
3. Action
Action describes how the subsequent process operates. The desirable values for action include: initdefault, sysinit, boot, bootwait, etc.: initdefault is a special action value that identifies the default startup level; when init is activated by the core, it will read the initdefault entry in the inittab, get the runlevel, and use it as the current run level. If there is no inittab file, or if there is no initdefault entry in it, init will request input runlevel on the console. Action such as sysinit, boot, bootwait, etc., will run unconditionally at system startup, ignoring the runlevel in it. The rest of the action (excluding initdefault) is related to a runlevel. The definition of each action is described in detail in inittab's man manual.
4. Process
Process is the specific execution program. The program can be followed by parameters.
Tips: if you can't read this file, it doesn't matter. With your in-depth understanding of linux, you will suddenly become enlightened when you look back at this file. But now you have to understand the meaning of all levels of runlevel.
C system initialization
There is a line in the configuration file of init: si::sysinit:/etc/rc.d/rc.sysinit calls to execute / etc/rc.d/rc.sysinit, while rc.sysinit is a script for bash shell, which mainly does some system initialization, and rc.sysinit is an important script to run first at every run level. Its main tasks are: activating swap partitions, checking disks, loading hardware modules, and other priority tasks.
Rc.sysinit has more than 850 lines, but each single function is relatively simple and annotated. It is recommended that interested users can read the file on their own machines to learn more about the initialization of the system. Because this file is long, it is not listed in this article, nor is it introduced in detail. When the rc.sysinit program is finished, it will return to init to continue to the next step. Usually the / etc/rc.d/rc program is executed next. Taking runlevel 3 as an example, init executes the following line in the configuration file inittab:
L5:5:wait:/etc/rc.d/rc 5
This line indicates that running / etc/rc.d/rc,/etc/rc.d/rc with a parameter of 5 is a Shell script that takes 5 as a parameter to execute all the rc startup scripts in the / etc/rc.d/rc5.d/ directory. The startup scripts in the / etc/rc.d/rc5.d/ directory are actually connection files, not real rc startup scripts. The real rc startup scripts are actually placed in the / etc/rc.d/init.d/ directory. These rc startup scripts have a similar usage, they generally accept parameters such as start, stop, restart, status, and so on.
The rc startup script in / etc/rc.d/rc5.d/ is usually a connection file that begins with K or S, and for startup scripts that begin with S, it will be run with the start parameter. If you find that there is a corresponding script that also has a K-start connection, and it is already running (marked by the file under / var/lock/subsys/), you will first stop these started daemons with stop as the parameter, and then run them again. This is done to ensure that all related daemons will restart when init changes the run level.
As to which daemons will run in each runlevel, users can set their own through the "System Services" in chkconfig or setup.
D establish terminal
When the execution of rc is finished, return init. At this point, the basic system environment has been set up, and various daemons have been started. Init then opens six terminals so that users can log in to the system. The following six lines in inittab define six terminals:
The code is as follows:
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
From the above, we can see that the mingetty program will be run in respawn mode in the run levels of 2, 3, 4 and 5, and the mingetty program can open the terminal and set the mode. At the same time, it will display a text login interface, which is the login interface we often see, in which the user will be prompted for a user name, and the user entered by the user will be passed as a parameter to the login program for verification.
Verify the identity of the user.
E user logs in to the system
For graphical users running level 5, their login is through a graphical login interface. After logging in successfully, you can go directly to KDE, Gnome and other window managers. This article is mainly about text login: when we see the login interface of mingetty, we can enter the user name and password to log in to the system.
Linux's account verifier is that login,login accepts the user name from mingetty as the user name parameter. Login then analyzes the user name: if the user name is not root and the / etc/nologin file exists, login will output the contents of the nologin file and exit. This is usually used to prevent non-root users from logging in during system maintenance. Only terminals registered in / etc/securetty allow root users to log in, and if this file does not exist, root can log in on any terminal. The / etc/usertty file is used to impose additional access restrictions on users, and if this file does not exist, there are no other restrictions.
After analyzing the user name, login will search / etc/passwd and / etc/shadow to verify the password and other information about the account, such as what the home directory is and what shell to use. If no home directory is specified, it defaults to the root directory; if no shell is specified, it defaults to / bin/bash.
After the login program succeeds, it outputs the last login information (recorded in / var/log/lastlog) to the corresponding terminal, and checks whether the user has any new mail (under the corresponding user name directory of / usr/spool/mail/). Then start setting various environment variables: for bash, the system first looks for the / etc/profile script file and executes it Then, if the .bash _ profile file exists in the user's home directory, it is executed, and other configuration files may be called in these files. After all the configuration files are executed, various environment variables are also set, and the familiar command line prompt appears, and the whole startup process is over.
This is the end of the content of "Analysis of the startup process of Linux system after boot". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.