1
00:00:00,000 --> 00:00:10,200
In this video, you'll learn about UDEV rules.

2
00:00:10,200 --> 00:00:15,040
So when devices are initialized, UDEV rules are used.

3
00:00:15,040 --> 00:00:19,680
And the rules can set specific device properties, so it allows you to manage how exactly the

4
00:00:19,680 --> 00:00:22,840
device is added to your system.

5
00:00:22,840 --> 00:00:28,500
Default rules are in user lib udev-rules.d, and they have the lowest priority.

6
00:00:28,500 --> 00:00:33,980
And administrator-created rules are in etc udev-rules.d, and they have the highest priority.

7
00:00:33,980 --> 00:00:39,939
So again, we see this difference of configuration in user lib as well as in etc.

8
00:00:39,939 --> 00:00:43,560
There can also be dynamically generated rules if they exist.

9
00:00:43,560 --> 00:00:46,720
Don't focus on that too much because it's not that important.

10
00:00:46,720 --> 00:00:50,340
You can find them in run udev-rules.d.

11
00:00:50,340 --> 00:00:52,820
I prepared a fun demo about UDEV rules.

12
00:00:52,820 --> 00:00:54,380
Let me show you.

13
00:00:54,380 --> 00:00:59,040
So in order to do this demo, we need access to the course git repository.

14
00:00:59,040 --> 00:01:00,980
Make sure you have a git client installed.

15
00:01:00,980 --> 00:01:04,300
Let me install it right now.

16
00:01:04,300 --> 00:01:14,379
And then use git clone https://github.com slash Sander van Vugt slash Linux plus.

17
00:01:14,379 --> 00:01:20,180
And in this Linux plus, you will find a couple of files, including the file 50 custom rules.

18
00:01:20,180 --> 00:01:24,220
And 50 custom rules, that is what I care about here.

19
00:01:24,220 --> 00:01:31,059
I'm going to copy it into etc udev-rules.d.

20
00:01:31,059 --> 00:01:39,160
And then we go to etc udev-rules.d to investigate what is in these 50 custom rules.

21
00:01:39,160 --> 00:01:45,500
So here I have a custom rule, action is add, subsystem is block, and drivers is USB storage.

22
00:01:45,500 --> 00:01:51,699
That means that the rule is triggered when a block device using the USB storage driver

23
00:01:51,699 --> 00:01:53,099
is added.

24
00:01:53,099 --> 00:01:54,099
Then what are we going to do?

25
00:01:54,180 --> 00:01:56,779
Well, two actions are defined in this rule.

26
00:01:56,779 --> 00:02:01,019
Simlink plus equals USB slash %k.

27
00:02:01,019 --> 00:02:05,379
That is going to create a directory in the slash dev directory.

28
00:02:05,379 --> 00:02:08,220
And in this directory, you will find the device node.

29
00:02:08,220 --> 00:02:10,699
And also it is running a command.

30
00:02:10,699 --> 00:02:13,419
And this is the real power of these custom rules.

31
00:02:13,419 --> 00:02:15,960
You can run any arbitrary command.

32
00:02:15,960 --> 00:02:20,460
And a command in this case is use binlogger custom UDEV added %k.

33
00:02:20,460 --> 00:02:25,779
So you will see that a new rule has been added.

34
00:02:25,779 --> 00:02:27,820
Now the rule is in place right here.

35
00:02:27,820 --> 00:02:30,899
So it should be picked up automatically.

36
00:02:30,899 --> 00:02:34,419
And I am going to connect my USB thumb drive again.

37
00:02:34,419 --> 00:02:40,460
So UDEV ADM monitor, not because it's mandatory, but because I like seeing what is going on

38
00:02:40,460 --> 00:02:42,580
when the device is plugged in.

39
00:02:42,580 --> 00:02:45,860
Now how do we verify the operation of the rules?

40
00:02:45,860 --> 00:02:52,460
Well, journal CTL, uppercase G to go all the way to the end.

41
00:02:52,460 --> 00:03:00,380
And we should see right here custom UDEV added SEA and custom UDEV added SEA1.

42
00:03:00,380 --> 00:03:07,259
And also if we go into the dev directory, there should be a USB subdirectory.

43
00:03:07,259 --> 00:03:12,380
And in this USB subdirectory, we can see that the device has been added.

44
00:03:12,380 --> 00:03:14,539
This is the power of UDEV rules.

45
00:03:14,539 --> 00:03:20,580
Now don't think that this is not commonly used, because if you go into uselib UDEV and

46
00:03:20,580 --> 00:03:25,699
have a look at rules.d, you can see there is a lot of rules.

47
00:03:25,699 --> 00:03:30,339
And these rules are taking care of all the hardware initialization that might happen

48
00:03:30,339 --> 00:03:32,500
on your system.

49
00:03:32,500 --> 00:03:34,779
And they are quite complex.

50
00:03:34,779 --> 00:03:36,339
These are the system rules.

51
00:03:36,339 --> 00:03:39,100
Don't change them unless you know exactly what you are doing.

