Skip to main content
LPIC-1 Exam 101

101.3 Change Run Levels and Shutdown or Reboot the Linux System

By August 23, 2013September 12th, 2022No Comments

booting LinuxIn this lesson, we have a few videos for you to look at and we are starting to really understand how Linux works. By the end of this section we are going to be able to reboot and shutdown the system in a number of ways. Notifying users if it is applicable. Additionally, we are also going to learn all about different run levels or targets that are used to control which services should start on the system boot. We will see how we can change run levels and targets and why we would do so.

Run levels


Often we do not need to concern ourselves too much with run levels. Servers will often boot to run level 3 where we only have text consoles and desktops will boot to run level 5 where we have the GUI. We do need to become involved until it all goes wrong. Perhaps the video card in a desktop is playing up and we need to boot to a text console only to fix the system, We can boot to run level 3 and this would allow us to log in. This is similar behaviour that you have in a Windows system where you may hit the F8 key during boot to enter a safe mode. On later systems, the term Run Level is replaced with target. For run level 5 we now have a Graphical Target and Run Level 3 would be a Multi-User Target. These later systems include CentOS7, Ubuntu 16.04 and openSUSE 42.

The following  details run level on Linux Systems

  • 0 Halt
  • 1 Single-User
  • 2 Multi-User without networking services
  • 3 Multi-User
  • 4 Not used
  • 5 Multi User with X server
  • 6 Reboot

Default Run Level

When the system boots without a specific run level specified within the kernel options, the system will boot to the default run level which has traditionally been defined within the /etc/inittab file and continues on many systems today as the method to configure the default run level

Change Run Levels

From the screenshot, we can see that this system would boot to run level 5, the GUI XServer mode.

Specifying the Default Run Level on Ubuntu 14.04 and Earlier

After many years of little change in Linux we, as administrators, now have a few changes making their way into Enterprise Linux distributions. Upstart is a welcome change to the sysinit scripts we have been used to over the last 20 years. However, as with all change, there is a little readjustment and we no longer have the /etc/inittab file in Ubuntu Server 12.04. If we need to set the default run level then we now edit the /etc/init/rc-sysinit.conf where we can see the line :

env DEFAULT_RUNLEVEL=2

On Red Hat 6 and CentOS 6 systems and later the /etc/inittab file is only used only for the configuration of the default run level

Traditional System V Run Level Directories

On the traditional Linux systems where the standard System V init scripts are still in use , and this includes all modern distributions, each run level is represented by a directory containing symbolic links to the actual scripts that start on stop the services. On Red Hat and CentOS these directories are in /etc/rc.d:

This is similar on SUSE 11 and earlier, except the run level directories are in the directory /etc/init.d . This shows that Linux distributions are very similar, the art is just being able to discover the needs of a particular system. A good analogy is life were we can keep friends by knowing what they need and like 🙂

Where these run level directories are employed, on both SUSE and Red Hat Enterprise Linux, the will contain symbolic links to the service scripts in /etc/init.d. The symbolic links will start with either a K or an S. Symlinks starting with an S are linked when entering the run level and use the start the service, when leaving the run level the K symlinks are invoked to stop services.

Using Shutdown

Sometimes it is more desirable to give users some warning of an impending shutdown or reboot , root or users who have been designated permissions within the /etc/sudoers files can use the shutdown command and schedule the shutdown or reboot at a future time or in so many minutes. Messages will be displayed to users prior to the event.

shutdown -r +5  : reboot in 5 minutes
shutdown -h 14:30 : halt at 2.30 in the afternoon

We can also use shutdown -r now to immediately reboot or shutdown -h now to halt immediately.

Upstart

I have been using Linux now for more years than I can remember and I have been used, for many of those years, to the System V init daemon and scripts. Since 2009 Ubuntu have been converting their services to use Upstart. This has been a feature of Ubuntu 6.10 later and Fedora 9 and later. With this process configuration files are created in the /etc/init directory and these files maintain, if you like, the configuration of the service startup through “start on” and “stop on” stanzas. We no longer require the symlinks in the rc directories to control autostart of a service. We also can leave chkconfig, insserv and service behind and in this video we will show you how it all come together.

For the admin /sbin/initctl can take the place of chkconfig and service in the original Sys V systems that we have been used to:

Systemd

In most current Linux Distributions, systemd is the default system and startup manager. Services can be managed and enabled using the tool systemctl. If you are using current versions of Fedora, Red Hat, openSUSE, CentOS, Debian or Ubuntu you will mow have a systemd based device. The video shows this on an early openSUSE 12.1 system.