1
00:00:00,000 --> 00:00:10,000
In this lesson, you will learn about systemd targets.

2
00:00:10,000 --> 00:00:11,240
So what is a target?

3
00:00:11,240 --> 00:00:13,440
Well, technically, a target is a group of units

4
00:00:13,440 --> 00:00:15,320
that can be managed as one.

5
00:00:15,320 --> 00:00:18,240
So you can use systemctl start on a target

6
00:00:18,240 --> 00:00:21,920
and systemctl stop on a target to manage the current state

7
00:00:21,920 --> 00:00:24,080
of all the units that are included.

8
00:00:24,080 --> 00:00:27,360
Some targets are isolatable, and that

9
00:00:27,360 --> 00:00:28,959
means that they can be used to define

10
00:00:28,959 --> 00:00:31,920
a state in which the system should be started.

11
00:00:31,920 --> 00:00:33,919
These are emergency target, which

12
00:00:33,919 --> 00:00:36,000
is your minimal troubleshooting target,

13
00:00:36,000 --> 00:00:38,560
residual target, which is a little bit more

14
00:00:38,560 --> 00:00:41,439
troubleshooting target, multi-user target,

15
00:00:41,439 --> 00:00:43,799
which is the current state of a server that doesn't run

16
00:00:43,799 --> 00:00:47,160
a graphical user interface, and graphical.target,

17
00:00:47,160 --> 00:00:50,680
which is bringing a complete graphical interface.

18
00:00:50,680 --> 00:00:52,919
You can use systemctl get default

19
00:00:52,919 --> 00:00:56,599
to see the default target in which your system will boot.

20
00:00:56,599 --> 00:00:59,360
And you can use systemctl set default

21
00:00:59,360 --> 00:01:02,400
to set the default target to something else.

22
00:01:02,400 --> 00:01:05,040
Let me show you.

23
00:01:05,040 --> 00:01:12,080
So I'm starting with systemctl list units minus t target.

24
00:01:12,080 --> 00:01:13,959
Minus t is for type, and it allows

25
00:01:13,959 --> 00:01:17,279
you to show unit files of a specific type.

26
00:01:17,279 --> 00:01:20,599
Here you can see all the units that are available,

27
00:01:20,599 --> 00:01:24,599
including, for instance, a unit like sound.target.

28
00:01:24,599 --> 00:01:28,160
So what happens if you do systemctl status sound.target?

29
00:01:32,120 --> 00:01:34,879
Well, we can see that the sound target is active.

30
00:01:34,879 --> 00:01:38,720
Doesn't provide any more details about it.

31
00:01:38,720 --> 00:01:41,879
Finding what is in a target is not always obvious.

32
00:01:41,879 --> 00:01:47,239
I like to go into etc systemd system.

33
00:01:47,239 --> 00:01:50,519
And in there, I'm looking for the once directory.

34
00:01:50,519 --> 00:01:52,680
And oh, boy, we don't have a once directory

35
00:01:52,680 --> 00:01:54,480
for the sound.target.

36
00:01:54,480 --> 00:01:57,879
Well, that means that the sound.target is empty.

37
00:01:57,879 --> 00:02:01,559
But I'm going to use the printer.target as an example.

38
00:02:01,559 --> 00:02:08,000
So if we use systemctl status on printer.target, we see what?

39
00:02:08,000 --> 00:02:10,800
We see that it is loaded, which means

40
00:02:10,800 --> 00:02:13,759
that systemd knows about the configuration file,

41
00:02:13,759 --> 00:02:15,919
but it's currently inactive.

42
00:02:15,919 --> 00:02:19,320
But if I use ls on printer.target once,

43
00:02:19,320 --> 00:02:21,520
then I can see symbolic links referring

44
00:02:21,520 --> 00:02:24,960
to the units that should be included in this target.

45
00:02:24,960 --> 00:02:29,119
More interesting are the targets that are isolatable.

46
00:02:29,119 --> 00:02:34,720
Let me use systemctl cat on graphical.target.

47
00:02:34,720 --> 00:02:36,199
And what do we see?

48
00:02:36,199 --> 00:02:40,119
We see that it has an allow isolate is yes.

49
00:02:40,119 --> 00:02:42,119
We also see that there is an after,

50
00:02:42,119 --> 00:02:44,679
which is defining when the graphical target should

51
00:02:44,679 --> 00:02:45,360
be loaded.

52
00:02:45,360 --> 00:02:48,240
So this should be loaded after multi-user target.

53
00:02:48,240 --> 00:02:51,240
And even after the display manager.service,

54
00:02:51,279 --> 00:02:55,880
because it needs display manager.service to be available.

55
00:02:55,880 --> 00:02:58,119
You want to know what is going on in this target?

56
00:02:58,119 --> 00:03:02,080
Well, use ls on graphical.target.once.

57
00:03:02,080 --> 00:03:06,320
And you can see everything that is started in this target.

58
00:03:06,320 --> 00:03:10,160
When you use systemctl enable, every unit

59
00:03:10,160 --> 00:03:14,000
has the install section, where it defines the target

60
00:03:14,000 --> 00:03:16,320
that it should be installed in.

61
00:03:16,320 --> 00:03:19,399
And when you use systemctl enable on a unit,

62
00:03:19,399 --> 00:03:23,000
the unit creates a symbolic link in this directory.

63
00:03:23,000 --> 00:03:26,240
And that makes sure that when you are processing your target,

64
00:03:26,240 --> 00:03:29,119
you will start all of these units.

65
00:03:29,119 --> 00:03:31,039
Now, your system has a default target.

66
00:03:31,039 --> 00:03:34,880
And you can find out using systemctl get default.

67
00:03:34,880 --> 00:03:38,240
There we can see that my default is graphical.target.

68
00:03:38,240 --> 00:03:40,600
You can use systemctl set default

69
00:03:40,600 --> 00:03:44,279
followed by anything else to change the default target.

70
00:03:44,279 --> 00:03:46,800
You can also specify your targets

71
00:03:46,800 --> 00:03:48,679
while you are rebooting.

72
00:03:48,720 --> 00:03:51,000
At the grub command prompt.

73
00:03:51,000 --> 00:03:53,360
I'm going to reboot so that I can show you.

74
00:03:53,360 --> 00:03:55,839
Now, you don't see the grub shell by default.

75
00:03:55,839 --> 00:03:57,880
It requires a little bit of practice

76
00:03:57,880 --> 00:04:01,080
to press escape at the right moment if you want to see it.

77
00:04:01,080 --> 00:04:03,000
And if you don't see it, it also helps

78
00:04:03,000 --> 00:04:05,679
if you reset your system while it is booting,

79
00:04:05,679 --> 00:04:07,479
because then on the next start,

80
00:04:07,479 --> 00:04:09,160
it will detect that the last time

81
00:04:09,160 --> 00:04:10,839
it wasn't started correctly.

82
00:04:10,839 --> 00:04:14,639
And it will automatically give you the grub shell.

83
00:04:14,639 --> 00:04:17,559
I'm going to enter this grub shell by using E,

84
00:04:17,640 --> 00:04:19,399
which puts me in edit mode.

85
00:04:19,399 --> 00:04:22,279
And there I'm looking up the line that starts with Linux

86
00:04:22,279 --> 00:04:25,359
and it ends with RHDB and quiet.

87
00:04:25,359 --> 00:04:29,000
First, I'm going to remove the RHDB and quiet.

88
00:04:29,000 --> 00:04:31,440
And I'm using systemd.unit

89
00:04:33,040 --> 00:04:37,839
is emergency.target.

90
00:04:37,839 --> 00:04:42,320
Emergency target is what you can use if you are in trouble.

91
00:04:42,320 --> 00:04:43,920
There is even more minimal modes,

92
00:04:43,920 --> 00:04:45,359
but we will talk about that later

93
00:04:45,359 --> 00:04:48,000
when we talk about the system boot procedure.

94
00:04:48,000 --> 00:04:50,559
For now, I want to show you emergency target.

95
00:04:50,559 --> 00:04:55,279
Likewise, you can also use systemd.unit is rescue.target.

96
00:04:55,279 --> 00:04:57,679
Use control X to start in the target,

97
00:04:57,679 --> 00:04:59,679
and then this will happen.

98
00:04:59,679 --> 00:05:01,559
So here we see what?

99
00:05:01,559 --> 00:05:04,000
Oh, no, I see cannot open access to console.

100
00:05:04,000 --> 00:05:05,600
The root account is locked.

101
00:05:05,600 --> 00:05:08,200
See, as you log in man page for more details

102
00:05:08,200 --> 00:05:09,880
and press enter to continue.

103
00:05:09,880 --> 00:05:11,079
You know what that means?

104
00:05:11,079 --> 00:05:14,040
That means that I can't enter emergency targets right now

105
00:05:14,079 --> 00:05:17,480
because my root account is protected.

106
00:05:17,480 --> 00:05:20,279
Fortunately, later in this course,

107
00:05:20,279 --> 00:05:23,880
you will learn how you can unlock your root account

108
00:05:23,880 --> 00:05:26,040
if it is locked.

109
00:05:26,040 --> 00:05:29,519
Consult lesson 12.6 in this lesson for more information

110
00:05:29,519 --> 00:05:33,359
on how to reset the root user account.

111
00:05:33,359 --> 00:05:37,559
For now, as I'm in a bootable state,

112
00:05:37,559 --> 00:05:39,399
I can use a different approach

113
00:05:39,399 --> 00:05:41,959
and show you emergency target anyway.

114
00:05:45,040 --> 00:05:47,200
So here I'm back on my system,

115
00:05:47,200 --> 00:05:52,000
and I'm going to use sudo minus I to open my sudo shell,

116
00:05:52,000 --> 00:05:57,720
and I'm using passwd root or even passwd.

117
00:05:57,720 --> 00:05:59,519
I'm in a root shell anyway.

118
00:05:59,519 --> 00:06:03,200
New password going once, new password going twice.

119
00:06:03,200 --> 00:06:05,799
At this point, my root user is enabled.

120
00:06:05,799 --> 00:06:07,559
I can log in as a root user

121
00:06:07,559 --> 00:06:09,760
because root user now has a password.

122
00:06:09,760 --> 00:06:12,119
So I'm going to reboot,

123
00:06:12,119 --> 00:06:14,920
and I need to enter the grub boot prompt again.

124
00:06:14,920 --> 00:06:16,959
Oops, that was too fast.

125
00:06:16,959 --> 00:06:20,679
If you see this, just type exit to get back into the grub shell.

126
00:06:20,679 --> 00:06:22,760
Then you type escape again,

127
00:06:22,760 --> 00:06:25,760
and you need to edit this line that starts with Linux.

128
00:06:25,760 --> 00:06:35,119
So once again, I'm using systemd.unit is emergency.target

129
00:06:35,119 --> 00:06:39,399
and control X to start in the emergency target.

130
00:06:39,399 --> 00:06:42,359
And this time you see that it is asking for the root password.

131
00:06:42,359 --> 00:06:44,480
Give root password for maintenance.

132
00:06:44,480 --> 00:06:48,640
It's doing that because emergency target is protected

133
00:06:48,640 --> 00:06:50,720
by the SU login program,

134
00:06:50,720 --> 00:06:53,640
and that means that I need to enter the root password

135
00:06:53,640 --> 00:06:55,119
to get access to a root shell

136
00:06:55,119 --> 00:06:57,920
that I can use for further troubleshooting.

137
00:06:57,920 --> 00:07:00,000
Now, if you want to investigate,

138
00:07:00,000 --> 00:07:05,559
it's interesting to see systemctl list units.

139
00:07:05,559 --> 00:07:07,519
That will show you all the units

140
00:07:07,559 --> 00:07:09,559
that you have in emergency target.

141
00:07:09,559 --> 00:07:12,279
And as you can see, there is 60 only.

142
00:07:12,279 --> 00:07:15,119
Now, once done in your emergency target,

143
00:07:15,119 --> 00:07:18,359
use a reboot to get back in a normal operational state.

