Understanding Linux Runlevels
In Linux, a runlevel is a mode of operation that defines what services and processes are running on the system. Each runlevel is assigned a specific purpose, such as system shutdown, single-user mode, or multi-user mode.
Common Runlevels
- 0: Halt the system (shutdown).
- 1: Single-user mode (maintenance mode).
- 2: Multi-user mode without networking.
- 3: Multi-user mode with networking (text-based).
- 4: Undefined (custom use).
- 5: Multi-user mode with networking and graphical interface (GUI).
- 6: Reboot the system.
How to Change Runlevels
To change the runlevel in Linux, you can use the telinit or systemctl command, depending on your system's init system.
Using telinit Command
For systems using SysVinit, you can change the runlevel with the telinit command:
sudo telinit
Example: To switch to runlevel 3 (multi-user mode with networking):
sudo telinit 3
Using systemctl Command
For systems using systemd, you can change the runlevel by switching the target:
sudo systemctl isolate .target
Example: To switch to graphical mode (runlevel 5 equivalent):
sudo systemctl isolate graphical.target
To switch to multi-user mode (runlevel 3 equivalent):
sudo systemctl isolate multi-user.target
To switch to single-user mode (runlevel 1 equivalent):
sudo systemctl isolate rescue.target
Checking the Current Runlevel
To check the current runlevel, use the following command:
runlevelorsystemctl get-defaultorwho -r
The output will show the previous and current runlevels.