In this lesson, you will learn about systemd targets.
So what is a target?
Well, technically, a target is a group of units
that can be managed as one.
So you can use systemctl start on a target
and systemctl stop on a target to manage the current state
of all the units that are included.
Some targets are isolatable, and that
means that they can be used to define
a state in which the system should be started.
These are emergency target, which
is your minimal troubleshooting target,
residual target, which is a little bit more
troubleshooting target, multi-user target,
which is the current state of a server that doesn't run
a graphical user interface, and graphical.target,
which is bringing a complete graphical interface.
You can use systemctl get default
to see the default target in which your system will boot.
And you can use systemctl set default
to set the default target to something else.
Let me show you.
So I'm starting with systemctl list units minus t target.
Minus t is for type, and it allows
you to show unit files of a specific type.
Here you can see all the units that are available,
including, for instance, a unit like sound.target.
So what happens if you do systemctl status sound.target?
Well, we can see that the sound target is active.
Doesn't provide any more details about it.
Finding what is in a target is not always obvious.
I like to go into etc systemd system.
And in there, I'm looking for the once directory.
And oh, boy, we don't have a once directory
for the sound.target.
Well, that means that the sound.target is empty.
But I'm going to use the printer.target as an example.
So if we use systemctl status on printer.target, we see what?
We see that it is loaded, which means
that systemd knows about the configuration file,
but it's currently inactive.
But if I use ls on printer.target once,
then I can see symbolic links referring
to the units that should be included in this target.
More interesting are the targets that are isolatable.
Let me use systemctl cat on graphical.target.
And what do we see?
We see that it has an allow isolate is yes.
We also see that there is an after,
which is defining when the graphical target should
be loaded.
So this should be loaded after multi-user target.
And even after the display manager.service,
because it needs display manager.service to be available.
You want to know what is going on in this target?
Well, use ls on graphical.target.once.
And you can see everything that is started in this target.
When you use systemctl enable, every unit
has the install section, where it defines the target
that it should be installed in.
And when you use systemctl enable on a unit,
the unit creates a symbolic link in this directory.
And that makes sure that when you are processing your target,
you will start all of these units.
Now, your system has a default target.
And you can find out using systemctl get default.
There we can see that my default is graphical.target.
You can use systemctl set default
followed by anything else to change the default target.
You can also specify your targets
while you are rebooting.
At the grub command prompt.
I'm going to reboot so that I can show you.
Now, you don't see the grub shell by default.
It requires a little bit of practice
to press escape at the right moment if you want to see it.
And if you don't see it, it also helps
if you reset your system while it is booting,
because then on the next start,
it will detect that the last time
it wasn't started correctly.
And it will automatically give you the grub shell.
I'm going to enter this grub shell by using E,
which puts me in edit mode.
And there I'm looking up the line that starts with Linux
and it ends with RHDB and quiet.
First, I'm going to remove the RHDB and quiet.
And I'm using systemd.unit
is emergency.target.
Emergency target is what you can use if you are in trouble.
There is even more minimal modes,
but we will talk about that later
when we talk about the system boot procedure.
For now, I want to show you emergency target.
Likewise, you can also use systemd.unit is rescue.target.
Use control X to start in the target,
and then this will happen.
So here we see what?
Oh, no, I see cannot open access to console.
The root account is locked.
See, as you log in man page for more details
and press enter to continue.
You know what that means?
That means that I can't enter emergency targets right now
because my root account is protected.
Fortunately, later in this course,
you will learn how you can unlock your root account
if it is locked.
Consult lesson 12.6 in this lesson for more information
on how to reset the root user account.
For now, as I'm in a bootable state,
I can use a different approach
and show you emergency target anyway.
So here I'm back on my system,
and I'm going to use sudo minus I to open my sudo shell,
and I'm using passwd root or even passwd.
I'm in a root shell anyway.
New password going once, new password going twice.
At this point, my root user is enabled.
I can log in as a root user
because root user now has a password.
So I'm going to reboot,
and I need to enter the grub boot prompt again.
Oops, that was too fast.
If you see this, just type exit to get back into the grub shell.
Then you type escape again,
and you need to edit this line that starts with Linux.
So once again, I'm using systemd.unit is emergency.target
and control X to start in the emergency target.
And this time you see that it is asking for the root password.
Give root password for maintenance.
It's doing that because emergency target is protected
by the SU login program,
and that means that I need to enter the root password
to get access to a root shell
that I can use for further troubleshooting.
Now, if you want to investigate,
it's interesting to see systemctl list units.
That will show you all the units
that you have in emergency target.
And as you can see, there is 60 only.
Now, once done in your emergency target,
use a reboot to get back in a normal operational state.