What are Linux Runlevels?

July 24, 2018 | Views: 3585

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

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
4 Not Used
5 Full Multi-user with Networking and X Windows (GUI)
6 Reboot.

SYSTEMD

In 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.

SYSTEMD Chart

  • 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:

/etc/init/rc-sysinit.confUbuntu (Non Systemd)

/etc/inittabRedhat/Centos

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 /etc/rc.d/, 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 .

Conclusion

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 or email me.

 

 

Share with Friends
FacebookTwitterGoogle+LinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterGoogle+LinkedInEmail
Ready to share your knowledge and expertise?
1 Comment
  1. This is a great explanation of run levels. Straight to the point.

Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play
 

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel