Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux: five ways to check the current runlevel

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The runtime level is the functional level that the Linux operating system is currently running. There are seven runlevels numbered from 0 to 6. The system can boot to any given run level. The run level is identified digitally.

Each runlevel specifies a different system configuration and allows access to different combinations of processes. By default, Linux boots to runlevel 3 or runlevel 5. Only one runlevel is executed at startup. It will not be executed one by one.

The default run level of the system is specified in the / etc/inittab file of the SysVinit system.

However, the systemd system does not read this file, and it uses the following file / etc/systemd/system/default.target to get the default run-level information.

We can use the following five methods to check the current running level of the Linux system.

Runlevel command: the previous and current runlevel of the runlevel print system.

Who command: prints information about the currently logged in user. It will print run-level information using the "- r" option.

The systemctl command: it controls the systemd system and the service manager.

Use the / etc/inittab file: the default run level of the system is specified in the / etc/inittab file of SysVinit System.

Use the / etc/systemd/system/default.target file: the default run level of the system is specified in the / etc/systemd/system/default.target file of systemd System.

Detailed run-level information is described in the following table.

The system will execute the program / service based on the run level.

1. For SysVinit system It will be executed from the following location: runlevel 0-/ etc/rc.d/rc0.d/ runlevel 1-/ etc/rc.d/rc1.d/ runlevel 2-/ etc/rc.d/rc2.d/ runlevel 3-/ etc/rc.d/rc3.d/ runlevel 4-/ etc/rc.d/rc4.d/ runlevel 5-/ etc/rc.d/rc5.d/ run Level 6-/ etc/rc.d/rc6.d/2, For systemd system It will be executed from the following location: runlevel1.target-/ etc/systemd/system/rescue.targetrunlevel2.target-/ etc/systemd/system/multi-user.target.wantsrunlevel3.target-/ etc/systemd/system/multi-user.target.wantsrunlevel4.target-/ etc/systemd/system/multi-user.target.wantsrunlevel5.target-/ etc/systemd/system/graphical.target.wants1, using the runlevel command

The previous and current run levels of the runlevel printing system:

[linuxidc@localhost linuxidc.com] $runlevel

N 5

1], N: "N" indicates that the run level has not changed since the system was started.

2], 5: "5" represents the current run level of the system.

2. Use the who command

Prints information about the currently logged-in user, which uses the-r option to print run-level information:

[linuxidc@localhost linuxidc.com] $who-r

Runlevel 5

3. Use the systemctl command

Systemctl is used to control the systemd system and service manager, and systemd is the system and service manager of the Unix operating system. It can be used as a direct replacement for sysvinit systems, and systemd is the first process for the kernel to start and maintain PID 1. Systemd uses .service files instead of bash scripts (used by SysVinit), systemd sorts all daemons into their own Linux cgroup, and you can view the system hierarchy by browsing the / cgroup/systemd file:

[linuxidc@localhost linuxidc.com] $systemctl get-defaultgraphical.target4, use / etc/inittab file

The default run level of the system is specified in the / etc/inittab file of SysVinit System, but systemd does not read files, so it applies only to SysVinit systems and not to systemd systems.

CentOS 6 modifies the default run level by modifying / etc/inittab: [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-X1room6-reboot (Do NOT set initdefault to this) id:5:initdefault: run vim / etc/inittab under CentOS 7 as follows:

[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

As you can see, there is nothing but comments, and there is no way to set the default run level in CentOS 6.

The main idea of the note is that

# multi-user.target is similar to runlevel 3 position # graphical.target is similar to runlevel5

The way to get the current default run level is

Systemctl get-default

How to set the default run level

Systemctl set-default TARGET.target

Format run-level commands:

Systemctl [command] [unit.target]

Command systemctl is required

If you set the default runlevel to 1, the command is: systemctl set-default xxx

The level corresponding to the system in is

Init level systemctl target0 shutdown.target1 emergency.target2 rescure.target3 multi-user.target4 no 5 graphical.target6 none

Note: the above commands all require Super Admin permissions. If you need to temporarily switch direct init + to the number you need to switch to.

5. Use the / etc/systemd/system/default.target file

The default run level of the system is specified in the / etc/systemd/system/default.target file of systemd System, which does not apply to SysVinit systems:

[linuxidc@localhost linuxidc.com] $cat / etc/systemd/system/default.target

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report