Understanding and managing runlevels is an essential skill for Linux administrators. Runlevels determine the state of the machine after booting, such as whether it starts with a graphical interface or in a multi-user mode. This article provides a comprehensive guide on how to check and change the default runlevel in Ubuntu Linux.
In this tutorial you will learn:
- What runlevels are and their history
- Different runlevels available in Ubuntu Linux
- How to check the current runlevel
- How to change the runlevel temporarily
- How to change the runlevel permanently
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Ubuntu Linux |
Software | systemd |
Other | Basic knowledge of Linux command line |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How to Check and Change the Default Runlevel on Ubuntu Linux
Runlevels are a legacy from UNIX System V, which define the state of a Unix-based operating system. Each runlevel represents a different mode of operation, from shutdown mode to full multi-user mode. Traditionally, Linux systems had seven runlevels, numbered from 0 to 6. With the advent of systemd, the concept of runlevels has been largely replaced by “targets,” but the fundamental principles remain the same.
Here is a brief overview of the traditional runlevels:
- 0 – Halt (shutdown)
- 1 – Single-user mode
- 2 – Multi-user mode without networking
- 3 – Multi-user mode with networking
- 4 – Undefined
- 5 – Multi-user mode with GUI
- 6 – Reboot
Below is a list of current systemd targets that are equivalent to traditional runlevels:
- poweroff.target – Equivalent to runlevel 0 (Halt/Shutdown)
- rescue.target – Equivalent to runlevel 1 (Single-user mode)
- multi-user.target – Equivalent to runlevel 3 (Multi-user mode with networking)
- graphical.target – Equivalent to runlevel 5 (Multi-user mode with GUI)
- reboot.target – Equivalent to runlevel 6 (Reboot)
- Check the current runlevel and target: To determine the current runlevel of your system, you can use the
runlevel
command. This command will output the previous and current runlevel.$ runlevelThe output will display two numbers, indicating the previous and current runlevels respectively. For example, “N 5” means no previous runlevel and the current runlevel is 5.Additionally, you can check the current target using the following systemd command:$ systemctl get-defaultThis will return the name of the current default target, such as “graphical.target”.Check the current runlevel and target - List available targets: In a systemd-based system like Ubuntu, targets have replaced traditional runlevels. To see all available targets, use the following command:$ systemctl list-units –type=target –allThis command will list all the targets, including those that are inactive.https://9b00755c0d3aa7ebd80833056fb08181.safeframe.googlesyndication.com/safeframe/1-0-40/html/container.html
- Change the default runlevel (temporarily): To change the runlevel temporarily, you can switch targets using the
systemctl isolate
command. For example, to switch to multi-user mode without a graphical interface:# systemctl isolate multi-user.targetThis command will switch the system to the specified target immediately, but the change will not persist after a reboot. - Change the default runlevel (permanently): To make a permanent change to the default runlevel, use the
systemctl set-default
command. For example, to set the system to boot into multi-user mode with networking by default:# systemctl set-default multi-user.targetThis command changes the default target, so the system will boot into the specified target on the next reboot.
Conclusion
Understanding and managing runlevels (or targets in systemd terminology) is crucial for controlling the behavior of your Ubuntu Linux system. By following the steps outlined in this guide, you can check the current runlevel, switch between runlevels temporarily, and change the default runlevel permanently to suit your needs.