Linux-查看Linux系统的运行级别
运行级别基本介绍
方法1、查看Linux系统的运行级别:runlevel
命令
[root@sr ~]# runlevel # 查看运行级别
N 3 # 可以看到是运行级别3(多用户有网络)
[root@sr ~]# runlevel --help # runlevel 命令的帮助文档
runlevel [OPTIONS...]
Prints the previous and current runlevel of the init system.
--help Show this help
[root@sr ~]#
参数说明:
N
:N
表示自系统启动后,运行级别尚未更改。3
:3
表示系统的当前运行级别。
方法2、查看Linux系统的运行级别:who -r
命令
[root@sr ~]# who -r # 查看运行级别
run-level 3 2021-06-05 09:59
[root@sr ~]# who --help # who 命令的帮助文档
Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]
Print information about users who are currently logged in.
-a, --all same as -b -d --login -p -r -t -T -u
-b, --boot time of last system boot
-d, --dead print dead processes
-H, --heading print line of column headings
-l, --login print system login processes
--lookup attempt to canonicalize hostnames via DNS
-m only hostname and user associated with stdin
-p, --process print active processes spawned by init
-q, --count all login names and number of users logged on
-r, --runlevel print current runlevel # 打印当前运行级别
-s, --short print only name, line, and time (default)
-t, --time print last system clock change
-T, -w, --mesg add user's message status as +, - or ?
-u, --users list users logged in
--message same as -T
--writable same as -T
--help display this help and exit
--version output version information and exit
If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common.
If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'who invocation'
[root@sr ~]#
方法3、查看Linux系统的运行级别:查看配置文件
参考资料:【Linux】Systemd 详解
运行级别 | sysvinit系统 | systemd系统 |
---|---|---|
0 | 关机 | shutdown.target |
1 | 单用户模式 | rescue.target |
2 | 多用户模式,无网络服务 | multi-user.target |
3 | 多用户模式,有网络服务 | multi-user.target |
4 | 系统未使用,保留给用户 | multi-user.target |
5 | 图形界面 | graphical.target |
6 | 系统重启 | reboot.target |
1、sysvinit
系统:/etc/inittab
配置文件中这一行的数字:id: 5: initdefault
2、systemd
系统:
(1)systemctl get-default
命令
[root@sr ~]# cat /etc/inittab # 查看文件 /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 # multi-user.target 类似于 运行级别3
# graphical.target: analogous to runlevel 5 # graphical.target 类似于 运行级别5
#
# To view current default target, run: # 要查看当前默认target,运行下面的命令:
# systemctl get-default
#
# To set a default target, run: # 要设置默认target,运行下面的命令:
# systemctl set-default TARGET.target
#
[root@sr ~]# systemctl get-default # 查看运行级别
multi-user.target # multi-user.target 类似于 运行级别3
[root@sr ~]#
(2)查看/etc/systemd/system/default.target
配置文件
[root@sr ~]# 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=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
[root@sr ~]#
扩展知识
1、对于sysvinit
系统,它将从以下位置执行:
运行级别0 - /etc/rc.d/rc0.d/
运行级别1 - /etc/rc.d/rc1.d/
运行级别2 - /etc/rc.d/rc2.d/
运行级别3 - /etc/rc.d/rc3.d/
运行级别4 - /etc/rc.d/rc4.d/
运行级别5 - /etc/rc.d/rc5.d/
运行级别6 - /etc/rc.d/rc6.d/
2、对于systemd
系统,它将从以下位置执行:
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
参考资料:Linux:检查当前运行级别的五种方法
参考资料:P22_022_尚硅谷_Linux实操篇_实用指令 运行级别和找回root密码