Latest web development tutorials

Linux system boot process

When linux starts we'll start seeing a lot of information.

Linux system boot process is not as complicated as we imagined, the process can be divided into five stages:

  • Kernel boot.
  • Run init.
  • system initialization.
  • Establishment of the terminal.
  • User login system.

Kernel boot

When the computer is turned on the power, first of BIOS POST, the BIOS settings according to the boot device (typically a hard disk) to start.

After the operating system to take over the hardware, first read the kernel file / boot directory.

bg2013081702

Run init

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

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

bg2013081703

Run Level

Many programs require start-up. These are called "service" (service) in Windows, in Linux is called "daemon" (daemon).

A big task init process is to run the boot program.

However, different situations need to launch different programs, such as when used as a server, you need to start Apache, as the desktop is not required.

Linux allows for different occasions, assign different start-up program, which is called "runlevel" (runlevel). That is, when activated according to "run level" to determine which program you want to run.

bg2013081704

Linux system has seven levels run (runlevel):

  • Run Level 0: system shutdown, the system default run level can not be set to 0, or can not properly start
  • Run Level 1: single-user operating state, root privileges for system maintenance, remote access is prohibited
  • Run level 2: multi-user state (not NFS)
  • Run Level 3: Full multi-user state (with NFS), after landing into the console command line mode
  • Run Level 4: The system does not use, retention
  • Run level 5: X11 console, login into the graphical GUI mode
  • Run level 6: a normal system shutdown and restart, the default run level 6 is not set, or can not properly start

system initialization

Such a line in the init configuration file: si :: sysinit: /etc/rc.d/rc.sysinit it calls executed /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 must be run first.

It is mainly the work are: activate the swap partition, check the disk, load the hardware modules and other priority tasks.

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

This line represents the parameters to run /etc/rc.d/rc,/etc/rc.d/rc 5 is a Shell script that accepts 5 as a parameter to perform /etc/rc.d/rc5.d/ directory All rc startup script under, / etc / rc.d / rc5.d / directory these startup scripts are actually some of the connection file, rather than a real rc startup script, real rc startup scripts are in fact /etc/rc.d/init.d/ placed under the directory.

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

The /etc/rc.d/rc5.d/ rc startup script usually K or attached document S at the beginning, for in order to start the script, will start at the beginning of the parameter S to run.

And if we find the corresponding script exists there K starts connection, and has been in the running state of the (file / var / lock / subsys / under as a symbol), then the first stop is to stop these parameters has launched guardian process, and then re-run.

This is done to ensure that when init changes levels, all the daemons are restarted.

As for what daemon runs in each class in, users can chkconfig or setup in "System Services" from the line set.

bg2013081705

Establishment of the terminal

Rc has finished, return to init. Then the basic system environment has been set up, various daemons have started.

init will open next six terminals, so that the user login system. Inittab in the following six lines that define 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

From the above it can be seen in the run levels 2,3,4,5 are run mingetty program will 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 prompts 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, the user's login in three ways:

  • (1) command line login
  • (2) ssh login
  • (3) Graphical login
bg2013081706

For graphical user run level 5, they log on through a graphical login screen. After successful login can go directly to KDE, Gnome and other window manager.

The article is mainly about the case or text login: When we see mingetty login screen, we can enter a user name and password to log in to the system.

Linux account verification process is login, login receives mingetty came username as the username parameter.

Then login user name will be analyzed: If the user name is not the root, and there is / etc / nologin file, the output nologin login file, then exit.

This prevents non-root user is usually used for system maintenance. Only the / etc / securetty registered in the terminal to allow root user login, if the file does not exist, the root can log in at any terminal.

/ Etc / usertty file for the user to make additional access restrictions, if the file does not exist, there are no other restrictions.


Switching mode graphics mode and text mode

Linux provides six preset command terminal window Let's login.

Our default login is the first window, which 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, then 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 switch in the graphical interface to the command window.

bg2013081707

Linux shutdown

In linux field mostly used in servers, rarely encountered shutdown operations. After all, a service running on a server are endless, except under special circumstances, it will be forced to shut down.

Correct shutdown sequence is: sysnc> shutdown> reboot> halt

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

For example, you can run the following command shutdown:

sync 将数据由内存同步到硬盘中。

shutdown 关机指令,你可以man shutdown 来看一下帮助文档。例如你可以运行如下命令关机:

shutdown –h 10 ‘This server will shutdown after 10 mins’ 这个命令告诉大家,计算机将在10分钟后关机,并且会显示在登陆用户的当前屏幕中。

Shutdown –h now 立马关机

Shutdown –h 20:25 系统会在今天20:25关机

Shutdown –h +10 十分钟后关机

Shutdown –r now 系统立马重启

Shutdown –r +10 系统十分钟后重启

reboot 就是重启,等同于 shutdown –r now

halt 关闭系统,等同于shutdown –h now 和 poweroff

To sum up, whether it is to restart the system or shut down 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, restart the system has shutdown -r now reboot init 6.