Linux and Unix utilize runlevels to enable certain functionalities from single user mode to GUI mode.These runlevels cater to different needs for system administrators and for troubleshooting.You can set a default runlevel to, say, boot the CLI instead of the GUI. On servers, you generally would use Runlevel 3, which is the multi-user mode that only gives you access to the GUI. But if you want to use the GUI, then you can raise your runlevel to Runlevel 5, which will enable the full GUI.The following is a chart of runlevels that apply to Linux and Unix:
|0||Halt the system.|
|1||Single-user mode (for special administration).|
|2||Local Multi-user with Networking but without network service (like NFS)|
|3||Full Multi-user with Networking|
|5||Full Multi-user with Networking and X Windows (GUI)|
SYSTEMDIn systemd, the runlevels are slightly different. Runlevels are targets, and in order to enable a target, you will use the systemctl command to enable the target.
Runlevel 0 is matched by poweroff.target (and runlevel0.target is a symbolic link to poweroff.target).
Runlevel 1 is matched by rescue.target (and runlevel1.target is a symbolic link to rescue.target).
Runlevel 3 is emulated by multi-user.target (and runlevel3.target is a symbolic link to multi-user.target).
Runlevel 5 is emulated by graphical.target (and runlevel5.target is a symbolic link to graphical.target).
Runlevel 6 is emulated by reboot.target (and runlevel6.target is a symbolic link to reboot.target).
Emergency is matched by emergency.target. Checking the current default runlevel in systemd
- systemctl get-default
As you can see from the above chart, you can issue a run-level, i.e., 0, which would halt, or shutdown the system. This is obviously the lowest level to which the system can go. Then the higher the runlevel, the more the functionality.You can see why you would use Runlevel 3 for a server environment: The base install of Ubuntu
server without a GUI installed, such as GNOME
or KDE, would go to a max runlevel of 3.You can change the default runlevel of your system and you can change the following file:
- Ubuntu (Non Systemd)
sudo systemctl enable multi-user.target - SystemD You would definitely NOT want to change your default runlevel to 0 or 6. That would be bad and result in a system that either shuts down right away or reboots right away, which is not very useful.You can also add scripts that run at certain runlevels. If you go to
you will see folders, such as
init.d/ rc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/.
You can add scripts to these folders, and the scripts will be called when that runlevel is initiated.You can also change runlevels by running a command in the terminal runlevel 1,2,3 etc .
I hope this helps you understand runlevels. If you have any questions, please let me know!Check out my Youtube
video with a demo of this in action!For this and other topics, visit my blog at www.seanmancini.com