Linux: running level and restart (1)

Source: Internet
Author: User

Learn to shut down or restart your Linux system, and warn you that the system is shutting down, switching to a somewhat restrictive running level. This process is still unfamiliar to many Linux enthusiasts. Next, ask IBM Senior Programmer Ian Shields to introduce the Linux running level, shutdown, and restart.

Overview

In this article, we will learn to shut down or restart your Linux system and warn you that the system is shutting down. Switch to single-user mode or a somewhat restrictive running level. Learning:

• Set the default running level

• Changes Between running levels

• Changed to single-user mode

• Shut down or restart the system from the command line

• Warn users of major system events, including switching to another running level

• Terminate processes as appropriate

Unless otherwise stated, the examples in this article use Fedora 8 with 2.6.26 kernel. The upstar example uses Fedora 13 with 2.6.34 kernel or Ubuntu 10.10 With 2.6.35 kernel. Your results may be different on other systems.

Prerequisites

To make the most effective use of the articles in this series, you should have basic Linux knowledge and need to prepare a Linux system for using the commands described in this article. Sometimes the output formats of different versions of the program are different, so the results you get may not always be the same as the list and diagram shown here. In particular, the recent appearance of the System has changed the content familiar to many users of the traditional System V init process (for more details, see Init vs. Upstart ). This article focuses on the traditional System V init process and only gives a rough overview of the difference between upstar.

Running level

The running level defines the tasks that can be completed in the current State (or running level) of the Linux system. Each Linux system supports three basic running levels, plus one or more running levels for normal operations. The basic running level is shown in table 1.

Table 1. Basic Linux running level
Level

Purpose

0 Shut down (or terminated) the system
1 Single-user mode: generally referred to as s or S
6 Restart the system

In addition to these basic running levels, the running levels of each release are also different. A command uses a set, as shown in table 2.

Table 2. Other commands run in linux

Level

Purpose
2

Multi-user mode without network

3

Multi-User Network Mode

5

Multi-user mode with network and X Window System

The Slackware release uses run level 4 instead of 5 because the entire system is running the X Window System. Debian and its derivative products, such as Ubuntu, use a single running level for any multi-user mode, usually level 2. Be sure to check your version documentation.

Default running level

When a Linux system is started, the default running level is determined by the id: entry in the/etc/inittab. Listing 1 illustrates a typical entry of a System (such as Fedora 8 or openSUSE 11.2), both of which use runtime Level 5 for X Window System.

Listing 1. Default running level in/etc/inittab

[root@pinguino ~]# grep "^id:" /etc/inittab
id:5:initdefault:

If you want your system to start at different running levels, such as running level 3, edit this value.

Change the running level

There are several ways to change the running level. To make a permanent change, you can edit the/etc/inittab and change the default running level, as you saw above.

If you only need to upgrade your system to a different running level in one boot, you can do so. For example, if you have just installed a new kernel, you need to create some kernel modules after using the new kernel to restart the System, but before starting the X Window System. You may want to upgrade your running level to level 3 to complete this task. You can perform this operation during boot by editing the kernel line (GRUB) or adding a parameter after the selected system name (LILO. Use a single digit to indicate the expected running level (3 here ). We will introduce the specific process through a GRUB instance. Assume that your/boot/grub/menu. lst file contains the fragment shown in Listing 2.

Listing 2. Starting a typical GRUB fragment of Fedora 8

title Fedora (2.6.26.8-57.fc8)root (hd0,5)kernel /boot/vmlinuz-2.6.26.8-57.fc8 ro root=LABEL=FEDORA8 rhgb quietinitrd /boot/initrd-2.6.26.8-57.fc8.img

To upgrade the system to running level 3 and wait until the boot item appears, select the entry and enter 'e' to edit the entry. Based on your GRUB options, you may need to press a key to display the boot item, and then enter a 'p' and a password to unlock and edit it. The GRUB screen on the Fedora 8 system looks like figure 1.

Figure 1. Select a pilot option in GRUB

In this example, you can see the lines starting with root, kernel, and initrd. Move the cursor to the row starting with "kernel" and enter 'e' to edit the row. The GRUB screen on the Fedora 8 system is shown in figure 2.

Figure 2. Select the kernel to edit

Move the cursor to the end of the row, and add a space and a number '3 '. You can delete 'quiet 'or modify any other parameters as needed. The GRUB screen on the Fedora 8 system is shown in figure 3.

Figure 3. Set the startup running level to 3

Finally, press Enter to save the changes and Enter 'B' to guide the system.

Note: The steps for using LILO or GRUB2 are different from those for using GRUB, but the basic principle for editing the kernel startup method is the same, even if the GRUB interface on other systems or other versions is very different from the interface displayed here. The prompt information is usually helpful to you.

You may want to switch to runtime Level 5 when you finish your installation under runtime Level 3. Fortunately, you do not need to restart the system. You can use the telinit command to switch to another running level. Run the runlevel command to display the previous and current running levels. If the output character is 'n', the running level cannot be changed because the system is being booted. Listing 3 shows how to verify and change the running level.

Listing 3. Verify and change the running level

[root@pinguino ~]# runlevelN 3[root@pinguino ~]# telinit 5

After entering telinit 5, you will see several transient messages. Your interface will switch to the configured graphical logon interface. Open a terminal window and verify that the running level has been modified, as shown in Listing 4.

Listing 4. Confirm the new running level

[root@pinguino ~]# runlevel3 5

If you use the ls command to display a long list of telinit commands, you will see that it is actually a symbolic link to the init command. We will describe this in listing 5.

Listing 5. telinit is just a symbolic link to init.

[root@pinguino ~]# ls -l $(which telinit)lrwxrwxrwx 1 root root 4 2008-04-01 07:50 /sbin/telinit -> init

The executable file init knows whether it is called init or telinit and then adjusts accordingly. As PID 1 runs at boot, init is also very intelligent, knowing when you will call it using init instead of using telinit. If you do, it assumes that you want it to behave as if telinit has been called. For example, you may use init 5 instead of telinit 5 to switch to runtime Level 5.

Single User Mode

Compared with a PC operating system, such as DOS or Windows, Linux itself is a multi-user system. However, this may sometimes become a problem, for example, when you need to recover an important file system or database, or install and test a new software. Run level 1. Single User mode is your best answer in these cases. The actual implementation varies according to different versions, but you usually only start it with a small system. There is usually no network connection, and no (or very few) daemon processes are running. In some systems, you must log on to perform authentication, but in other systems, you can directly start to operate the shell prompt with the root user. The single-user mode may be a lifebuoy or damage your system. Therefore, you should be careful when using root user permissions at any time. Immediately restart to a normal multi-user mode.

Similar to switching to a normal multi-user running level, you can also use telinit 1 to switch to single-user mode. As described in table 1, 's' and 'S' are aliases of runtime Level 1, so you can use telinit s instead.


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.