Wu Yuxiong - natural born Linux operating system: Linux system boot process

We will see a lot of information to start linux boot.
Linux system boot process is not as complicated as we imagined, the process can be divided into five stages:
The kernel boot.
Run init.
system initialization.
Establishment of the terminal.
User login system.

Type init program:
SysV: init, before CentOS 5, the configuration file: / etc / inittab.
Upstart: the init, CentOS 6, the configuration file: / etc / inittab, / etc / the init / * .conf.
Systemd: systemd, the CentOS . 7, the configuration file: / usr / lib / systemd / system, / etc / systemd / system.
Kernel boot
When the computer is powered on, first the BIOS POST, the BIOS boot device in accordance with the set (typically a hard disk) to start.
After the operating system to take over the hardware, first read the kernel files in the / boot directory.

Run init
The init process is the starting point of all processes of the system, you can compare it to our ancestors all processes of the system, not the process, the system will not start any process.

The first is the need to init program reads the configuration file / etc / inittab.

Run Level
Many programs require start-up. They are called the Windows " Service " (Service), in Linux called " daemon " (daemon).
A major task of the init process, is to run these programs in the boot.
However, different situations need to launch different programs, such as when used as a server, you need to start Apache, you do not need to use as a desktop.
Linux allows for different occasions, assign different boot program, which is called " operational level " (runlevel). That is, the boot according to " run level " to determine which program to run.

Linux system has seven operational level (runlevel):
Run Level 0: system shutdown, the system can not be set by default to run level 0, or can not start properly
Run Level 1: single-user work status, root permission for system maintenance, prohibits remote login
Run level 2: multi-user state (not NFS)
Run Level 3: Full multi-user state (there are NFS), after landing into the console command line mode
Run Level 4: The system is not used, reserved
Run Level 5: X11 console After you log in GUI mode graphics
Run level 6: a normal system shutdown and restart, the default operating level can not be set to 6, or can not start properly
system initialization
Such a line in the init configuration file: Si :: the sysinit: /etc/rc.d/rc.sysinit it calls performed /etc/rc.d/ rc.sysinit, and rc.sysinit is a bash shell script it is the completion of a number of system initialization work, rc.sysinit is important to run a script every level should be run first.
It is mainly the work: activate the swap partition, check the disk, load the hardware module and a number of other priority tasks.

l5:5:wait:/etc/rc.d/rc 5

This line of argument is expressed in 5 runs /etc/rc.d/rc,/etc/rc.d/rc Shell is a script that takes 5 as a parameter to perform /etc/rc.d/rc5.d/ directory All rc script at startup, / etc / rc.d / rc5.d / directory of the startup scripts are actually some of the connection file, rather than true rc startup script, real rc startup scripts are in fact on /etc/rc.d/init.d/ directory.

These rc startup scripts have similar usage, they are generally able to accept start, stop, restart, status and other parameters.

/etc/rc.d/rc5.d/ the rc startup script is usually the beginning of the S K or connection file for the script to start, will start at the beginning of S parameters to run.
If the script is found there is a corresponding connection starts with K, and has been in the operating mode (in / var / lock / subsys / file as a flag), the first stop to stop these parameters has started guardian process, and then re-run.
This is done to ensure that when init to change run levels, all the daemons will be restarted.
As for what daemon running in a run each level, users can chkconfig or setup in the " System Services " from the line set.

Establishment of the terminal
Rc has finished, return to init. Then the basic system environment has been set up, all kinds of daemons have been started.
init will open next six terminals, so that the user login system. The following 6 line is defined in inittab six terminals:

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

As can be seen from the above in 2, 3 and 4 run level 5 are mingetty program will run respawn, mingetty program can open the terminal, setting mode.
At the same time it will display a text login screen, the interface is what we often see the login screen, in the login screen will prompt the user to enter a user name, and the user will be entered by the user as a parameter to the login program to verify the user's identity.
User login system
In general, users log in three ways:

( 1 ) Command Line Login
( 2 ) SSH login
( 3) Graphical login

For graphical user run level 5, their log in through a graphical login screen. After a successful login can go directly to KDE, Gnome and other window manager.
The paper stresses the situation or text login: When we see mingetty login screen, we can enter a user name and password to log in the system.
Linux account verification process is login, login will receive a user name mingetty came as the username parameter.
Then login user name will be analyzed: If the username is not root, and there is / etc / nologin file, login nologin will output the contents of the file, and then exit.
This prevents non-root user login time is usually used for system maintenance. Only / / etc registered in the securetty terminal only allow the root user login, if the file does not exist, the root user can log on any terminal.
/ etc / usertty file is used to make additional access restrictions on users, if the file does not exist, there are no other restrictions.
Graphics and text mode mode switching manner
Linux provides six preset command terminal window Let's login.
The default is the first sign in our window, that is tty1, the six windows were tty1, tty2 ... tty6, you can press Ctrl + Alt + F1 ~ F6 to switch between them.
If you install a graphical interface, the default is to enter the graphical interface, in which case you can press Ctrl + Alt + F1 ~ F6 to enter one of the commands window interface.
When you enter the command window interface and then return to the graphical interface, just press Ctrl + Alt + F7 on the back.
If you use vmware virtual machine, the command shortcut key to switch to the window Alt + Space + F1 ~ F6. If you press Alt + Shift + Ctrl + F1 ~ F6 to switch in a graphical interface to the command window.

Linux shutdown
Linux in the field mostly used in servers, rarely encountered in the operation shut down. After all, running a service on the server is never-ending, except under special circumstances, it will be forced to shut down.

Proper shutdown procedure is: Sync > the shutdown> reboot> the HALT

Shutdown command is: shutdown, you can look at the man shutdown help documentation.

For example, you can run the following command shutdown:

The sync data from the synchronous memory to the hard disk.

shutdown shutdown command, you can look at the man shutdown help documentation. For example, you can run the following command shutdown:

-h the shutdown 10 'This Server by Will the After the shutdown 10 mins' This tells you that the computer will shut down after 10 minutes, and will appear in the user's current login screen.

shutdown -h now shutdown immediately
-h the shutdown 20:25 the system will shut down at 20:25 today
-h the shutdown +10 ten minutes after shutdown
shutdown -r now reboot the system immediately
-r the shutdown +10 system reboot after ten minutes
reboot reboot is equivalent to shutdown -r now
halt off the system, and is equivalent to the shutdown -h now poweroff
Whether restart the system or turn off the system, we must first run the sync command, the data in memory is written to disk.
Shutdown command has command shutdown -h now halt poweroff and init 0, reboot the system -r now reboot the init have the shutdown 6.

 

Guess you like

Origin www.cnblogs.com/tszr/p/12107393.html