Which command will display both the current runlevel and the previous runlevel?

A system's run level (also known as an init state) defines what services and resources are available to users. A system can be in only one run level at a time.

The release has eight run levels, which are described in the following table. The default run level is specified in the /etc/inittab file as run level 3.

Table 6-2 Oracle Solaris Run Levels

Run Level

Init State

Type

Purpose

0

Power-down state

Power-down

To shut down the operating system so that it is safe to turn off power to the system.

s or S

Single-user state

Single-user

To run as a single user with some file systems mounted and accessible.

1

Administrative state

Single-user

To access all available file systems. User logins are disabled.

2

Multiuser state

Multiuser

For normal operations. Multiple users can access the system and all file system. All daemons are running except for the NFS and SMB server daemons.

3

Multiuser level with NFS resources shared

Multiuser

For normal operations with NFS and SMB resources shared. This is the default run level.

4

Alternative multiuser state

Multiuser

Not configured by default, but available for customer use.

5

Power-down state

Power-down

To shut down the operating system so that it is safe to turn off power to the system. If possible, automatically turns off power on systems that support this feature.

6

Reboot state

Reboot

To shut down the system to run level 0, and then reboot to multiuser level with NFS and SMB resources shared (or whatever level is the default in the

inittab

file).

In addition, the svcadm command can be used to change the run level of a system, by selecting a milestone at which to run. The following table shows which run level corresponds to each milestone.

Table 6-3 Run Levels and SMF Milestones

Run Level

SMF Milestone FMRI

S

milestone/single-user:default

2

milestone/multi-user:default

3

milestone/multi-user-server:default

When to Use Run Levels or Milestones

In general, changing milestones or run levels is an uncommon procedure. If it is necessary, using the init command to change to a run level will change the milestone as well and is the appropriate command to use. The init command is also useful for shutting down a system.

However, booting a system by using the none milestone can be very useful when you are debugging startup problems. There is no equivalent run level to the none milestone. See How to Boot Without Starting Any Services for specific instructions.

Determining a System's Run Level

Display run level information by using the who -r command.

$ who -r

Use the who -r command to determine a system's current run level for any level.

Example 6-1 Determining a System's Run Level

This example displays information about a system's current run level and previous run levels.

$ who -r
 .    run-level 3  Dec 13 10:10  3  0 S
$

Output of

who -r

command

Description

run-level 3

Identifies the current run level

Dec 13 10:10

Identifies the date of last run level change

3

Also identifies the current run level

0

Identifies the number of times the system has been at this run level since the last reboot

S

Identifies the previous run level

Copyright © 1998, 2011, Oracle and/or its affiliates. All rights reserved. Legal Notices

Which command will display both the current runlevel and the previous runlevel?
Which command will display both the current runlevel and the previous runlevel?

A run level is an operating system state on Linux system.There are seven runlevels exist, numbered from zero to six.A system can be booted into any of the given runlevel. Run levels are identified by numbers.

Each runlevel designates a different system configuration and allows access to a different combination of processes.By default Linux boots either on runlevel 3 or runlevel 5.

Only one runlevel is executed at a time on startup. It doesn’t execute one after another.The default runlevel for a system is specified in the /etc/inittab file for SysVinit system.

But systemd systems doesn’t read this file and it uses the following file /etc/systemd/system/default.target to get default runlevel information.

We can check the Linux system current runlevel using the below five methods.

  • runlevel Command: runlevel prints the previous and current runlevel of the system.
  • who Command: Print information about users who are currently logged in. It will print the runlevel information with “-r” option.
  • systemctl Command: It controls the systemd system and service manager.
  • Using /etc/inittab File: The default runlevel for a system is specified in the /etc/inittab file for SysVinit System.
  • Using /etc/systemd/system/default.target File: The default runlevel for a system is specified in the “/etc/systemd/system/default.target” file for systemd System.

Detailed runlevels information is described in the below table.

Runlevel SysVinit System systemd System
0 Shutdown or Halt the system shutdown.target
1 Single user mode rescue.target
2 Multiuser, without NFS multi-user.target
3 Full multiuser mode multi-user.target
4 unused multi-user.target
5 X11 (Graphical User Interface) graphical.target
6 reboot the system reboot.target

The system will execute the programs/service based on the runlevel.

For SysVinit system, it will be execute from the following location.

  • Run level 0 – /etc/rc.d/rc0.d/
  • Run level 1 – /etc/rc.d/rc1.d/
  • Run level 2 – /etc/rc.d/rc2.d/
  • Run level 3 – /etc/rc.d/rc3.d/
  • Run level 4 – /etc/rc.d/rc4.d/
  • Run level 5 – /etc/rc.d/rc5.d/
  • Run level 6 – /etc/rc.d/rc6.d/

For systemd system, it will be execute from the following location.

  • 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) How to check your current Runlevel in Linux using runlevel Command?

runlevel prints the previous and current runlevel of the system.

$ runlevel
N 5
  • N: “N” indicates that the runlevel has not been changed since the system was booted.
  • 5: “5” indicates the current runlevel of the system.

2) How to check your current Runlevel in Linux using who Command?

Print information about users who are currently logged in. It will print the runlevel information with -r option.

$ who -r
         run-level 5  2019-04-22 09:32

3)How to check your current Runlevel in Linux using systemctl Command?

systemctl is used to controls the systemd system and service manager. systemd is system and service manager for Unix like operating systems.

It can work as a drop-in replacement for sysvinit system. systemd is the first process get started by kernel and holding PID 1.

systemd uses .service files Instead of bash scripts (SysVinit uses). systemd sorts all daemons into their own Linux cgroups and you can see the system hierarchy by exploring /cgroup/systemd file.

$ systemctl get-default
graphical.target

4) How to check your current Runlevel in Linux using /etc/inittab File?

The default runlevel for a system is specified in the /etc/inittab file for SysVinit System but systemd systemd doesn’t read the files.

So, it will work only on SysVinit system and not in systemd system.

$ 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) How to check your current Runlevel in Linux using using /etc/systemd/system/default.target File?

The default runlevel for a system is specified in the /etc/systemd/system/default.target file for systemd System.

Note : It doesn’t work on SysVinit system.

$ 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

Which command will display both the current run level and the previous run level?

Use the runlevel command /sbin/runlevel to find the current and previous runlevel of an operating system. Runlevels zero through six are generally delegated to single-user mode, multi-user mode with and without network services started, system shutdown and system reboot.

Which command displays the current runlevel for a system?

runlevel Command: runlevel prints the previous and current runlevel of the system. who Command: Print information about users who are currently logged in. It will print the runlevel information with “-r” option. systemctl Command: It controls the systemd system and service manager.

Which command is used to change runlevel in Linux?

Type init X and press Enter, where X is replaced by the run level you want to change to. Note: If this command does not work, refer to the manual for your distribution of Linux. Caution: This command exits all running applications.

What is the default run level in Linux?

The default run level is specified in the /etc/inittab file as run level 3. To shut down the operating system so that it is safe to turn off power to the system. To run as a single user with all file systems mounted and accessible. To access all available file systems with user logins allowed.