In this video, you'll learn about UDEV rules.
So when devices are initialized, UDEV rules are used.
And the rules can set specific device properties, so it allows you to manage how exactly the
device is added to your system.
Default rules are in user lib udev-rules.d, and they have the lowest priority.
And administrator-created rules are in etc udev-rules.d, and they have the highest priority.
So again, we see this difference of configuration in user lib as well as in etc.
There can also be dynamically generated rules if they exist.
Don't focus on that too much because it's not that important.
You can find them in run udev-rules.d.
I prepared a fun demo about UDEV rules.
Let me show you.
So in order to do this demo, we need access to the course git repository.
Make sure you have a git client installed.
Let me install it right now.
And then use git clone https://github.com slash Sander van Vugt slash Linux plus.
And in this Linux plus, you will find a couple of files, including the file 50 custom rules.
And 50 custom rules, that is what I care about here.
I'm going to copy it into etc udev-rules.d.
And then we go to etc udev-rules.d to investigate what is in these 50 custom rules.
So here I have a custom rule, action is add, subsystem is block, and drivers is USB storage.
That means that the rule is triggered when a block device using the USB storage driver
is added.
Then what are we going to do?
Well, two actions are defined in this rule.
Simlink plus equals USB slash %k.
That is going to create a directory in the slash dev directory.
And in this directory, you will find the device node.
And also it is running a command.
And this is the real power of these custom rules.
You can run any arbitrary command.
And a command in this case is use binlogger custom UDEV added %k.
So you will see that a new rule has been added.
Now the rule is in place right here.
So it should be picked up automatically.
And I am going to connect my USB thumb drive again.
So UDEV ADM monitor, not because it's mandatory, but because I like seeing what is going on
when the device is plugged in.
Now how do we verify the operation of the rules?
Well, journal CTL, uppercase G to go all the way to the end.
And we should see right here custom UDEV added SEA and custom UDEV added SEA1.
And also if we go into the dev directory, there should be a USB subdirectory.
And in this USB subdirectory, we can see that the device has been added.
This is the power of UDEV rules.
Now don't think that this is not commonly used, because if you go into uselib UDEV and
have a look at rules.d, you can see there is a lot of rules.
And these rules are taking care of all the hardware initialization that might happen
on your system.
And they are quite complex.
These are the system rules.
Don't change them unless you know exactly what you are doing.