Linux startup process

Source: Internet
Author: User

There are 5 stages of the Linux boot process

1) boot of the kernel.

2) Run init.

3) Initialization of the system.

4) set up the terminal.

5) User Login system

1. Boot of the kernel

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

2. Start the initialization process

After the kernel file is loaded, it starts running the first program/sbin/init, which is initialized with the system environment. Since Init is the first program to run, its process number (PID) is 1. All other processes derive from it, all of which are its child processes.

3. Determine the operating level

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.

Linux presets seven RunLevel (0-6). In general, 0 is shutdown, 1 is single-user mode (that is, maintenance mode), and 6 is a reboot. Run level 2-5, each release is not the same,

The INIT process first reads the file/etc/inittab, which is the run-level settings file. There is a initdefault in its file that represents the RunLevel at which the system starts. My 3 is the default runlevel. If you need to specify a different level, you can modify this value manually.

The system then specifies the program to be loaded via a subdirectory under the/ETC/RC.D

The "RC" in the above directory name represents the Run command (running the program) and the last D indicates directory. Let's look at what programs are specified in the/ETC/RC.D/RC3.D directory.

You can see that the file name is in the form "letter S+ two digits + program names". The letter S means start, that is, the starting point (the start script runs with start), if the position is the letter K, which means kill (close), that is, if you switch from another runlevel, you need to close the program (the startup script has a run parameter of stop). The next two digits indicate the processing order, the smaller the number, the earlier processing, so the first program to start is MOTD, then rpcbing, NFS ... When the numbers are the same, they start in alphabetical order of the program name, so the Rsyslog will start before sudo.

All files in this directory are the programs to be loaded at startup. If you want to add or remove some programs, it is not recommended to manually modify the/ETC/RC.D/RCN.D directory, preferably with some special commands to manage.

4. Load Boot startup program

As mentioned earlier, the seven preset "RunLevel" each have a directory that stores the programs that need to start up. It is not difficult to think that if more than one "runlevel" needs to start the same program, then the program's startup script will have a copy in each directory. This can be a management problem: if you want to modify the startup script, not every directory will be changed.

The Linux solution, is the seven/ETC/RC.D/RCN.D directories listed in the program, are set as a link file, pointing to another directory/ETC/INIT.D, the real startup scripts are unified in this directory. The init process loads the start-up program, which is actually running the startup script in this directory.

Another benefit of this is that if you want to manually shut down or restart a process, go directly to the directory/ETC/INIT.D to find the startup script.

5. User Login

In general, there are three ways users can sign in: (1) command line login (2) SSH login (3) GUI Login

In all three cases, users are certified in their own way.

(1) Command line login: The init process calls the Getty program (meaning get teletype), allowing the user to enter a user name and password. Once the input is complete, call the login program and check the password (Debian will run an identity check/etc/pam.d/login). If the password is correct, read the user-specified shell from the file/etc/passwd and start the shell.

(2) SSH login: Then the system calls the SSHD program (Debian will run/etc/pam.d/ssh again), replacing Getty and Login, and then start the shell.

(3) GUI Login: The init process invokes the display manager, the Gnome graphical interface corresponds to the display manager for GDM (Gnome Display manager), then the user enters the user name and password. If the password is correct, read/etc/gdm3/xsession and start the user's session.

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.

Reference: http://www.ruanyifeng.com/blog/2013/08/linux_boot_process.html

Linux startup process

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.