The Linux operating system has gone through several different stages since it was started to start. These stages are called runlevel, which is the same
When the Linux operating system is shut down, there are several different runlevels. Next we will introduce runlevel in detail and show you some tips to help you
Linux does not need to be restarted. .
Runlevel can be regarded as the system status and image. You can think that runlevel is a bit like that in Microsoft Windows
Normal, safemode, and command prompt
Only. To access each runlevel, you need to start or close a series of services. These services are placed in the directory as initialization scripts.
/Etc/rc. d/RC ?. D/or/etc/rc ?. Under d (? Indicates the serial number of runlevel)
. .
In most Linux releases, there are usually eight runlevels ..
Runlevel system state
0 halt the system
#0-stop (never set initdefault to 0)
1 single user mode
#1-single-user mode
2 Basic Multi User Mode
#2-multiple users without NFS
3 Multi User Mode
#3-full multi-user mode (Standard Operation Level)
#4-useless
5 Multi User Mode with GUI
#5-X11 (XWindow)
6 reboot the system
S, s single user mode
.
#6-Restart (do not set initdefault to 6. Setting initdefault to 0 or 6 is a denial of service attack !)
In most Desktop Linux systems, the default runlevel is 5. When users log on to the Linux system, the graphic interface is used. In most server versions
In Linux, the default runlevel is 3, and the user logs on to the character interface. runlevel 1 and 2 are rarely used except debugging. runlevel
S and S are not directly used by users, but used to prepare for single user mode.
..
Compared with the Windows Startup Mode, the Linux running mode has the following advantages: You can use the. init tool to switch the runlevel you are currently using when the system is idle. In addition, when
When you shut down or start the Linux system, you may have switched your runlevel without knowing it. The system shutdown process needs to call runlevel (0 or 6) to close all running
.
!
Display current running mode
.
When you get started, you may be curious about the previous and current running modes. The runlevel command can be used to display the information:
$/Sbin/runlevel
3 5
The runlevel command output indicates that the initial running mode is 3, and the current running mode is 5.
.
Use the telinit command (Root User) to switch the running mode ):
$/Sbin/telinit
In general, the purpose of switching the running mode is to restart some applications
For example, if xfree86 switches the running mode from 5 to 3, it will terminate xfree86 and all processes related to it, and then switch the running mode to 5, so that xfree86 can be very clean.
Start. Before doing this, make sure that all the work in xfree86 has been saved. Use the root user:
$/Sbin/telinit 3
$/Sbin/telinit 5
After you type a command, your screen may display information about the service start or stop.
.
Add startup service in Running Mode
..
To add a startup service in a running mode, you must first create a STARTUP script for the service and place it in/etc/rc. d/init. D or/etc/init. d
/(Depending on your Linux version). to associate the startup script with the running mode, you need to create a directory in the running mode with/etc/rc. d/init. d/lower
Start the symbolic script
Link. the prefix of the file name is generally sxx and XX is a number, which is used to control the service startup sequence in this running mode. The script is executed in ascending order of numbers, that is, the smaller the number.
The following is an example of adding the startup service to the running mode:
$ CP myservice/etc/rc. d/init. d/
$ Ln-S/etc/rc. d/init. d/myservice/etc/rc3.d/s99myservice
In this way, the next time runlevel 3 is started, myservice will automatically start.
Start with a certain runlevel
You can customize the runlevel entered during startup. If your system uses Lilo, set the corresponding part in the startup command:
Lilo: Linux 5
If you are using grub, you can press the e key to enter the Setting Mode at startup, and the corresponding position is displayed as follows:
Kernel/vmlinuz Ro root =/dev/hda1 5
Application settings:
How to set up a program (service) to start automatically in Linux
1,
This is also the most common
Rcconf:
Sudo apt-Get install rcconf
Run rcconf under root.
More comprehensive functions: sysv-RC-Conf
Sudo apt-Get install sysv-RC-Conf
Run: sysv-RC-Conf
This is easy to change, for example:
2,
Directly change/etc/rc0.d ~ Something in/etc/rc6.d and/etc/RCs. D. Start with S and not start with K,
For example, to disable automatic startup of vsftpd, you only need to run sudo mV/etc/rc2.d/s20vsftpd/etc/rc2.d/k20vsftpd.
The purpose of this command is to use the MV rename function.
3. chkconfig
This method is commonly used in RedHat and Debian. It is relatively simple to use method 1 in fedora and Ubuntu, but it is also good to learn about this method.
But in Ubuntu, this command is not as easy as RedHat, and it is always wrong.
Check the usage of chkconfig in RedHat.
1. chkconfig -- level [0123456] [service name] [ON | Off]
Chkconfig -- level 23 dhcp3-server off ---- set DHCP server service to close under level2, 3.
2. view the auto-enable status of the Service in chkconfig -- list.
3. Add a service to chkconfig for management, but the service must be in/etc/init. d.
Example,
1, gedit/etc/init. d/test
Chkconfig: [runlevels] [start number] [stop number]
Chkconfig: 23 80 70
The START number indicates s80test.
Stop number indicates k70test
2, chkconfig -- add Test
3, chkconfig -- List Test
Test 0: off 1: off 2: On 3: On 4: off 5: off 6: Off
4. Check/etc/rc. d/Files
Find/etc/rc. d-type L | grep 'test' | sort
/Etc/rc. d/rc0.d/k70test
/Etc/rc. d/rc1.d/k70test
/Etc/rc. d/rc2.d/s80test
/Etc/rc. d/re3.d/s80test
/Etc/rc. d/rc4.d/k70test
/Etc/rc. d/rc5.d/k70test
/Etc/rc. d/rc6.d/k70test
/Etc/rc. d/rc7.d/k70test
-Type L indicates "connection file"
4. chkconfig -- del deletes a service managed by chkconfig.
5. The current run level 2 is the started service.
Chkconfig -- list | grep '3: on'
If the above method does not work in Ubuntu 10.04
For example, MySQL and vsftpd will still start up after the above settings
You need to do the following:
Go to the/etc/init/directory
CP/etc/init/
You will find the mysql. conf and vsftpd. conf files
Yes, these two files need to be modified.
At the beginning of the file
Start on (filesystem and net-device-up iface! = LO)
Stop on runlevel [xxxx]
# XXXX indicates the runlevel level. For example, 2345 indicates runlevel 2, 3, 4, and 5.
In my vsftpd. conf
Stop on runlevel [! 2345]
# Indicates that the instance is not started at runlevel 2, 3, 4, and 5.
Here is the key to the problem. Our system is started with runlevel 2 by default.
So we can change it
Stop on
Runlevel [0126]
# Of course this is not the case, but at least two