Linux Learning Note (iii): Switching between system run level and run level

Source: Internet
Author: User

The 1.Linux system differs from other operating systems, and it has a runlevel. The run level specifies the state in which the operating system is located. Linux systems run at a certain run level at any time, and the programs and services that run at different run levels are different, and the work to be done is different from what is to be achieved.


2.Linux (Red Hat 9.0) sets up 7 different run levels, and the system can switch between these runlevel to do different things.


3. The following is a brief introduction to 7 system operating levels:

(1). Run Level 0: Turn off the computer.

(2). Run Level 1: Single user mode.

(3). Run Level 2: Multi-user mode (without network File system NFS support feature).

(4). Run Level 3: Multi-user mode with NFS support for network file systems.

(5). Run Level 4: The system is reserved for standby.

(6). Run Level 5: Used to automatically start the XFREE86 system (graphical mode).

(7). Run Level 6: Reboot.

In addition, there are two special operational levels (run level)


4. Next, understand the 7 system run levels:

(1). Run Level 0 is designed to shut down the computer system, when all the open services are stopped, the running process will be turned to the terminating state, the system reclaims the allocated resources, and power off the system. When the shutdown Command shutdown-h command is used, the system is transferred to that run level.

(2). Run Level 1 is designed to maintain a computer system in single-user mode, where you can run commands that do not fit in multi-user, multi-tasking mode. At this point the system only opens up very few services.

(3). The run-level 2,3,5 are multi-user mode, except that the run-level 2,3 is a character terminal mode, but the run-level 2 does not have network File System (NFS) support, and the run-level 3 has Network File System (NFS) support. Run Level 5 is a graphical way, it makes ordinary user's operation more simple and convenient.

(4). Run Level 6 is set up for restarting the computer system, at which time all the services that are opened in the system are to be stopped, the running process is turned to the terminating state, the system reclaims the allocated resources, and restarts the computer system, when using the Shutdown-r or reboot command, The system is transferred to the run level.


5. System run level view, can be implemented by executing command mode or viewing the configuration file way:

(1). Execute Command mode: Use the RunLevel command to view the previous and current system run levels.

Enter the RunLevel command at the command line, which looks at the/etc/run/utmp file and outputs the previous and current run-level conditions on the standard output device, as shown in:

N 5 indicates that the previous run level is unknown, the current run level is 5, that is, the current run level is automatically started XFREE86 system (graphical mode).

(2). How to view the configuration file, how to view the configuration file can only see the current operating level of the system, the system configuration file is/etc/inittab:

We can open it through the file editor, or we can use the Open File command to view it, and at the command line enter: Gedit/etc/inittab, i.e.:

See the red arrow pointing at the box, Id:5:initdefault:, 5 in this line means that the current default system run level is 5.


6. The switching of the system run level can be achieved by executing the command or by modifying the configuration file:

(1). Execute the command mode, the Linux system can switch the system operation level as needed at any time, the switch command has two:

Command one: init [0123456Ss]

Command two: Telinit [0123456sSQqabcUu]

Description of the parameter:

0~6: Switches to the specified system run level.

A,b,c: Processes that can be run in the A,b,c run level for those specified in the/etc/inittab file.

s or S: Switch to single-user mode.

Q or Q: Recheck the/etc/inittab file.

U or u: make the/etc/inittab file rerun again, keep the current state, and do not recheck the/etc/inittab file.

Because the system is going to install or unload some of the file systems, turn off and turn on some of the services, allocate other resources, it takes a certain amount of time to switch the running level, so don't assume that there is something wrong with a cup of water to rest. Each time you switch the run level, the system will return to the user login interface and ask the user to log in again.


Next we can enter command one in the above command, enter command at command line: Init 1, enter single user mode, as shown in:

Press ENTER to execute this command, following the execution:

Entering the single-user mode, we can enter the command: Init 2, enter multi-user mode (without network File system NFS support feature) as shown in:

Press ENTER to execute this command, as follows:

After entering the login name and password, the interface appears:

Then we want to go back to just the graphical interface, you can enter init 5, to automatically start the XFREE86 system (graphically), as shown in:

Press ENTER to execute this command as follows:

After entering the user name and password, enter the GUI.

Let's try to use command two to see if we can switch the system operation level? Enter the command Telinit 6 to see if it restarts, enter the command:

The red box is to restart the system.

(2). Switch the system run level can also modify the configuration file mode, modify the configuration file mode is directly to the/etc/inittab file in the default run level modified to the run level to be set and save (in the 5th section on how to open the file and view the default system run level), However, this approach requires restarting the system for the run level to take effect, so it is more convenient to switch the system run level in real-world use with the execution of commands.


8. Next, the system run-level services are introduced, and the services started at different run-level are different, and these services are also known as Daemons under Linux. Users can see which services the Linux system has started and shut down in character or graphics mode, or you can modify the default settings in the installation in character or graphics mode, and the services you need are turned on or off.

(1). The following describes how to view the service by command, enter the command at the command line: Chkconfig--list, as shown in:

The displayed results are divided from left to right: service name, run level, state.

(2). The following describes how to view system run-level services graphically, as shown in:

Click the red arrow pointing point, also services, you can start the Service Setup program:

check box tick is open service, not ticked is not open service.


9. The standalone daemon is managed by the Init script file, where all the script files for the standalone daemon are placed in the/ETC/RC.D/INIT.D directory, and in/ETC/RC.D/RCX.D, there are many symbolic link files that start with K or S, which all point to/ The script files in the ETC/RC.D/INIT.D directory, the files beginning with k indicate that a service is to be terminated at run-level switching, and a file starting with s indicates that a service is to be started at run-level switching, and we can simply understand that k is kill, which kills, S is start, that is, starts.

We can switch to the/ETC/RC.D/RC0.D directory to view these linked files:

(1). Enter the command CD/ETC/RC.D/RC0.D and Ls-l, respectively, as shown in:

You can see that the link file here is pointing to: /init.d/Directory of files, this: Refers to the parent directory, the parent directory of the INIT.D directory is the/ETC/RC.D directory, that is, the link file points to a file in the/ETC/RC.D/INIT.D directory.


10. The settings for system run-level services can be implemented either by command or by graphical means:

(1). Command mode: In character mode you can use the command to set the turn on or off service, the setting command is: NTSYSV, after executing the command as shown:

Use the cursor keys or mouse to move the scrollbar to the service item you want to set, press SPACEBAR or click the option box with the mouse, select * indicates, if you do not need the service, then press the SPACEBAR or click the option box with the mouse, no symbol is selected.

You can also run the Setup command, and then select the System Services menu item and press ENTER to set it.

(2) graphics, and the service to view the same graphics, that is, the second section of the 8th above, you can set the service.


11. I am also a beginner Linux, the above content is only for everyone to learn the reference used, but also conducive to the accumulation of learning knowledge, so write a bad place please forgive me, if there are errors, please point out, thank you!



Linux Learning Note (iii): Switching between system run level and run level

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.