Linux运行等级共有7级:
0:系统直接关机
1:单用户模式
2:和等级3一致,但无NFS服务
3:完整的含有网络功能的纯文本模式
4:系统保留功能
5:与运行等级3类似,但使用X Window
6:系统重启
从上面7级可以看出,我们可以设置运行等级其实只能设置1,2,3,5。0和6我不用解释吧,如果设置为4,系统会不断的自动关机或自动重启的。
默认情况下,要想修改默认运行等级,要修改/etc/inittab文件。但是Ubuntu系统并没有这个文件。而是需改/etc/init/rc-sysinit.conf这个文件:
description "System V initialisation compatibility" author "Scott James Remnant <scott@netsplit.com>" start on filesystem stop on runlevel # Default runlevel, this may be overriden on the kernel command-line # or by faking an old /etc/inittab entry env DEFAULT_RUNLEVEL=3 # There can be no previous runlevel here, but there might be old # information in /var/run/utmp that we pick up, and we don't want # that. # # These override that env RUNLEVEL= env PREVLEVEL= task script # Check for default runlevel in /etc/inittab if [ -r /etc/inittab ] then eval "$(sed -nre 's/^[^#][^:]*:([0-6sS]):initdefault:.*/DEFAULT_RUNLEVEL="\1";/p' /etc/inittab || true)" fi # Check kernel command-line for typical arguments for ARG in $(cat /proc/cmdline) do case "${ARG}" in -b|emergency) # Emergency shell [ -n "${FROM_SINGLE_USER_MODE}" ] || sulogin ;; [0123456sS]) # Override runlevel DEFAULT_RUNLEVEL="${ARG}" ;; -s|single) # Single user mode [ -n "${FROM_SINGLE_USER_MODE}" ] || DEFAULT_RUNLEVEL=S ;; esac done # Run the system initialisation scripts [ -n "${FROM_SINGLE_USER_MODE}" ] || /etc/init.d/rcS # Switch into the default runlevel telinit "${DEFAULT_RUNLEVEL}" end script
看到env DEFAULT_RUNLEVEL=3这一行没,对了,这里就是系统默认的运行等级。我们可以通过修改这里的值来达到修改运行等级效果。
查看系统的运行等级:runlevel
切换系统运行等级:init 0~6
===============================================================