1 00:00:00,000 --> 00:00:10,640 In this lesson, I will explain Linux hardware management. 2 00:00:10,640 --> 00:00:14,100 So the Linux kernel is responsible for device management. 3 00:00:14,100 --> 00:00:19,799 So any hardware you want to use needs to be addressed by a Linux kernel module. 4 00:00:19,799 --> 00:00:23,820 And these modules work with specific device types. 5 00:00:23,820 --> 00:00:28,840 Kernel modules are included in InitRAMFS, and InitRAMFS is created when you install 6 00:00:28,840 --> 00:00:30,040 Linux. 7 00:00:30,040 --> 00:00:33,599 So it's created according to the hardware that was found and makes sure that all the 8 00:00:33,599 --> 00:00:37,200 essential drivers are available while booting. 9 00:00:37,200 --> 00:00:42,240 There's also a part of the hardware that can be loaded by the plug-and-play manager. 10 00:00:42,240 --> 00:00:48,599 And this plug-and-play manager is systemd-udev-d. 11 00:00:48,599 --> 00:00:54,360 So automatic on-demand device initialization is done by systemd-udev-d. 12 00:00:54,360 --> 00:01:01,080 And systemd-udev-d is defined by rules in uselib-udev-rules.d and etc-udev-rules.d. 13 00:01:01,080 --> 00:01:02,080 And that's pretty cool. 14 00:01:02,080 --> 00:01:07,279 You can customize these rules to make sure that specific actions will happen when a specific 15 00:01:07,279 --> 00:01:10,040 device is plugged in. 16 00:01:10,040 --> 00:01:16,279 So if you want a message to be logged to your syslog, or a file to be created, or whatever, 17 00:01:16,279 --> 00:01:21,919 if a device is plugged in, systemd-udev-d rules is what you need to do. 18 00:01:21,919 --> 00:01:27,680 That's beyond what you need to know for Linux Plus, so I won't explain it right here. 19 00:01:27,680 --> 00:01:33,480 So systemd-udev-d detects devices and will load the required kernel modules. 20 00:01:33,480 --> 00:01:37,959 And there's also a manual way of doing it, and that would be modprobe. 21 00:01:37,959 --> 00:01:42,800 And if you want to interface with devices, many, but not all of the devices have a device 22 00:01:42,800 --> 00:01:45,400 node file in slash dev. 23 00:01:45,400 --> 00:01:50,959 If you are going to use a hard disk, for instance, you use commands like mount slash dev slash 24 00:01:50,959 --> 00:01:51,959 sda1. 25 00:01:51,959 --> 00:01:59,480 Well, the dev sda1 is referring to your first partition, and this first partition addresses 26 00:01:59,480 --> 00:02:05,559 the appropriate kernel module to make sure that the device is initialized. 27 00:02:05,559 --> 00:02:10,919 And in this, the device nodes in the slash dev directory have a major number, and they 28 00:02:10,919 --> 00:02:12,479 have a minor number. 29 00:02:12,479 --> 00:02:16,160 And that indicates which kernel driver to use. 30 00:02:16,160 --> 00:02:21,880 And also, hardware-related parameters are stored in slash sys and its subdirectories. 31 00:02:21,880 --> 00:02:26,360 Let me show you a little bit of what's going on in this slash dev directory. 32 00:02:26,360 --> 00:02:32,679 So the part that I need you to be aware of is ls minus l slash dev slash, well, just 33 00:02:32,679 --> 00:02:33,679 slash dev. 34 00:02:33,679 --> 00:02:36,520 Here we can see all these device nodes. 35 00:02:36,520 --> 00:02:40,919 And in my list of device nodes, I'm looking up my storage device. 36 00:02:40,919 --> 00:02:45,919 I have an NVMe disk, and my NVMe disk is right here. 37 00:02:46,679 --> 00:02:48,440 And it's 259 comma 0. 38 00:02:48,440 --> 00:02:49,440 This is what matters. 39 00:02:49,440 --> 00:02:54,240 259 is the major, and the minor is 0. 40 00:02:54,240 --> 00:02:56,479 So the major addresses the driver. 41 00:02:56,479 --> 00:03:02,039 So here we can see 259 comma 1 for partition number 1, and so on. 42 00:03:02,039 --> 00:03:04,960 All of these devices have a major. 43 00:03:04,960 --> 00:03:09,720 And if you want to find out what that is, you need to have a look at the PROCFILE system, 44 00:03:09,720 --> 00:03:14,479 because in the PROCFILE system, there is a file with the name devices. 45 00:03:14,479 --> 00:03:19,759 The PROCFILE system is about kernel settings, about the current kernel state. 46 00:03:19,759 --> 00:03:24,479 If you investigate the PROCFILE system, you can learn so much about what is going on on 47 00:03:24,479 --> 00:03:25,479 your system. 48 00:03:25,479 --> 00:03:28,440 I'm going to use less on devices. 49 00:03:28,440 --> 00:03:32,720 And there we can see that it starts with a list of character devices. 50 00:03:32,720 --> 00:03:39,119 And then there is a list of block devices, where 259 is identified as a block ext. 51 00:03:39,119 --> 00:03:44,399 And block ext, well, that addresses the kernel functionality that is required. 52 00:03:44,399 --> 00:03:48,839 So there is a kernel module that makes sure that this device can be used.