Linux Runlevel Startup scripts

Source: Internet
Author: User

The Linux operating system has been going through several different stages since it started to start, and these stages are called Runlevel, as well as a few different Runlevel when the Linux operating system shuts down, as described in detail in Runlevel, And show some tips to get Linux systems to avoid unnecessary reboots.

Runlevel can be thought of as a system state, image a little, you can think of Runlevel a bit like the normal startup in Microsoft's Windows operating systems (normal), security mode (safemode) and command prompt only. Entering each Runlevel requires starting or shutting down the corresponding series of services (services), which are placed in directory/ETC/RC.D/RC in the form of initialization scripts. d/or/ETC/RC? D below. (? represents the corresponding serial number of the Runlevel).

In most Linux distributions, there are typically 8 runlevel system states (Runlevel System State):

    • 0 Halt The system stops (do not set Initdefault to 0), the machine shuts down
    • 1 single user mode, similar to safe mode under Win9x
    • 2 Basic Multi User mode with no NFS support
    • 3 Multi User mode is a full multiuser model and is a standard run-level
    • 4 None generally not, in some special cases you can use it to do something. For example, you can switch to this mode to do some setup when your laptop's battery is running out.
    • 5 Multi User mode with GUI is X11, into the Xwindow system.
    • 6 Reboot The system restarts (do not set Initdefault to 6), the Init 6 machine will restart
    • s, s single user mode

Different run levels have different uses, and should be set according to their own different situations. For example, if you lose the root password, you can set the machine to boot into a single-user state. At the Lilo prompt after startup, enter:

Init=/bin/sh RW (or Linux 1;linux single)

You can get the machine into run Level 1 and hang the root file system as read-write. He will skip all system certifications, let you use the passwd program to change the root password, and then boot to a new run level.

Most of the desktop Linux system default Runlevel is 5, the user login is the graphical interface, and most of the server version of the Linux system default Runlevel is 3, the user login is the character interface, Runlevel for 1 and 2 in addition to debugging is rarely used, RUNL Evel for S and s are not intended for use directly to the user, but for single user mode.

Show current operating mode : RunLevel

$ runlevel

3 5

The output of the RunLevel command indicates that the initial operating mode is 3, and now the operating mode is 5.

To join the startup service in run mode

To add a startup service to a run mode, first create a new service startup script, and then put it in/ETC/RC.D/INIT.D or/etc/init.d/(depending on your Linux version) to associate the startup script with the run mode. You need this run mode directory to create a symbolic link with the startup script under/etc/rc.d/init.d/, the filename prefix is usually sxx,xx, which is used to control the boot order of the service in this run mode. The order in which the scripts are executed is performed according to the number size, that is, the smaller the number the first, the following is a specific example of adding a startup service in run mode:

$ CP myservice/etc/rc.d/init.d/

$ ln-s/etc/rc.d/init.d/myservice/etc/rc3.d/s99myservice

This way, the next time you start with RunLevel 3, the MyService will start automatically.

Start with a runlevel

You can make your own runlevel that you enter at startup, and if your system uses LILO, the corresponding section in the Boot command is:

Lilo:linux 5

If you are using grub, you can press and hold the E key to enter setup mode at startup, and the corresponding position is displayed as:

Kernel/vmlinuz RO root=/dev/hda1 5

Ubuntu Run Level

The default installed Ubuntu Linux will go directly to the graphical interface. But most of the time I don't need to do things on the graphical interface, and the command line of the character interface is enough. Recall that in Redhat you can change the default run level (Runlevel) from 5 to the implementation by modifying the/etc/inittab, unfortunately there is no such file in Ubuntu. However, Ubuntu is compatible with Inittab, but it needs to be built by hand.

The default Runlevel after Ubuntu installation is 2, which can be viewed with the Runlevel command. Because of runlevel=2, scripts that start with s in the/etc/rc2.d/directory are automatically executed during the boot process. The reason why Ubuntu can be launched directly into the graphical interface is due to the running of GDM. So as long as the GDM startup script is disabled, the method is to change the name of the first letter S to K:

Cd/etc/rc2.d

sudo mv S30GDM K30GDM

This is a method, and it's very simple. But the more convenient way is to set a new Runlevel, and let the new Runlevel start to the character interface. This facilitates management. Ubuntu does not have/etc/inittab file, had to create a new, content only one line:

Id:3:initdefault:

This will automatically run the script under the/etc/rc3.d/directory the next time it starts, instead of being in/etc/rc2.d/. So the next step is to go into/etc/rc3.d/and look at the startup script file name of GDM:

Ls-l *GDM

If it starts with S, change the file name to K-line.

Linux Runlevel Startup scripts

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.