Systemd Targets (Demo)

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
Video Transcription
00:00
>> Hello, Cybrarians. Welcome back to
00:00
the Linux+ course here at Cybrary.
00:00
I'm your instructor Rob Gayles,
00:00
and in today's lesson we're going to be
00:00
talking about systemd targets.
00:00
Now upon completion of today's lesson,
00:00
you're going to be able to explain
00:00
the purpose of the systemd target files,
00:00
which are actually just unit files
00:00
like we talked about in the previous lesson.
00:00
We're going to talk about how
00:00
the systemd target files work
00:00
and use the systemctl command
00:00
to interact with the target files.
00:00
In systemd you can control services
00:00
and system capabilities that come up as boot time,
00:00
and this is done through a target file.
00:00
Previously in SysVInit this was called a runlevel,
00:00
but here in systemd this is referred to as a target.
00:00
Now, there are several targets to
00:00
know about and I'm going to try to relate
00:00
these to SysVInit because we're going to talk
00:00
about that later in this module
00:00
and we want to have a common
00:00
understanding of what things do.
00:00
Poweroff.target does exactly what it sounds like,
00:00
it shuts off the system,
00:00
shuts down the system, and that's equivalent
00:00
to runlevel 0 in SysVInit.
00:00
The rescue.target configures a rescue shell session
00:00
that's equivalent to runlevel 1 in SysVInit.
00:00
Multi-user target boots the system into
00:00
a non-graphical multi-user environment
00:00
that's equivalent to runlevel 2,
00:00
3, and 4 in SysVInit,
00:00
and graphical target boots the system
00:00
into a graphical multi-user environment.
00:00
That's pretty much what we've been using in
00:00
our demos as we've gone through all of these lessons.
00:00
That's going to be equivalent to what's called
00:00
runlevel 5 in SysVInit.
00:00
Then the final target that we need to know about here
00:00
>> is the reboot target that reboots the system which
00:00
>> is equivalent to runlevel 6 in SysVInit.
00:00
Let's go ahead and have a look at all of
00:00
these target files with some demo time.
00:00
Here we are over in our demo environment and
00:00
today we're going to be using CentOS.
00:00
The first thing we'll do with systemctl related to
00:00
targets is that we'll display the default target,
00:00
and the way that we do that is by running
00:00
the systemctl command called git.default,
00:00
and we can see that it displays graphical target.
00:00
That's makes sense, we're in
00:00
graphical user environment here we can see that we
00:00
have a background and a desktop is not
00:00
just the command line with just black and white cursor,
00:00
so this is a graphical environment.
00:00
We can look at this target file by actually running
00:00
the systemctl cat command
00:00
and then specifying the target that we want to view,
00:00
which is really nice, we don't need to go
00:00
hunt down the location of that unit file.
00:00
We can just tell systemctl, hey,
00:00
display this file for us,
00:00
and there we go, we see the content of that unit file,
00:00
of that target file.
00:00
Now the target file has a couple
00:00
of lines that are really important.
00:00
These two are the requires in want line,
00:00
requires means that before
00:00
>> this target can be processed,
00:00
>> all of the services that are in
00:00
the multi-user target must be started.
00:00
Then the wants statement says that all
00:00
of this gets processed after
00:00
the require statements fully processed,
00:00
here this means that
00:00
the display manager services started,
00:00
which brings up the graphical user interface.
00:00
In essence, what all this means is that
00:00
>> the kernel boots,
00:00
>> then systemd initialization takes over
00:00
>> it processes the multiuser target,
00:00
and once it's done with that then it moves on to
00:00
the want line where it brings up the graphical target.
00:00
Really the graphical target
00:00
its only purpose is to bring up
00:00
this display manager service and
00:00
give us the display manager to work.
00:00
Now, one of the other things that we can
00:00
do here is we can look
00:00
in the target file and see that
00:00
there's a line that says "allow isolate yes,"
00:00
>> what does that mean? Well, it's cool.
00:00
>> The isolate command is how we actually change
00:00
between targets in systemd.
00:00
For example, if we want to change from
00:00
the graphical target and
00:00
go to just a command line or multiuser target,
00:00
we can do that using the systemctl command,
00:00
and we say isolate,
00:00
and we're going to put us into,
00:00
let's say we want to go into multi-user.target.
00:00
Actually I'm going to run this as pseudo,
00:00
I'm going to elevate my privileges
00:00
as pseudo and temporarily become root
00:00
>> because we need to do that to change targets.
00:00
>> Now when I hit "Enter" with
00:00
hopefully the right password, there we go.
00:00
We boot into just this
00:00
non-graphical multi-user target environment
00:00
which is just a command line.
00:00
I'm going to log back in as me.
00:00
Now that I'm logged in here I can use systemctl,
00:00
get default, and
00:00
we can see that I'm still set
00:00
the default the graphical target.
00:00
Well, that's weird.
00:00
What do you think's going to happen? Well, let's see.
00:00
Let's do a systemctl, isolate,
00:00
and we're going to go to the reboot target.
00:00
[NOISE] I'm just going
00:00
to actually use pseudo as well because again,
00:00
we're going to need to elevate
00:00
privileges in order to do this,
00:00
change our targets and hit "Enter" and we reboot.
00:00
We can see that this is a VirtualBox VM,
00:00
so we're actually just going to use that to
00:00
reboot into CentOS once again.
00:00
We'll wait a little while for
00:00
that to come up and bring us
00:00
to a login session.
00:00
Again, that's going to bring us to
00:00
that user-space to login,
00:00
so we'll wait a couple of seconds for
00:00
that to come up and we get logged in here.
00:00
We can already see that this is coming
00:00
up in a graphical target.
00:00
When the system comes up,
00:00
it comes up in a graphical target,
00:00
and so we might be asking ourselves, why is that?
00:00
Well, again, like I just showed you a
00:00
moment ago when we went in and we ran that systemctl,
00:00
get default, we saw that the system was
00:00
set to be the graphical target.
00:00
We'll do that again here in just a second.
00:00
Let's wait for this to finish loading,
00:00
>> and there we are.
00:00
>> Let's go ahead and open up a terminal window,
00:00
and we'll maximize the terminal
00:00
window and then we'll do a systemctl,
00:00
get default and we
00:00
can see that it's still set to graphical target.
00:00
Now if we wanted to change this so
00:00
that every time we reboot,
00:00
we boot into that multi-user target
00:00
instead of graphical, you can do that.
00:00
You do multi-task user target,
00:00
and now if we do,
00:00
we're going to provide a password remember,
00:00
in order to change targets,
00:00
you need to be root or you need
00:00
to elevate your privileges with pseudo.
00:00
We can see what it actually does is it creates a same
00:00
like it removes the same like that
00:00
exists for default target,
00:00
and then it recreates that same link,
00:00
it's default target just
00:00
points to one of the target files.
00:00
That's really all it does.
00:00
We see that it points from
00:00
systemd system default target to
00:00
user lib systemd system multi-user target.
00:00
That's where that unit file actually lives,
00:00
and we talked about that previously.
00:00
But we don't really want to be in multi-user,
00:00
I want to use this graphical environment just
00:00
as a little nicer to show things during the demo.
00:00
Let me change this back.
00:00
I'm going to change this from
00:00
multi-user target to graphical target,
00:00
[NOISE] and then I'm going
00:00
to do this as pseudo and
00:00
put in my pseudo password again,
00:00
so you can elevate privileges, and there we go.
00:00
It removes the default target and we set
00:00
>> the default target to now point to graphical target.
00:00
>> Just changed it similarly, it's
00:00
all similarly tricks, all similarly video.
00:00
But with that, we wish to end this lesson,
00:00
>> and in this lesson we cover the purpose of target
00:00
>> unit files versus
00:00
>> convenient how those target files work.
00:00
>> We also use systemctl to change
00:00
between targets and to set the default target.
00:00
Thanks so much for being here and I look
00:00
forward to seeing you in our next lesson.
Up Next