Analysis of running level and startup mechanism of Linux system

Source: Internet
Author: User

Original Technology Achievement Dream

Original link: http://ixdba.blog.51cto.com/2895551/533740

a system run level
The Windows system has a safe operating mode and a normal operating mode, which is two different run levels, and Linux also has a system runlevel, and the Linux system has a more flexible and diversified operating level.
Before telling the running level, the INIT program under Linux is described, because the INIT program is directly associated with the system RunLevel, and the INIT program is one of the most important programs of the Linux operating system and is a user-level process initiated by the system kernel. The init process is also the originator of all other system processes, which means that the INIT process is the first process running on the system, and its process number is always 1.
The Linux system has 7 RunLevel, which are specified in the/etc/inittab file, and the specific implementation of the/etc/inittab file is described below.
Take Redhat Linux as an example, here is a piece of information for/etc/inittab.
# Default RunLevel. The runlevels used by RHS is:
# 0-halt (do not set Initdefault to this)
# 1-single User mode
# 2-multiuser, without NFS (the same as 3, if you don't have networking)
# 3-full Multiuser mode
# 4-unused
# 5-x11
# 6-reboot (do not set Initdefault to this)
The above information lists the 7 operating levels of the Linux system:
0-shutdown mode,
1-Single user mode, single user only system administrator can log in.
2-Multi-user mode, but file sharing is not supported, for example, NFS service is not supported. This mode is not commonly used.
3-Full multi-user mode, support for NFS services. The most common user mode, the default login to the system's character interface.
4-Basic Unused user mode, you can implement some specific login requests.
5-Full multi-user mode, the default login to the X-window system, that is, login to the Linux GUI.
6-Restart mode, that is, execute to close all running processes, and then restart the system.
These runlevel and Linux init programs correspond to each other, such as the execution of the Init 1 system into single-user mode, the execution of the Init 6 system will be restarted.

two system start-up process
1. Kernel boot
Power on the system, start the BIOS self-test, the system according to the BIOS settings to boot the device (usually hard disk boot), and then into the Linux boot program, the general Linux system provides two ways of booting: grub and Lolo, where grub is the default boot mode for most Linux systems, Lilo is based on a number of special needs or personal preferences prepared, once the Linux boot program loaded into memory, it displays a graphical interface to the user, this interface contains different kernel options, the user can select different kernel boot through the upper and lower keys, when the boot successfully completed boot, the Linux connection Take control of the CPU, then the CPU starts to execute the Linux kernel image program, loads the kernel, locates the INITRD image in a predetermined place, extracts and mounts it, loads all the necessary drivers, and then kernel creates the root device. Mount the root partition in read-only mode and release any unused memory, at which point the kernel has been loaded into memory to run. However, because there is no user application that allows the input of meaningful instructions to the system, the system cannot do anything at this time.
2. Run Init
The init process is the starting point for all processes in the system, immediately after Linux completes the kernel boot, the INIT program needs to read the configuration file/etc/inittab, and Inittab is a non-executable text file, we will The system run level section is described in detail.
3. System initialization
Init program First call Rc.sysinit and RC program, rc.sysinit mainly complete some system initialization work, it is the system each run level to first run the important script. Its main work is to check the disk, load the hardware module, activate the swap partition, and some other priority tasks, and when the Rc.sysinit program finishes executing, the boot returns to the INIT program.
4. Start the daemon at run level
Rc.sysinit program execution finished, next, the RC program starts, the RC program mainly starts the system corresponding to the operating level of the daemon, the RC program is completed, and will return to the INIT program to continue the next step.
5. Set up terminal
At this point the system basic environment has been set up, the INIT program will then open 6 terminals, so that users log in.
6. Login System
When we see the login screen of Mingetty, we can enter the username and password to log into the system. The Linux account Verification program is login, and when the login program executes successfully, it finally enters the shell terminal.
The Linux system then completes the process from boot to boot.

three-system shutdown process
Before understanding the Linux shutdown process, we will first learn some of the common Linux shutdown commands, the most common Linux shutdown commands are as follows: Init, shutdown, halt,reboot, and so on, these commands can achieve the purpose of shutdown restart, But the internal work process for each command is different. We'll learn more about the Linux security shutdown process by telling you about the shutdown command.
1. Shutdown command
Using the shutdown command to safely shut down the Linux system, some Linux beginners use the direct power off method to shut down Linux, which is very dangerous, because Linux is different from Windows, the Linux background runs a lot of processes, These processes control the various operations of Linux on the system, if forced shutdown, can cause confusion and loss of data, if the system workload is high, sudden power loss, not only will lose data, and even damage the hardware device.
Shutdown command is a program written in the shell, must be performed by the Superuser, the shutdown command executes, will be broadcast to notify all users working in the system, the system will be closed within a specified time, please save the file, stop the job, log off the user; At this point, the login command is frozen, the new user cannot log in, when all the users log off from the system or the specified time has elapsed, shutdown sends a signal to the INIT program, requiring the INIT program to change the system RunLevel, followed by the INIT program passed the parameters according to the shutdown instruction. , the corresponding change of the run level, for example, the shutdown specified parameter is the shutdown command, the INIT program executes the init 0 shutdown, if the shutdown specified parameter is to restart the system, then the INIT program executes the init 6 system restart.
? Detailed syntax for the shutdown command:
Shutdown [-FFHKNRC (parameter name)] [-t number of seconds] time [warning message]
Specific parameters of the function:
-F does not perform fsck on reboot (note: fsck is a program for checking and repairing file systems under Linux, which we will cover in more detail later in this chapter).
-F to perform fsck upon restart.
-H shuts down the system to some extent with the equivalent of the halt command.
-K simply sends out information to all users, but does not actually shut down.
-N does not call the INIT program shutdown, but by shutdown itself (the general shutdown program is called by shutdown Init to implement the shutdown action), using this parameter will speed up the shutdown, but it is not recommended for users to use this type of shutdown.
-R shutdown after rebooting the system.
-C cancels the previous shutdown command. For example, when you execute a command such as "Shutdown-h 15:30", you can interrupt the shutdown command by pressing the "CTRL + C" key. The execution of a command such as "Shutdown-h 15:30 &" will shutdown go to the background and it is time to use Shutdown-c to cancel the previous shutdown command.
Number of seconds between-t< seconds > send out warning message and shutdown signal. The warning message will alert the user to save the current work.
[TIME] Set how long after the shutdown command is executed. The time parameter has hh:mm or +m two modes.
The hh:mm format represents a few minutes to execute the shutdown command. For example, "shutdown 16:50" means that shutdown will be executed at 16:50, +m represents M-minute execution shutdown, and the more special usage is to immediately execute shutdown with now, it is worth noting that this part of the parameter cannot be omitted.
[Warning message] information to be transmitted to all logged-in users.
? Application Examples:
Immediate shutdown restart: shutdown–r now
Immediate shutdown: Shutdown–h now
Set the shutdown after 5 minutes and issue a warning message to the logged-on Linux User:
Shutdown +5 "System would shutdown after 5 minutes"
2. Halt command
Halt is the simplest shutdown command, equivalent to the shutdown–h combination, when Halt executes, kill many applications, and then call the system directive Sync,sync to write all memory information through the file system to the hard disk and then stop the kernel.
Some of the parameters of the halt command are as follows:
[-f] does not invoke shutdown and forces shutdown or restart.
[-i] turn off all network interfaces before shutting down or restarting.
[-p] calls Poweroff at shutdown, which is the default option.
3. Reboot command
The execution of the reboot command is basically similar to the halt, unlike the halt, which is used to shut down the machine, and the reboot is to cause the system to restart after the shutdown.
4. init command
The INIT process is the originator of all processes, the process number is always the 1,init program is mainly used for switching between different operating levels of the system, the switch is done immediately, for example, Init 0 is to switch the system run level to 0, that is, shutdown, the init 6 command to switch the system RunLevel to 6, That is, rebooting the system.

Analysis of running level and startup mechanism of Linux system

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.