linux 运行级别

运行级别(Runlevel) 指的是Unix或者Linux等类Unix操作系统下不同的运行模式。运行级别通常分为7等,分别是从0到6,但如果必要的话也可以更多。

例如在大多数Linux操作系统下一共有如下7个典型的运行级别:

  • 0 停机,关机
  • 1 单用户,无网络连接,不运行守护进程,不允许非超级用户登录,通常别称为s或S
  • 2 多用户,无网络连接,不运行守护进程
  • 3 多用户,正常启动系统
  • 4 用户自定义
  • 5 多用户,带图形界面
  • 6 重启

查看运行级别

runlevel

root@g:~# runlevel
N 5
  1. N:“N”表示自系统启动后运行级别尚未更改。
  2. 5:“5”表示系统的当前运行级别。

who -r

root@g:~# who -r
         run-level 5  2019-08-26 09:59

systemctl

root@g:~# systemctl get-default
graphical.target

输出的结果不是数据来的, 有:

multi-user.target: analogous to runlevel 3
graphical.target: analogous to runlevel 5

/etc/inittab

系统的默认运行级别在SysVinit System的/etc/inittab文件中指定,但systemd systemd不读取文件,因此,它仅适用于SysVinit系统而不适用于systemd系统:

$ cat /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:

/etc/systemd/system/default.target

系统的默认运行级别在systemd System的/etc/systemd/system/default.target文件中指定,它不适用于SysVinit系统:

$ cat /etc/systemd/system/default.target
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service
AllowIsolate=yes

运行级别
运行级别、关机和重启
Linux:检查当前运行级别的五种方法

  • qq_43638135
    妲己再美究为妃: 博主没有想过自己接一些私活干吗?我现在还没毕业,但是我也确实听说外挂市场自动化游戏脚本市场挺火热的,并且报酬也很丰厚,但是具体的我也不是很清楚,求解答。 (1个月前 #47楼) 查看回复(2) 举报 回复
    22