Boot systems into different targets manually – RHCSA Objective Preparation

In this part of RHCSA exam preparation you will learn how to manually change into a different boot targets. This article will also teach you how to set a default boot targets to automatically boot into graphical or multi-user target on Red Hat Enterprise Linux system.

In this tutorial you will learn:

  • How to check default boot target
  • How to manually switch between different targets
  • How to set default boot to multi-user target
  • How to set default boot to graphical target

Change default runlevel target on RHEL 8 system

Change the default runlevel target on RHEL 8 system.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Red Hat Enterprise Linux 8
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
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

What are runlevel targets

You can think of boot target as specific level of operation. So for example if you prefer to use Graphical user interface ( given that GUI is installed ) you may want to change the level of operation to graphical.target. Similarly, for non-graphical multi-user operational level you will need to change to multi-user.target.

If you are familiar with SysV which was the default initialization standard for many GNU/Linux systems prior to the systemd proliferation you might recall the graphical target as runlevel 5 or multi-user target as runlevel 4. In fact not much has changed and the runlevel nomenclature still exist. Using the following command you can list all runlevel targets available on your RHEL system:

# ls -l /lib/systemd/system/runlevel*.target

For all possible targets use:

# systemctl list-units --type target
or
# systemctl list-units --type target --all


To following table lists all available run levels of operation of the Red Hat Enterprise Linux 8 system.
Runlevel Target Unit Target Unit Description
0 runlevel0.target or poweroff.target Changing your system to runlevel 0 will shutdown the system and power off your server/desktop.
1 runlevel1.target or rescue.target Also known as single mode the rescue runlevel is use for system troubleshooting and various system administration tasks.
2 runlevel2.target or multi-user.target User defined runlevel. By default, identical to runlevel 3.
3 runlevel3.target or multi-user.target This is a multi-user and non-graphical runlevel. Multiple users can log in via local consoles/terminals or remote network access.
4 runlevel4.target or multi-user.target User defined runlevel. By default, identical to runlevel 3.
5 runlevel5.target or graphical.target Multi-user graphical runlevel. Multiple users can log in via local consoles/terminals or remote network access.
6 runlevel6.target or reboot.target Changing your system to this runlevel will reboot your system.
HINT
On your RHCSA exam when you get stuck or simply cannot remember some of the above terminology regarding the runlevels consult the manual page by executing man runlevel command.

How to check and change default boot target

First, we will learn how to check a currently configured default runlevel boot target. Once done, we will set a default runlevel target of our system to runlevel 3 that is to the multi-user.target target unit. Setting a default runlevel target will instruct your system to automatically boot into a pre-configured runlevel.

  1. Check a default runlevel system configuration:
    # systemctl get-default
    graphical.target
    OR
    # ls -l /etc/systemd/system/default.target
    

    The above command will output a name of currently set default runlevel target unit.



  2. Set default runlevel target unit to multi-user.target target unit. This will configure your system to boot into runlevel3 the next time you reboot your system.
    # systemctl set-default multi-user.target
    Removed /etc/systemd/system/default.target.
    Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target.
    
    DID YOU KNOW?
    You can refer to single target units via different names. For example, for your RHCSA exam you may find it easier to remember runlevel3 instead of multi-user.target. Not only it is easier to remember but also it is faster to type, hence saving you some time on your exam. For example the following four commands are completely identical. The best command to use is the one you remember the easiest:

    # systemctl set-default multi-user.target
    # systemctl set-default multi-user
    # systemctl set-default runlevel3.target
    # systemctl set-default runlevel3
    

    To better understand what is going on here you should first review the Create hard and soft links RHCSA objective. Once ready note that targets such as for example the multi-user.target is simply a symbolic link of the runlevel3.target unit.

    List all available boot targets on RHEL system

    List all available boot targets on RHEL system.

  3. Reboot your system:
    # reboot
    

How to change manually into a different runlevel target

The above section, explained how to change a default runlevel. This means that the next time the system is rebooted it will boot into a user selected runlevel. Next, we will learn how to change runlevel on-fly without a need for reboot. This can be accomplished by the use of the systemctl command with a combination of isolate argument.

In the below example we will temporarily change from the graphical runlevel to multi-user target.

  1. Change to multi-user runlevel:
    # systemctl isolate multi-user
    

    The above a command simply disabled the graphical runlevel and corresponding services.



  2. If you cannot see login prompt you might need to change to a different TTY console by using the combination of CTRT+ALT+F1 keys.

Exercises

  1. Reboot your system by manually switching to reboot.target using the systemctl command. Can you also use runlevel target shutdown and power off your system?
  2. Set your system to boot directly to multi-user target. Reboot your system and confirm that the system persistently boots into multi-user target.
  3. Try to switch repeatedly between the multi-user runlevel and graphical runlevel. Why you cannot see the login prompt directly when switching from the graphical to multi-user runlevel?
  4. This is an extra curriculum question for good students and those who are not afraid of little hassle and self research.
    WARNING
    While working on the question 4 you might end up with a broken system. Hence proceed only on non-production system such as sandbox virtual machines etc.

    Again, do not attempt this question if you are not ready to possibly break your system! Set your default boot target to reboot.target unit and reboot your system. Can you fix the constant reboots and set your default runlevel back to say runlevel5?