Linux get current runlevel

How to Check and Set Linux Runlevels

Runlevel today implemented on systemd, previously most Linux distributions were equipped with the init system, Sys-V style. Sys-V used seven different runlevels to determine which processes can be started on the system. For example, runlevel 3 was usually reserved for the command line and associated programs, while runlevel 5 launched a GUI and all the processes required to do so. Results may vary by distribution.

The vast majority of Linux distributions have adopted systemd as their init system. Some distributions still use Sys-V where the traditional implementation of runlevels still exists. The systemd implementation adopted the concept of runlevels, converting them to systemd “targets”.

On some systems there are still scraps of Sys-V, on which commands such as runlevel can still be found. But some modern systemd distributions have completely eradicated this support. In this tutorial we show how to check the current runlevel on Linux.

How to check current runlevel?

Below are two commands to determine the current runlevel.

$ runlevel N 5 $ who -r run-level 5 2022-11-07 14:52

As you can see, runlevel 5 has started here. Alternatively, the command who -r can be ran. The runlevel command is only available on some systemd distributions, but should work on any sys-V system.

The different runlevels were assigned to corresponding systemd targets.The following command can be used to check the targets.

$ ls -l /lib/systemd/system/runlevel*

Below is the output of the runlevels at a Linux Mint, which is based on Ubuntu/Debian.

$ lrwxrwxrwx 1 root root 15 Aug 31 17:27 /lib/systemd/system/runlevel0.target -> poweroff.target lrwxrwxrwx 1 root root 13 Aug 31 17:27 /lib/systemd/system/runlevel1.target -> rescue.target lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel2.target -> multi-user.target lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel3.target -> multi-user.target lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel4.target -> multi-user.target lrwxrwxrwx 1 root root 16 Aug 31 17:27 /lib/systemd/system/runlevel5.target -> graphical.target lrwxrwxrwx 1 root root 13 Aug 31 17:27 /lib/systemd/system/runlevel6.target -> reboot.target /lib/systemd/system/runlevel1.target.wants: Total 0 /lib/systemd/system/runlevel2.target.wants: Total 0 /lib/systemd/system/runlevel3.target.wants: Total 0 /lib/systemd/system/runlevel4.target.wants: Total 0 /lib/systemd/system/runlevel5.target.wants: Total 0

Runlevels in Linux

0 Halt shut down the system
1 Single-user mode (Rescue and special administration)
2 Multi-user mode not start network interfaces and daemons
3 Multi-user mode with Networking starts system normally
4 Not Used
5 Multi-user mode as runlevel 3 + display manager X11 GUI
6 Reboot the system
Читайте также:  Сетевое администрирование unix linux

As with runlevels, there are 7 systemd targets by default. The two main targets are multi-user.target and graphical.target. The following command displays the default systemd targets.

$ systemctl get-default graphical.target

In this example, graphical.target is started, which makes sense because we need a graphical desktop environment. On a server where often no GUI is running, multi-user.target is usually started.

$ systemctl get-default multi-user.target

Use the command to see which services are associated with this target.

$ systemctl list-dependencies graphic.target graphic.target

Try the following command to see which systemd target (or runlevel) a service needs to run.In this example, we check the SSH service.

$ systemctl show -p WantedBy sshd.service WantedBy=multi-user.target

How to set runlevel?

The runlevel can be set with this command.

$ sudo systemctl set-default multi-user.target

The next time the system boots in multi-user mode (multi-user.target).

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Tell us how we can improve this post?

Источник

How can I see or change default run level?

In the Linux / Unix administration handbook it mentions that you can edit the /etc/inittab file to change the run level. I don’t have that file on 10.04. I Googled this and found a tip saying that file had been replaced with /etc/event.d/rc-default — however I don’t have that file on my system either. Have these been deleted or does 10.04 deal with run levels differently?

4 Answers 4

Yes, it deals with them differently.

To see the current (and previous) runlevel:

The init you are reading about was replaced by upstart starting with Edgy Eft 6.10; and, one of the programs provided by upstart is its own implementation of init. Here are the docs for 10.04.

To change the default runlevel, use your favorite text editor on /etc/init/rc-sysinit.conf.

sudo vim /etc/init/rc-sysinit.conf 

Change this line to whichever runlevel you want.

Читайте также:  Astra linux вход доменным пользователем windows

Then, at each boot, upstart will use that runlevel.

To See the Current Run Level Command:

$ who -r or $ runlevel

If you want chance the runlevel Command

$ sudo init 1 ( it will take to u single user mode)

This are differnt runlevel you can perform :

0 — System halt; no activity, the system can be safely powered down.

1 — Single user; rarely used.

2 — Multiple users, no NFS (network filesystem); also used rarely.

3 — Multiple users, command line (i.e., all-text mode) interface; the standard runlevel for most Linux-based server hardware.

5 — Multiple users, GUI (graphical user interface); the standard runlevel for most Linux-based desktop systems.

6 — Reboot; used when restarting the system.

This is an old thread, but no matter. @Premkumar, yr answer applies more to Unix type specifications such as the Lx Standard Base (LSB) than to Debian GNU Lx or Ubuntu for that matter. Check the run level of yr Ubuntu type distro and you will see that it is probably 2 or perhaps 1, in rare cases where a single user mode runlevel is preferred. See this Wiki for a detailed description. In Ubuntu, Runlevel 2 is for «Graphical multi-user with networking». The Wiki holds descriptions for many distros.

Normally this is done by explicitly adding a number to the kernel options in the GRUB entry.

Let’s say, you want to change default grub entry from default run level (5) to 3:

Find a place of default boot entry, and have a look at linux line. Might look something like this:

linux /boot/vmlinuz-3.0.0-13-generic root=UUID=d07e0c99-65ba-4eda-98d8-79693dc79554 ro quiet splash vt.handoff=7 

Add 3 at the end of that line:

linux /boot/vmlinuz-3.0.0-13-generic root=UUID=d07e0c99-65ba-4eda-98d8-79693dc79554 ro quiet splash vt.handoff=7 3 

You could also make use of the corresponding target of your desired runlevel. You can check which of the available target your system is running as default using:

Supposing the graphical.target is the default, you can further check its definition and detailed information using: systemctl cat graphical.target . There are some target units tailored after the corresponding runlevels. You can find which of them are available on your system by listing them: systemctl list-unit-files -t target Suppose you want to set runlevel 2 as default, you can do this by running:

sudo systemctl set-default runlevel2.target 

You should use this with caution and make sure you are not causing any issues running on the inappropriate target.

Читайте также:  Raspberry pi это linux

Источник

How to check your current Runlevel in Linux

Runlevel is the operating system state on Linux system (it dictates the state that the machine is currently operating, and what applications or services can run at that time). There are seven (7) run levels numbered from 0 to 6. A system can be booted into any of the given runlevel. Runlevels are identified by numbers. By default, a system boots either to runlevel 3 or to runlevel 5. Runlevel 3 is CLI, and 5 is GUI. There are different commands that can show the current run level state on a server.

Using /etc/inittab File
– The default runlevel for a system is specified in the /etc/inittab file

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.

The following details show what each of the default runlevels represent. These are the standard definitions which may be slightly different depending on your Linux distribution.

  • 0 – is described as Halt. your machine will halt when the runlevel is set to 0.
  • 1 – is single-user Mode which is used for administrative tasks before the non-essential services are started.
  • 2 – is the first multi-user mode runlevel and will start some non-essential services. This may, or may not contain networking depending on your Linux distribution.
  • 3 – is a multi-user mode which headless servers usually run at. All essential and non-essential services such as Apache HTTP Server should be running.
  • 4 – is a multi-user mode runlevel which is not used by the default operating system and can be used for user defined purposes.
  • 5 – is when GUI desktops are loaded such as Gnome or KDE.
  • 6 – is the reboot runlevel. the operating system will reboot when runlevel 6 is issued.

I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.

Источник

Оцените статью
Adblock
detector