Linux Changing Run Levels Command

Linux Changing Run Levels Command For Sysv and Systemd init
This page explains how to change the run level under Linux and how it affects Linux users.

Advertisement

What is a Linux Runlevels?

Runlevels are a state, defined by the services listed in the SysV /etc/rc.d/rc?.d/ directory, where ? is the number of the runlevel. The following runlevels are defined by default for Linux starting from number 0:

SysV runlevels number Description
0 Halt or shutdown the Linux system
1 Single-user text mode (useful for maintenance mode)
2 Not used
3 Full multi-user text mode (used on Linux servers)
4 Not used
5 Full multi-user GUI mode. You can use X-based login screen. Useful for Linux desktop
6 Reboot Linux system

Suppose you are moving to higher run levels. You may make additional services available to users while moving to a lower run level will cause services (daemons) to become unavailable. For example, the production server run level 3 is typically used and rarely changed. However, some administrative tasks require the system administrator to move the system to run level 1, i.e. single-user mode.

systemd as init

These days most modern and popular Linux distros such as Ubuntu, Debian, Suse, RHEL, CentOS, Fedora, Alma, Rocky, Arch and others use systemd as init instead of older SysV init or Upstart. So runleves numbered from 0 to 6 were replaced with systemd targets. Here is a quick table indicating new changes:

SysV runlevels number Systemd targets Description
0 runlevel0.target
poweroff.target
Halt or shutdown the Linux system
1 runlevel1.target
rescue.target
Single-user text mode (useful for maintenance mode)
2 runlevel2.target
multi-user.target
Not used
3 runlevel3.target
multi-user.target
Full multi-user text mode (used on Linux servers)
4 runlevel4.target
multi-user.target
Not used
5 runlevel5.target
graphical.target
Full multi-user GUI mode. You can use X-based login screen. Useful for Linux desktop
6 runlevel6.target
reboot.target
Reboot Linux system

The side effect of using the systemd is some command names are changed.

Linux Find Out Current Run Level Command

Type the following who command or runlevel command when using the SysV init:
$ runlevel
## OR ##
$ who -r

Sample outputs:

         run-level 2  2011-10-12 05:38   

Systemd init user run the systemctl command:
$ systemctl get-default
Here is what I see on Ubuntu 20.04 LTS:

graphical.target

Linux Changing Run Levels Command When Using the SysV init

Use the init command or telinit command to change rune levels when using the SysV as init. The following will change runlevel to 1. In other words, go to a single-user text mode:
# init 1
## OR poweroff using runlevel number '0' ##
# telinit 0

A note about the systemd users – Linux Change Run Levels Command

Similarly, the systemd init user can switch to a rescue (maintenance) mode using the systemctl command:
# systemctl rescue
Here are other commands for the systemd init users:
# systemctl reboot #<--Reboot the system
# systemctl poweroff #<--Power off the system
# systemctl emergency #<--Put in emergency mode
# systemctl default #<--Back to default target

Runlevel And Its Usage (SysV Init)

The Init is the parent of all processes with PID # 1. Its primary purpose is to create processes from a script stored in the file /etc/inittab file. This file usually has entries which cause init to spawn gettys on each line that users can log in. A runlevel is nothing but a software configuration of the Linux system which allows only a selected group of processes to exist. The processes spawned by init for each of these runlevels are defined in the /etc/inittab file. Init can be in one of eight runlevels as follows:

  • Runlevel 0 is halt
  • Runlevel 1 is single-user
  • Runlevels 2-5 are multi-user (some distro uses RUN level 5 to start X [KDE/Gnome])
  • Runlevel 6 is for rebooting system

For example, typing the init 3 command will move system to run level 3:

# init 3

On most Linux server system default run level is 3 and on most Linux Desktop system default run level is 5. The default run level is defined by the initdefault line at the top of /etc/inittab file under CentOS / Fedora / Redhat / RHEL / Debian Linux. To change the default run level, edit /etc/inittab file, and edit entry initdefault using a text editor such as vim command:

# vi /etc/inittab

Set initdefault to 5, so that you can boot to X next time when Linux comes up:

id:5:initdefault:
Save and close the file under vim text editor. Reboot the Linux system to see changes:
# reboot
You can use the cat command or grep command to view it too:
# grep initdefault /etc/inittab
Again, the systemd init users see “how to switch boot target to text or GUI in systemd Linux” for more info. For example:

# 01. Find which target unit is used by default:
sudo systemctl get-default
 
# 02. To change boot target to the text mode:
sudo systemctl set-default multi-user.target
 
# 03. Reboot the system using the reboot command:
sudo systemctl reboot

More About getty

The getty is the program which opens a tty port, prompts for a login name and password (via /bin/login command). Your console displays a login/password prompt at run levels 1 through 6. You can use ALT+F1…ALT+F6 keys to switch console (use CTRL+ALT+F1..F6 under X windows). SSH logins are handled by OpenSSH (sshd) server which starts at run level 2/3. KDE/Genome Desktop login are handled by GDM/XDM/KDM display manager which starts at run level 5 (however Debian Linux and some other distro can start them from run level 2 via special rc.d script located in /etc/init.d/gdm)

Summing up

That is all for today’s blog post about SysV init runlevels. I revised this post to include information about systemd init. The SysV init users read the following manual pages using the help command or man command:
$ man init
$ man telinit
$ man 5 inittab

The systemd init users must use the newer commands instead of the telinit or init. For example:
$ man systemctl

See also

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

23 comments… add one
  • matt Oct 17, 2005 @ 14:38

    you have some good content! i’m reading this blog since last 4+ months; althoug it is not updated daily like other blog/sites still it makes a good read as it is based upon Linux/UNIX sys admins hard core experince
    considering only 1 or 2 perople contributes to this blog it is a good read and you have Good number of hits as well. Just wanna say good job man & keep it up

  • Anonymous Oct 17, 2005 @ 14:44

    my questions is very simple how do i find out current runlevel as well as last runlevel? since you take linux sys admin class you must have some info 😀

    –bha

    • Namdev Oct 27, 2012 @ 12:02

      RUN-LEVEL IN LINUX
      ==================
      0 – halt (shutdown pc)
      1 – Single user mode
      2 – Multiuser
      3 – Full multiuser mode
      4 – unused
      5 – X11 (Graphical)
      6 – reboot

      TO VIEW RUNLEVEL CONFIG FILE

      # cat /etc/inittab

      TO CHANGE RUNLEVEL CONFIGURATION FILE
      # vi /etc/inittab

      To check Current Run Level
      # who -r or
      # runlevel

      To change Run Level
      # init 1

      On most Linux server system default run level is 3 and on most Linux Desktop system default run level is 5.

      • narendra Apr 30, 2013 @ 5:57

        if it is set as 0, then how to change as system get reboot again and again
        kindly advice

        • vivek Nov 4, 2015 @ 16:58

          I guess you can use any live distro to boot into your system and then access the drive and then change the default runlevel from the file it is contained.

  • cyberciti Oct 17, 2005 @ 18:31

    > how do i find out current runlevel as well as last runlevel?
    Use who -r command
    $ who -r
    run-level 2 Oct 17 18:21 last=S

    • Ronald Kaiser Apr 9, 2012 @ 14:24

      In order to get the last runlevel as well as the current, you can use /sbin/runlevel too.
      $ /sbin/runlevel
      S 2

  • cyberciti Oct 17, 2005 @ 18:34

    Thanks matt 🙂 We don’t update our blog everyday, as and when event occurs in our life it is get documented here.

    I appreciate your post.

  • srikar Mar 5, 2013 @ 9:55

     How to Change the run levels of the linux at run time with out restarting the system

  • Tony S. May 20, 2013 @ 11:52

    Thanks, this really helped me out. It turns out Ubuntu does have both commands, albeit a bit useless due to it lacking a proper single-user bootmode that’s accessible, this still helped. Thanks very much.

  • Rajesh May 20, 2013 @ 14:04

    I went and changed the default run level as 6 in the config files. now system starts with default mode as 6 and then restarts again.

  • Guignol Jun 13, 2013 @ 18:21

    For the folks fool enough to edit their /etc/inittab config file to 0 or 6, your only way to break the loop is to boot the system from a livecd, then navigate to the config file through the live filesystem (probably /mnt/sd*/etc/inittab or /media/*) and edit it. But seriously, what were you expecting to happen?

  • air805ronin Jan 8, 2014 @ 23:01

    Guignol is actually kind of wrong there. A better option, to me, would to use Grub to boot into a specific runlevel, and then edit the inittab file to fix your mistake.

    Just google “grub change runlevel” and you should get some useful results.

  • ashwin Sep 15, 2015 @ 6:08

    i have set default as 6, then how to change as system get reboot again and again
    kindly advice

    • Addams Scrub Oct 20, 2016 @ 11:29

      Try to avoid 0 and 6 .. Put 5 for example.

      As someone said before in the documentation:
      0 – halt (shutdown pc)
      1 – Single user mode
      2 – Multiuser
      3 – Full multiuser mode
      4 – unused
      5 – X11 (Graphical)
      6 – reboot

      If you are on 6, the system will reboot on and on.
      If you want to use Linux desktop and graphics try setting runlevel to 5
      If you have a Linux server, try 3
      You can change your runlevel by typing ‘init 5’ from bash cli.
      init 5
      init 3

  • ashwin Sep 15, 2015 @ 6:09

    i have set default as 6,
    system stops and says noting to do
    pls help hoe to over come this issue

  • satish Feb 16, 2016 @ 9:59

    Under Red Hat Enterprise Linux, it is possible to change the default runlevel at boot time.

    To change the runlevel of a single boot session, use the following instructions:

    When the GRUB menu bypass screen appears at boot time, press any key to enter the GRUB menu (within the first three seconds).

    Press the a key to append to the kernel command.

    Add at the end of the boot options line to boot to the desired runlevel. For example, the following entry would initiate a boot process into runlevel 3:

  • Ava Jan 13, 2017 @ 8:50

    I know this page is from 2000, but this page needs refreshments as systemd targets are represented by target units and are the new init.

    • Aabirah Feb 14, 2018 @ 13:13

      Hi Vivek, I am with Ava. Could you please add at least a note about systemctl commands?

      • Murphy Apr 28, 2022 @ 3:02

        +++1. Come on, my man. We need updating.

  • sruthi Mar 13, 2017 @ 5:29

    Why do we need to reboot to change the run level ?

    • Robin Apr 3, 2017 @ 2:00

      I guess it’s for when you configured the wrong target (runlevel) as default.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.