Run level is Linux functional level operating system currently running. There are seven run levels, numbered from 0-6. The system can be directed to any given run level. Run level is identified by a number. |
Each run level specified different system configurations and allows different combinations of access to the process. By default, Linux will boot to run level 3 or level 5 to run. Do only a run level at startup. It will not be executed one by one.
The default system run level is specified in the / etc / inittab file SysVinit system.
But systemd system does not read this file, it uses the following files /etc/systemd/system/default.target to get the default run level information.
We can use the following five ways to check the Linux system is currently running level. runlevel
Command : runlevel
a printing system and the current operating level. who
Command : print information about the currently logged-on user. It will use the " -r
" option to print run level information. systemctl
Command: It controls the systemd
system and service manager.
Use /etc/inittab
file: default run level of the system in SysVinit System
the /etc/inittab
file specified.
Use /etc/systemd/system/default.target
file: default run level of the system in systemd System
the /etc/systemd/system/default.target
file specified.
Detailed operational level information described in the table below.
The system will run according to the level of implementation of the program / service.
Run Level 0 - /etc/rc.d/rc0.d/ Run Level 1 - /etc/rc.d/rc1.d/ run level 2 - /etc/rc.d/rc2.d/ run level 3 - / etc / rc.d / rc3.d / run level 4 - /etc/rc.d/rc4.d/ run level 5 - /etc/rc.d/rc5.d/ run level 6 - /etc/rc.d /rc6.d/
runlevel1.target – /etc/systemd/system/rescue.target runlevel2.target – /etc/systemd/system/multi-user.target.wants runlevel3.target – /etc/systemd/system/multi-user.target.wants runlevel4.target – /etc/systemd/system/multi-user.target.wants runlevel5.target – /etc/systemd/system/graphical.target.wants
runlevel
And is currently running on a level printing system:
[Linuxidc linuxidc.com @ localhost] $ runlevel
5 N
1], N: "N" represents the system up and running since the level has not been changed.
2], 5: "5" indicates that the current run level of the system.
打印有关当前登录用户的信息,它将使用-r选项打印运行级别信息:
[linuxidc@localhost linuxidc.com]$ who -r
运行级别 5
systemctl
命令
systemctl
用于控制systemd系统和服务管理器,systemd是Unix操作系统的系统和服务管理器。它可以作为sysvinit
系统的直接替代品,systemd
是内核启动并保持PID 1的第一个进程。systemd
使用.service文件而不是bash脚本(SysVinit使用),systemd将所有守护进程排序到他们自己的Linux cgroup
中,可以通过浏览/cgroup/systemd
文件来查看系统层次结构:
[linuxidc@localhost linuxidc.com]$ systemctl get-default graphical.target
系统的默认运行级别在SysVinit System
的/etc/inittab
文件中指定,但systemd不读取文件,因此,它仅适用于SysVinit系统而不适用于systemd系统。
[root@localhost ~]# vim /etc/inittab # inittab is only used by upstart for the default runlevel. # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # System initialization is started by /etc/init/rcS.conf # Individual runlevels are started by /etc/init/rc.conf # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) id:5:initdefault:
[linuxidc@localhost linuxidc.com]$ vim /etc/inittab # inittab is no longer used when using systemd. # # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target # # systemd uses 'targets' instead of runlevels. By default, there are two main targets: # # multi-user.target: analogous to runlevel 3 # graphical.target: analogous to runlevel 5 # # To view current default target, run: # systemctl get-default # # To set a default target, run: # systemctl set-default TARGET.target
可以看到,里面除了注释,什么也没有,并没有CentOS 6中设置默认运行级别的方式。
注释内容大意是说,
# Multi-user.target 3 similar runlevel; # graphical.target similar runlevel5
Get the current mode is the default run level
systemctl get-default
Set the default run level way
systemctl set-default TARGET.target
Set run level command format:
systemctl [command] [unit.target]
Commands need systemctl
to set the default level is a run command: systemctl set-default xxx
the level corresponds to the system is
init target level systemctl 0 shutdown.target . 1 emergency.target 2 rescure.target . 3 multi-user.target . 4 no . 5 graphical.target . 6 None
Note: The above commands require super administrator privileges, if you need to temporarily switch directly init
+ need to switch to digital.
The default system run level specified in systemd System of /etc/systemd/system/default.target file, it does not apply to SysVinit system:
[Linuxidc linuxidc.com @ localhost] $ cat /etc/systemd/system/default.target