- In this video, we'll talk about systemd targets.
So a systemd target is group of units.
And if the target has the isolate property set,
then it can define the state that the system starts in.
When we are talking about targets
that are used for system starts,
there are four that matter.
Emergency target is a target for minimal troubleshooting.
You use it if you want a minimal amount
of units to be started.
Rescue target is used for troubleshooting
in a more complete system.
And there's multi-user target,
which starts a complete non-graphical system.
And graphical.target starts
a complete graphical environment.
You need to know how to manage the default target,
and you can do so using systemctl get or set-default.
Get will show you.
Set will set it.
And if you want to change your target,
well, you can pass a desired target
as a kernel argument
in the Grub boot menu for troubleshooting.
I'll show you that in the next video.
For now, I would like to show you what's going on
in these targets.
So let me start using systemctl list unit files
minus t target, so that you get a complete overview
of all the targets that are available.
As you can see,
multiple targets are available,
and these include targets that you use
to define your current system state,
but they also include targets
that are really just a group of units
like sound.target for instance.
Let's investigate two of these targets
using systemctl cat sound.target to start it.
So what is that?
Well, it just has a unit section,
and for the rest of it, it has nothing.
Why does it have nothing?
Well, that is because the target doesn't know
about the units that belong to the target.
The units know which target they belong to.
That's what we can see.
If you use systemctl cat on any unit,
sshd.service, for instance,
there you can see the install section
where we have wanted by is multi-use.target.
So that's how the unit knows which target it belongs to.
Now as I mentioned,
targets that have a state of isolatable,
these are the targets that you can use
to start your system in a specific state.
So if you use systemctl cat on the emergency.target,
we get an example,
and there we can see allow isolate is yes,
and this allow isolate is yes.
That makes that you can start your system
in emergency mode.
Now the last thing I need to show you
is systemctl get-default,
which is showing the default target.
And if you want a different default target,
that's fine, use systemctl set-default multi-user.target.
And that has created a symbolic link
to etc systemd system default.target,
which is pointing to multi-user target.
So what's happening if you reboot right now?
Well, we will be starting in multi-user target.
You will see that in a few seconds.
So here is the login prompt.
It's a multi-user target login prompt.
So it's non-graphical,
and, well, I just need to provide my credentials,
and then I can use sudo systemctl start graphical.target
if I want to get back to the graphical target.
And there we go.
Here we have the graphical target again.
Now there is one thing that I still need to show you,
and that is how we can switch between targets.
You have just seen that I used sudo systemctl start.
Now I'm going to use sudo systemctl isolate
multi-user.target.
Now what is the difference between start and isolate?
Well, isolate allows you to get back,
back to a target that has a fewer amount of services,
and start only allows you to get forward.
Graphical target builds on top of multi-user targets.
So you can easily start that from multi-user target.
If you are in graphical and you want to go to multi-user,
now you don't start, you are going to isolate.
You're going to isolate only these services
that are required in multi-user and not in graphical.
And there we go.
We should see the multi-use login prompt in a few seconds.
There it is.
So let me restore the original situation, then we are done.
So sudo systemctl set-default graphical.target.
And now sudo reboot.
And it's rebooting.
And after the reboot, we are back in the graphical mode.
That's it.