Linux system Boot Process "go"

Source: Internet
Author: User

We'll see a lot of boot information when the inux starts.

The boot process for Linux is not as complex as you might think, and the process can be divided into 5 phases:

    • Boot of the kernel.
    • Run init.
    • System initialization.
    • Set up the terminal.
    • The user logs on to the system.
Kernel boot

When the computer is powered on, it is the BIOS post that starts with the boot device (usually the hard disk) set up in the BIOS.

After the operating system takes over the hardware, it first reads the kernel file in the/boot directory.

Run Init

The init process is the starting point for all processes in the system, and you can compare it to the ancestor of all processes in the system, without which any process in the system will not start.

The INIT program first needs to read the configuration file/etc/inittab.

Run level

Many programs need to boot up. They are called "services" in Windows, and in Linux they are called "daemons" (daemon).

One of the major tasks of the Init process is to run these boot-up programs.

However, different applications need to start different programs, such as when serving as a server, the need to start Apache, as a desktop is not required.

Linux allows different start-up programs to be assigned for different occasions, which is called "RunLevel" (runlevel). That is, at startup, depending on the runlevel, determine which programs to run.

The Linux system has 7 runlevel (runlevel):

    • RunLevel 0: System down state, system default RunLevel cannot be set to 0, otherwise it will not start normally
    • RunLevel 1: Single User working status, root privilege, for system maintenance, remote login Forbidden
    • RunLevel 2: Multi-User State (no NFS)
    • RunLevel 3: Full multiuser State (with NFS), enter console command line mode after login
    • Run Level 4: System not used, reserved
    • Run level 5:x11 console, login to GUI mode
    • RunLevel 6: The system shuts down gracefully and restarts, the default runlevel cannot be set to 6, otherwise it will not start normally
System initialization

There is a line in the init configuration file: Si::sysinit:/etc/rc.d/rc.sysinit It calls execution/etc/rc.d/rc.sysinit, and Rc.sysinit is a bash shell script, It is mainly to do some system initialization work, Rc.sysinit is each run level must first run the important script.

Its main tasks are: Activating the swap partition, checking the disk, loading the hardware modules, and some other priorities that need to be performed.

L5:5:WAIT:/ETC/RC.D/RC 5

This line indicates that running with the 5 parameter/ETC/RC.D/RC,/ETC/RC.D/RC is a shell script that accepts 5 as a parameter to execute all RC startup scripts under the/etc/rc.d/rc5.d/directory,/etc/rc.d/rc5.d/ These startup scripts in the directory are actually some connection files, not the actual RC startup scripts, and the actual RC startup scripts are actually placed in the/etc/rc.d/init.d/directory.

These RC startup scripts have a similar usage, and they generally accept start, stop, restart, status, and so on.

The RC startup script in/etc/rc.d/rc5.d/is usually a connection file that starts with K or S, and will run with the start parameter for startup scripts starting with S.

If you find that the corresponding script also has a K-link, and is already in the running state (the file under/var/lock/subsys/as the flag), the stop will be the first parameter to stop these started daemons, and then rerun.

This is done to ensure that when Init changes the RunLevel, all associated daemons are restarted.

As to which Daemons will be run at each run level, the user can be set from the row by using "System Services" in Chkconfig or Setup.

Set up terminal

After the RC finishes executing, return to init. At this point the basic system environment has been set up, various daemons have been started.

Init then opens 6 terminals so that the user can log on to the system. The following 6 lines in Inittab define 6 terminals:

1:2345:respawn:/sbin/mingetty Tty12:2345:respawn:/sbin/mingetty tty23:2345:respawn:/sbin/mingetty tty34:2345: Respawn:/sbin/mingetty Tty45:2345:respawn:/sbin/mingetty Tty56:2345:respawn:/sbin/mingetty Tty6

From the above can be seen in the 2, 3, 4, 5 of the operating level will be respawn to run the Mingetty program, mingetty program can open terminal, set mode.

At the same time it will display a text login interface, which is the login interface we often see, in this login screen will prompt the user to enter a user name, and the user input user will be passed as a parameter to the login program to verify the identity of the user.

User Login System

In general, there are three ways users sign in:

    • (1) Command line login
    • (2) SSH login
    • (3) Graphical interface login

For graphical users with a run level of 5, their login is via a graphical login interface. After successful login, you can go directly to KDE, GNOME and other window manager.

This article is mainly about the text mode of login: When we see the Mingetty login interface, we can enter the user name and password to log into the system.

Linux Account Verification Program is Login,login will receive mingetty from the user name parameters.

Login then parses the username: If the user name is not root and there is a/etc/nologin file, login will output the contents of the Nologin file and then exit.

This is typically used for system maintenance to prevent non-root users from logging on. Only the terminal registered in/etc/securetty allows the root user to log on, and if the file does not exist, root can log on at any terminal.

The/etc/usertty file is used to make additional access restrictions to the user, and there are no additional restrictions if the file does not exist.

How to switch between graphic mode and text mode

Linux presets provide six command window terminals let's log in.

By default we are logged in the first window, that is, Tty1, the six windows are Tty1,tty2 ... tty6, you can press CTRL + ALT + F1 ~ F6 to toggle them.

If you have a graphical interface installed, by default it is entered into the graphical interface, you can press CTRL + ALT + F1 ~ F6 to enter one of the command window interfaces.

When you go to the Command window interface and then return to the graphical interface just press CTRL + ALT + F7 to come back.

If you are using a VMware virtual machine, the shortcut keys for the command window switch are ALT + Space + f1~f6. If you are in the graphical interface, press ALT + Shift + Ctrl + F1~F6 to switch to the command window.

Linux shutdown

Most of the Linux domain is used on the server, and there are few shutdown operations. After all, running a service on the server is endless, unless in exceptional circumstances, the last resort will be turned off.

The correct shutdown process is: sysnc > Shutdown > Reboot > Halt

The shutdown instruction is: shutdown, you can look at the help document with man shutdown.

For example, you can run the following command to shut down:

Sync synchronizes the data from memory to the hard disk. Shutdown shutdown instructions, you can look at the help documentation for man shutdown. For example, you can run the following command to shut down: shutdown–h ' This server would shutdown after the mins ' This command tells you that the computer will shut down after 10 minutes and will be displayed in the login user's current screen. Shutdown–h now immediately shuts down Shutdown–h 20:25 the system shuts down at 20:25 today, Shutdown–h +10 10 minutes after shutting down the machine shutdown–r the system immediately restarts Shutdown–r +10 system restarts after 10 minutes Reb Oot is the restart, equivalent to the Shutdown–r nowhalt shutdown system, equivalent to Shutdown–h now and Poweroff

In conclusion, whether it is rebooting the system or shutting down the system, first run the sync command to write the data in memory to disk.

The command to shut down has shutdown–h now halt Poweroff and Init 0, and the command to restart the system has shutdown–r now reboot init 6.

Linux system Boot Process "go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.