First, the Linux boot process
1, firmware firmware (Cmos/bios) post power-on self-test
2. Bootloader bootloader (GRUB) loaded into kernel
3. Load kernel kernel drive hardware
4. Startup process Init
5. Read the execution configuration file/etc/inittab
A. Run from the default run level (Initdefault)
B. Execute script/etc/rc.d/rc.sysinit This script will run at any time when the system starts
C, execute script/ETC/RC.D/RC This script will determine the default boot level
d, perform corresponding operation level of/ETC/RC.D/RC[0123456].D start corresponding service
E, username password ...
Second, the Linux operating level
Default RunLevel. The runlevels used is:
# 0-halt (do not set Initdefault to this)
# 1-single User mode no graphical interface, only root can log in, similar to Windows security mode
# 2-multiuser, without NFS (the same as 3, if you don't have Networking) NFS (Network File system)
# 3-full Multiuser mode
# 4-unused does not use a runlevel that can be customized by the user
# 5-x11 system default Run level graphical multi-user level
# 6-reboot (do not set Initdefault to this) restart RunLevel
init [0123456] setting from what start level starts
Iii. Interpretation of Inittab documents
In Inittab, all entries take the following format
Id:runlevel:action:process
ID: identifier, typically two-bit letters or numbers
RunLevel: The specified run level, you can specify multiple
Action: Run state
Process: Specify the script/command to run
1. Introduction of key script files
/etc/rc.d/rc.sysinit This script as long as the system runs, it will run once, if there are any commands to be specified in the system, can be written at the end of the script
/ETC/RC.D/RC[0123456].D This is a directory that corresponds to the service to start and stop at each operating level
Example: S nfslock
S Start Service
K Kill stop Service (case sensitive)
14 followed by numbers indicates the priority of the run
Nfsclock the following letter sequence indicates the name of the run script
/etc/rc.d/init.d This directory contains the startup service that you installed when you installed the Linux system, which is started or shut down separately via the sshd command.
set up self-launcher: When we write a script file that wants to run at a certain runlevel, we can use a soft connection to link the script file to the/ETC/RC.D/RC[012345].D directory and rename it as:msg.script-> S100msg.script
Cases:
Ln-s/etc/rc.d/init.d/msg.script/etc/rc.d/rc3.d/s100msg.script
2. Some values of action
| Behavior |
Describe |
| Respawn |
Once the process command specified in item 4th is aborted, rerun the command. |
| Wait |
Executes the process specified in item 4th, and then runs other commands when it finishes. Blocking |
| Once |
Executes the 4th specified process without waiting for it to complete and continues running other commands. |
| Boot |
The 4th specified process is run at system startup regardless of the execution level. |
| Bootwait |
Regardless of the level of execution, the system starts with the 4th specified process and waits until it is complete. |
| Off |
Closing any action is equivalent to ignoring the configuration line. |
| OnDemand |
When entering the OnDemand execution level, the process specified in item 4th is executed. |
| Initdefault |
The level of execution entered after the system starts, and the row does not need to specify process. |
| Sysinit |
Regardless of the execution level, the system executes the 4th specified process before the boot and bootwait are executed. |
| Powerwait |
Executes the 4th specified process when the system is running out of power, and waits until it finishes. |
| Powerokwait |
When the power supply of the system returns to normal, it executes the process specified in item 4th and waits for it to execute. |
| Powerfailnow |
Executes the process specified in item 4th when the system's power supply is severely inadequate. |
| Powerfail |
When a power error occurs, the process command specified in item 4th is executed without waiting for it to end. |
| Ctrlaltdel |
The process specified by item 4th is executed when the user presses "Ctrl+alt+del". |
| Kbrequest |
This key combination is defined in the Keymaps file when the user presses a special key combination to execute the process specified in item 4th. |
Iv. relationship of the parent-child process
1. The parent process terminates before the child process:
This situation is the orphan process we used earlier. When the parent process exits first, the system causes the INIT process to take over the child process.
2. The child process terminates before the parent process, and the parent process does not call the wait or Waitpid function
In this case, the child process goes into a zombie state and will persist until the system restarts. When a child process is in a zombie state, the kernel only saves some of the necessary information for the process in case the parent process needs it. At this point the child process always occupies resources and reduces the maximum number of processes that the system can create.
Zombie State : A process that has been terminated, but its parent process has not yet processed it (getting information about terminating the child process, releasing the resources it still occupies) is called the Zombie process (zombie). The PS command prints the status of the zombie process to Z.
3, the child process terminates before the parent process, and the parent process calls the wait or Waitpid function
At this point the parent process waits for the child process to end.
The configuration and application of self-lifting program Grup
Boot process for Linux one