linux 运行级别 文件,在Linux操作系统中检查当前运行级别的五种方法

运行级别是Linux系统上的操作系统状态,存在七个运行级别,编号从0到6,系统可以引导到任何给定的运行级别,运行级别由数字标识,每个运行级别指定不同的系统配置,并允许访问不同的进程组合。默认情况下,Linux会引导至运行级别3或运行级别5,启动时一次只执行一个运行级别,它不会一个接一个地执行,系统的默认运行级别在SysVinit系统的/etc/inittab文件中指定,但是systemd系统不读取此文件,它使用以下文件/etc/systemd/system/default.target来获取默认的运行级别信息。

7e4d721dbcccff25d027e8517b5a87dc.png

使用以下五种方法检查Linux系统当前运行级别

1、runlevel命令:runlevel打印系统的上一个和当前运行级别。

2、who命令:打印有关当前登录用户的信息,它将使用“-r”选项打印运行级别信息。

3、systemctl命令:它控制systemd系统和服务管理器。

4、使用/etc/inittab文件:系统的默认运行级别在SysVinit System的/etc/inittab文件中指定。

5、使用/etc/systemd/system/default.target文件:系统的默认运行级别在systemd System的/etc/systemd/system/default.target文件中指定。

详细的运行级别信息如下表所示:

运行级别

SysVinit系统

systemd系统

0

关闭或暂停系统

shutdown.target

1

单用户模式

rescue.target

2

多用户,没有NFS

multi-user.target

3

完全多用户模式

multi-user.target

4

没用过

multi-user.target

5

X11(图形用户界面)

graphical.target

6

重启系统

reboot.target

系统将根据运行级别执行程序/服务。

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系统(参考: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

1、使用runlevel命令

runlevel打印系统的上一个和当前运行级别:

$ runlevel

N 5

1]、N:“N”表示自系统启动后运行级别尚未更改。

2]、5:“5”表示系统的当前运行级别。

2、使用who命令

打印有关当前登录用户的信息,它将使用-r选项打印运行级别信息:

$ who -r

run-level 5  2019-04-24 20:32

3、使用systemctl命令

systemctl用于控制systemd系统和服务管理器,systemd是Unix操作系统的系统和服务管理器。它可以作为sysvinit系统的直接替代品,systemd是内核启动并保持PID 1的第一个进程。systemd使用.service文件而不是bash脚本(SysVinit使用),systemd将所有守护进程排序到他们自己的Linux cgroup中,可以通过浏览/cgroup/systemd文件来查看系统层次结构:

$ systemctl get-default

graphical.target

4、使用/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:

5、使用/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

相关主题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值