In this lesson, I will explain Linux hardware management.
So the Linux kernel is responsible for device management.
So any hardware you want to use needs to be addressed by a Linux kernel module.
And these modules work with specific device types.
Kernel modules are included in InitRAMFS, and InitRAMFS is created when you install
Linux.
So it's created according to the hardware that was found and makes sure that all the
essential drivers are available while booting.
There's also a part of the hardware that can be loaded by the plug-and-play manager.
And this plug-and-play manager is systemd-udev-d.
So automatic on-demand device initialization is done by systemd-udev-d.
And systemd-udev-d is defined by rules in uselib-udev-rules.d and etc-udev-rules.d.
And that's pretty cool.
You can customize these rules to make sure that specific actions will happen when a specific
device is plugged in.
So if you want a message to be logged to your syslog, or a file to be created, or whatever,
if a device is plugged in, systemd-udev-d rules is what you need to do.
That's beyond what you need to know for Linux Plus, so I won't explain it right here.
So systemd-udev-d detects devices and will load the required kernel modules.
And there's also a manual way of doing it, and that would be modprobe.
And if you want to interface with devices, many, but not all of the devices have a device
node file in slash dev.
If you are going to use a hard disk, for instance, you use commands like mount slash dev slash
sda1.
Well, the dev sda1 is referring to your first partition, and this first partition addresses
the appropriate kernel module to make sure that the device is initialized.
And in this, the device nodes in the slash dev directory have a major number, and they
have a minor number.
And that indicates which kernel driver to use.
And also, hardware-related parameters are stored in slash sys and its subdirectories.
Let me show you a little bit of what's going on in this slash dev directory.
So the part that I need you to be aware of is ls minus l slash dev slash, well, just
slash dev.
Here we can see all these device nodes.
And in my list of device nodes, I'm looking up my storage device.
I have an NVMe disk, and my NVMe disk is right here.
And it's 259 comma 0.
This is what matters.
259 is the major, and the minor is 0.
So the major addresses the driver.
So here we can see 259 comma 1 for partition number 1, and so on.
All of these devices have a major.
And if you want to find out what that is, you need to have a look at the PROCFILE system,
because in the PROCFILE system, there is a file with the name devices.
The PROCFILE system is about kernel settings, about the current kernel state.
If you investigate the PROCFILE system, you can learn so much about what is going on on
your system.
I'm going to use less on devices.
And there we can see that it starts with a list of character devices.
And then there is a list of block devices, where 259 is identified as a block ext.
And block ext, well, that addresses the kernel functionality that is required.
So there is a kernel module that makes sure that this device can be used.