Udev and Rule Locations
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 »

Video Transcription
00:00
>> Hey Cyberians, welcome back to
00:00
the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Gills.
00:00
In today's lesson, we're going to be
00:00
discussing udev and udev rules.
00:00
Upon completion of today's lesson,
00:00
you are going to be able to understand
00:00
the purpose of udev,
00:00
we're going to talk about how
00:00
udev and udev rules work, and then finally,
00:00
we're going to locate udev rules files
00:00
during some demo time at the end of the lesson.
00:00
Udev is actually short for userspace dev,
00:00
and it acts as a device manager for the Linux kernel.
00:00
Udev is started in the background at boot time,
00:00
and it runs as a daemon.
00:00
On SysVinit or system five systems,
00:00
you're going to find that at rc5 or rc3.d/udev.
00:00
On our systemd systems,
00:00
it's a service, so it's just systemd-udevd.service.
00:00
Now udev is actually supposed to sit
00:00
there and listen to kernel notifications,
00:00
information from the kernel
00:00
when it finds a hardware device.
00:00
This comes from the kernel in
00:00
the form of something called a uevent.
00:00
So the hardware device is placed in/sys by the kernel,
00:00
uvent is generated and then
00:00
>> what happens is udev manages
00:00
>> the device files in/dev by
00:00
using the information that it gets from that sysfs,
00:00
the information that's in this sys directory and it
00:00
configures devices based on configuration rules,
00:00
which we'll look at later.
00:00
Now here's an example of this.
00:00
Just to make this a little bit clearer, hopefully,
00:00
the kernel module is going to detect
00:00
the device and this could be at boot time or it
00:00
could just be because the device is
00:00
added and the kernel is going to place
00:00
that device entry in/sys for
00:00
that device and generate a uevent.
00:00
That uevent turn gets picked up by
00:00
udevd which responds to
00:00
the uevent and it matches that event against
00:00
this configuration files or
00:00
rules about how to handle that,
00:00
how to create the device.
00:00
If the device matches a rule,
00:00
udev acts on the uevent
00:00
and configures the device based on
00:00
the rule creating an entry in the dev file system.
00:00
Udev has to match
00:00
the device information from uevent against the rule.
00:00
Well, where are the rules found?
00:00
There's a few places that you
00:00
>> can find these udev rules.
00:00
>> The default user system default,
00:00
our lowest priority is /usr/lib/udev/rules.d.
00:00
Now u as a system administrator
00:00
can create custom rules to
00:00
override or create a higher priority
00:00
and specify how you want devices to be handled.
00:00
If you put these rules in sudev/rules.d directory.
00:00
Finally there's another place run/udev/rules.d,
00:00
these are non-persistent
00:00
>> custom rules that are created by
00:00
>> applications on the fly when
00:00
they're utilizing or working with a device.
00:00
The rules in these directories are
00:00
all handled in dictionary order,
00:00
which means numbers first,
00:00
higher numbers override lower numbers,
00:00
and then by names alphabetically.
00:00
Let's have a closer look at all of
00:00
this with some demo time.
00:00
Here we are in our demo environment.
00:00
Today we're going to be working in Ubuntu.
00:00
Let's first take a look at some of the default rules.
00:00
We can do this by doing an ls on /usr/lib/udev/rules.d.
00:00
In here we can see every possible conceivable rule
00:00
for the system that handle uevents.
00:00
These are pretty much all of the kind of
00:00
things that you might need to
00:00
handle in terms of hardware and kernel operation.
00:00
If we open one of these files,
00:00
we can see a little bit more about them.
00:00
We'll do a /usr/lib/udev/rules.d.
00:00
I don't know, let's do it 99 systemb rules.
00:00
What we find is that that's pretty wickedly complex.
00:00
They're not all this bad.
00:00
A simpler one we can look at would be,
00:00
let's take a look at 40-usbmedia.player.rules.
00:00
This is a little bit more easy to read.
00:00
Just tells us about what it's going to use
00:00
for USB media plugged into the system.
00:00
We can also take a look at the custom rules.
00:00
For example, if we do an ls on etc/udev/rules.d,
00:00
these are the custom rules,
00:00
the highest priority that override
00:00
everything else is configured by default on the system.
00:00
One of them we can look at would be like,
00:00
let's say less/60-vbox [NOISE]. Oh, sorry.
00:00
No, we're going to have to
00:00
>> pipe the whole thing in here.
00:00
>> We'll do [NOISE] less on
00:00
etc/udev/rules.d60-vboxdrv.rules and then we can
00:00
see here that this is
00:00
just a rule that handles
00:00
how Virtual Box works with USB drives.
00:00
I guess the question that this
00:00
brings us to is how often you
00:00
>> have to change these rules.
00:00
>> Hopefully as little as possible.
00:00
But if you do have to modify rules,
00:00
make sure that you do it in etc/udev/rules.d.
00:00
Again, this is the highest priority we'll override.
00:00
Then generally you want to set them at something low,
00:00
like 10 low for rules.
00:00
But with that, we've reached the end of this lesson.
00:00
In this lesson, we covered
00:00
the purpose of the udev device manager,
00:00
we talked a little bit about how udev and udev rules
00:00
work and then we talked about how to locate udev rules.
00:00
Thank you so much for being here and I look
00:00
forward to seeing you in the next lesson.
Up Next
Instructed By
Similar Content