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 ~]#

在这里插入图片描述

参数说明

  • NN表示自系统启动后,运行级别尚未更改。
  • 33表示系统的当前运行级别。

方法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密码

  • 19
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值