1 00:00:07,020 --> 00:00:10,350 - In this video, we'll talk about systemd targets. 2 00:00:10,350 --> 00:00:13,530 So a systemd target is group of units. 3 00:00:13,530 --> 00:00:16,950 And if the target has the isolate property set, 4 00:00:16,950 --> 00:00:20,190 then it can define the state that the system starts in. 5 00:00:20,190 --> 00:00:21,810 When we are talking about targets 6 00:00:21,810 --> 00:00:23,160 that are used for system starts, 7 00:00:23,160 --> 00:00:25,200 there are four that matter. 8 00:00:25,200 --> 00:00:28,680 Emergency target is a target for minimal troubleshooting. 9 00:00:28,680 --> 00:00:31,110 You use it if you want a minimal amount 10 00:00:31,110 --> 00:00:33,180 of units to be started. 11 00:00:33,180 --> 00:00:35,040 Rescue target is used for troubleshooting 12 00:00:35,040 --> 00:00:36,423 in a more complete system. 13 00:00:37,470 --> 00:00:38,880 And there's multi-user target, 14 00:00:38,880 --> 00:00:41,940 which starts a complete non-graphical system. 15 00:00:41,940 --> 00:00:43,377 And graphical.target starts 16 00:00:43,377 --> 00:00:45,573 a complete graphical environment. 17 00:00:46,590 --> 00:00:49,440 You need to know how to manage the default target, 18 00:00:49,440 --> 00:00:53,460 and you can do so using systemctl get or set-default. 19 00:00:53,460 --> 00:00:54,450 Get will show you. 20 00:00:54,450 --> 00:00:55,503 Set will set it. 21 00:00:56,430 --> 00:00:58,590 And if you want to change your target, 22 00:00:58,590 --> 00:01:00,590 well, you can pass a desired target 23 00:01:00,590 --> 00:01:01,770 as a kernel argument 24 00:01:01,770 --> 00:01:04,260 in the Grub boot menu for troubleshooting. 25 00:01:04,260 --> 00:01:06,750 I'll show you that in the next video. 26 00:01:06,750 --> 00:01:09,030 For now, I would like to show you what's going on 27 00:01:09,030 --> 00:01:10,083 in these targets. 28 00:01:13,470 --> 00:01:17,940 So let me start using systemctl list unit files 29 00:01:17,940 --> 00:01:21,570 minus t target, so that you get a complete overview 30 00:01:21,570 --> 00:01:23,850 of all the targets that are available. 31 00:01:23,850 --> 00:01:24,683 As you can see, 32 00:01:24,683 --> 00:01:27,360 multiple targets are available, 33 00:01:27,360 --> 00:01:31,560 and these include targets that you use 34 00:01:31,560 --> 00:01:34,080 to define your current system state, 35 00:01:34,080 --> 00:01:36,060 but they also include targets 36 00:01:36,060 --> 00:01:39,120 that are really just a group of units 37 00:01:39,120 --> 00:01:41,880 like sound.target for instance. 38 00:01:41,880 --> 00:01:44,850 Let's investigate two of these targets 39 00:01:44,850 --> 00:01:49,850 using systemctl cat sound.target to start it. 40 00:01:51,360 --> 00:01:52,680 So what is that? 41 00:01:52,680 --> 00:01:54,570 Well, it just has a unit section, 42 00:01:54,570 --> 00:01:57,570 and for the rest of it, it has nothing. 43 00:01:57,570 --> 00:01:58,830 Why does it have nothing? 44 00:01:58,830 --> 00:02:01,980 Well, that is because the target doesn't know 45 00:02:01,980 --> 00:02:04,680 about the units that belong to the target. 46 00:02:04,680 --> 00:02:07,413 The units know which target they belong to. 47 00:02:08,760 --> 00:02:09,960 That's what we can see. 48 00:02:09,960 --> 00:02:13,830 If you use systemctl cat on any unit, 49 00:02:13,830 --> 00:02:16,410 sshd.service, for instance, 50 00:02:16,410 --> 00:02:18,660 there you can see the install section 51 00:02:18,660 --> 00:02:21,870 where we have wanted by is multi-use.target. 52 00:02:21,870 --> 00:02:25,350 So that's how the unit knows which target it belongs to. 53 00:02:25,350 --> 00:02:26,400 Now as I mentioned, 54 00:02:26,400 --> 00:02:28,920 targets that have a state of isolatable, 55 00:02:28,920 --> 00:02:30,690 these are the targets that you can use 56 00:02:30,690 --> 00:02:33,153 to start your system in a specific state. 57 00:02:34,140 --> 00:02:38,567 So if you use systemctl cat on the emergency.target, 58 00:02:39,840 --> 00:02:41,220 we get an example, 59 00:02:41,220 --> 00:02:44,220 and there we can see allow isolate is yes, 60 00:02:44,220 --> 00:02:46,200 and this allow isolate is yes. 61 00:02:46,200 --> 00:02:49,140 That makes that you can start your system 62 00:02:49,140 --> 00:02:50,583 in emergency mode. 63 00:02:51,930 --> 00:02:53,400 Now the last thing I need to show you 64 00:02:53,400 --> 00:02:56,580 is systemctl get-default, 65 00:02:56,580 --> 00:02:58,440 which is showing the default target. 66 00:02:58,440 --> 00:03:00,330 And if you want a different default target, 67 00:03:00,330 --> 00:03:05,330 that's fine, use systemctl set-default multi-user.target. 68 00:03:09,180 --> 00:03:11,160 And that has created a symbolic link 69 00:03:11,160 --> 00:03:13,920 to etc systemd system default.target, 70 00:03:13,920 --> 00:03:16,230 which is pointing to multi-user target. 71 00:03:16,230 --> 00:03:18,430 So what's happening if you reboot right now? 72 00:03:20,070 --> 00:03:22,260 Well, we will be starting in multi-user target. 73 00:03:22,260 --> 00:03:24,630 You will see that in a few seconds. 74 00:03:24,630 --> 00:03:26,130 So here is the login prompt. 75 00:03:26,130 --> 00:03:28,470 It's a multi-user target login prompt. 76 00:03:28,470 --> 00:03:29,910 So it's non-graphical, 77 00:03:29,910 --> 00:03:33,363 and, well, I just need to provide my credentials, 78 00:03:34,830 --> 00:03:39,830 and then I can use sudo systemctl start graphical.target 79 00:03:42,120 --> 00:03:44,420 if I want to get back to the graphical target. 80 00:03:49,380 --> 00:03:50,213 And there we go. 81 00:03:50,213 --> 00:03:52,563 Here we have the graphical target again. 82 00:03:53,580 --> 00:03:56,940 Now there is one thing that I still need to show you, 83 00:03:56,940 --> 00:03:59,790 and that is how we can switch between targets. 84 00:03:59,790 --> 00:04:04,020 You have just seen that I used sudo systemctl start. 85 00:04:04,020 --> 00:04:08,620 Now I'm going to use sudo systemctl isolate 86 00:04:09,570 --> 00:04:12,060 multi-user.target. 87 00:04:12,060 --> 00:04:14,970 Now what is the difference between start and isolate? 88 00:04:14,970 --> 00:04:17,250 Well, isolate allows you to get back, 89 00:04:17,250 --> 00:04:22,170 back to a target that has a fewer amount of services, 90 00:04:22,170 --> 00:04:25,260 and start only allows you to get forward. 91 00:04:25,260 --> 00:04:28,170 Graphical target builds on top of multi-user targets. 92 00:04:28,170 --> 00:04:31,680 So you can easily start that from multi-user target. 93 00:04:31,680 --> 00:04:35,310 If you are in graphical and you want to go to multi-user, 94 00:04:35,310 --> 00:04:38,250 now you don't start, you are going to isolate. 95 00:04:38,250 --> 00:04:40,620 You're going to isolate only these services 96 00:04:40,620 --> 00:04:44,970 that are required in multi-user and not in graphical. 97 00:04:44,970 --> 00:04:45,803 And there we go. 98 00:04:45,803 --> 00:04:49,680 We should see the multi-use login prompt in a few seconds. 99 00:04:49,680 --> 00:04:50,513 There it is. 100 00:04:52,980 --> 00:04:56,310 So let me restore the original situation, then we are done. 101 00:04:56,310 --> 00:05:01,310 So sudo systemctl set-default graphical.target. 102 00:05:06,900 --> 00:05:09,543 And now sudo reboot. 103 00:05:12,660 --> 00:05:13,710 And it's rebooting. 104 00:05:13,710 --> 00:05:16,440 And after the reboot, we are back in the graphical mode. 105 00:05:16,440 --> 00:05:17,273 That's it.