1 00:00:06,900 --> 00:00:09,900 - In this video, I'll tell you about kernel modules. 2 00:00:09,900 --> 00:00:12,570 A kernel module is an object file containing code 3 00:00:12,570 --> 00:00:14,970 that extends the Linux kernel. 4 00:00:14,970 --> 00:00:17,610 An object file is what you get when you compile a file 5 00:00:17,610 --> 00:00:20,340 that is written in the C programming language. 6 00:00:20,340 --> 00:00:22,440 And for every single piece of hardware, 7 00:00:22,440 --> 00:00:25,113 you need a kernel module in order to use it. 8 00:00:26,070 --> 00:00:29,100 Kernel modules are obtained from the initramfs, 9 00:00:29,100 --> 00:00:31,320 which is created upon system installation 10 00:00:31,320 --> 00:00:33,390 to match all hardware that is found 11 00:00:33,390 --> 00:00:35,013 while your system was installed. 12 00:00:36,450 --> 00:00:37,890 There is systemd-udevd, 13 00:00:37,890 --> 00:00:40,170 which is used as a plug-and-play manager 14 00:00:40,170 --> 00:00:43,350 to load kernel files dynamically when needed. 15 00:00:43,350 --> 00:00:44,700 And alternatively, 16 00:00:44,700 --> 00:00:47,193 kernel files can be loaded manually, as well. 17 00:00:49,320 --> 00:00:51,390 So how do we manage kernel modules? 18 00:00:51,390 --> 00:00:53,790 Well, there's a couple of commands involved 19 00:00:53,790 --> 00:00:57,720 like lsmod, which shows all modules currently loaded. 20 00:00:57,720 --> 00:01:01,140 And modprobe, which is used to manually load a kernel file, 21 00:01:01,140 --> 00:01:02,913 including its dependencies. 22 00:01:03,750 --> 00:01:05,310 There is modprobe -r, 23 00:01:05,310 --> 00:01:08,370 which is used to manually unload a kernel file. 24 00:01:08,370 --> 00:01:09,480 And modinfo, 25 00:01:09,480 --> 00:01:12,960 which provides information about kernel modules. 26 00:01:12,960 --> 00:01:16,500 And then there is depmod, which generates the modules.dep 27 00:01:16,500 --> 00:01:18,393 kernel module dependency file. 28 00:01:19,560 --> 00:01:22,770 Kernel module parameters are listed by modinfo. 29 00:01:22,770 --> 00:01:25,200 And they can be specified in include files 30 00:01:25,200 --> 00:01:26,970 in /etc/modprobe.d/, 31 00:01:26,970 --> 00:01:30,423 which allows you to change default kernel module parameters. 32 00:01:31,320 --> 00:01:33,300 All right. So let me demonstrate 33 00:01:33,300 --> 00:01:36,000 how you can manage kernel modules. 34 00:01:36,000 --> 00:01:37,860 I composed a small demo. 35 00:01:37,860 --> 00:01:41,220 Most important steps are on the slides. 36 00:01:41,220 --> 00:01:45,000 Feel free to post the video and try for yourself. 37 00:01:45,000 --> 00:01:47,493 And then, you can watch what I've been doing. 38 00:01:48,690 --> 00:01:50,103 So let's go for it. 39 00:01:53,550 --> 00:01:55,380 So first, lsmod. 40 00:01:55,380 --> 00:01:57,210 The lsmod command to show when all the kernel modules 41 00:01:57,210 --> 00:01:59,490 that are currently loaded. 42 00:01:59,490 --> 00:02:04,020 I wanna know if we have cdrom available. 43 00:02:04,020 --> 00:02:05,610 And there we can see that right now, 44 00:02:05,610 --> 00:02:08,373 we do have cdrom, which is loaded. 45 00:02:09,210 --> 00:02:12,933 So I want to unload modprobe -r cdrom. 46 00:02:13,770 --> 00:02:15,300 And uh oh. What do we get? 47 00:02:15,300 --> 00:02:17,523 We get module cdrom is in use. 48 00:02:18,420 --> 00:02:20,730 Before continuing, it's a good idea 49 00:02:20,730 --> 00:02:22,863 to verify that you have nothing mounted. 50 00:02:24,930 --> 00:02:28,140 The findmnt command is a convenient way to figure out 51 00:02:28,140 --> 00:02:31,500 if anything related to your cdrom is currently mounted. 52 00:02:31,500 --> 00:02:36,500 Look at the second column and look for either sr0 or cdrom. 53 00:02:36,540 --> 00:02:38,070 And if you can find it in here, 54 00:02:38,070 --> 00:02:40,470 you mount it before continuing. 55 00:02:40,470 --> 00:02:44,190 If you don't find it, as is the case right here, 56 00:02:44,190 --> 00:02:46,140 we need to make sure that we get rid of 57 00:02:46,140 --> 00:02:48,330 this module cdrom is in use. 58 00:02:48,330 --> 00:02:49,560 Now, why do we get this? 59 00:02:49,560 --> 00:02:52,560 Well, we get it because we have isofs. 60 00:02:52,560 --> 00:02:55,890 Isofs is currently using the cdrom module. 61 00:02:55,890 --> 00:03:00,090 And that means that we can't unload it at this moment. 62 00:03:00,090 --> 00:03:02,730 You may see, depending who your current configuration, 63 00:03:02,730 --> 00:03:05,970 other modules, as well, like sr_mod. 64 00:03:05,970 --> 00:03:07,650 And if you see them, well, 65 00:03:07,650 --> 00:03:09,930 you need to unload these dependencies. 66 00:03:09,930 --> 00:03:14,930 So modprobe -r isofs. 67 00:03:16,650 --> 00:03:20,190 And then, we can try the modprobe -r cdrom again. 68 00:03:20,190 --> 00:03:22,503 And as you can see, now it is working. 69 00:03:23,370 --> 00:03:24,990 Now, I would like to show you 70 00:03:24,990 --> 00:03:28,620 modprobe on isofs, at this moment. 71 00:03:28,620 --> 00:03:31,410 Because what is modprobe isofs doing? 72 00:03:31,410 --> 00:03:34,263 Well, this module has a dependency. 73 00:03:35,790 --> 00:03:37,950 And as a result, right now, 74 00:03:37,950 --> 00:03:40,350 we can see that cdrom is available again. 75 00:03:40,350 --> 00:03:41,730 We just unloaded it. 76 00:03:41,730 --> 00:03:44,670 We did not load it again, but we loaded isofs. 77 00:03:44,670 --> 00:03:46,860 And because we loaded isofs, 78 00:03:46,860 --> 00:03:49,230 isofs has triggered the dependency, 79 00:03:49,230 --> 00:03:52,710 and for that reason, cdrom is now here. 80 00:03:52,710 --> 00:03:55,440 And that brings us back to our starting point 81 00:03:55,440 --> 00:03:57,720 modprobe -r cdrom. 82 00:03:57,720 --> 00:04:00,840 It's not going to work, but at least you know why. 83 00:04:00,840 --> 00:04:02,820 And this concludes the small demo 84 00:04:02,820 --> 00:04:04,683 about managing kernel modules.