1 00:00:00,000 --> 00:00:11,440 In the end, working with devices on Linux is all about working with kernel modules. 2 00:00:11,440 --> 00:00:16,120 Because for every device that you are using, a kernel module is required. 3 00:00:16,120 --> 00:00:21,959 Kernel modules are loaded first through InitRAMFS or InitRD while you are booting. 4 00:00:21,959 --> 00:00:27,320 InitRAMFS or InitRD are system specific and they are automatically generated at the end 5 00:00:27,320 --> 00:00:32,599 of the installation to make sure that you have all the configuration that you need inside. 6 00:00:32,599 --> 00:00:39,520 Where InitRAMFS is what you will find on Red Hat oriented Linux and InitRD is the equivalent 7 00:00:39,520 --> 00:00:40,919 on Ubuntu. 8 00:00:40,919 --> 00:00:44,080 You can find the result in the slash boot directory. 9 00:00:44,080 --> 00:00:50,160 If ever you need to manually trigger the generation of an InitRAMFS, you use DRAKUT. 10 00:00:50,160 --> 00:00:51,759 That's a Red Hat utility. 11 00:00:51,759 --> 00:00:54,599 Now the big question is why would you want to do that? 12 00:00:54,599 --> 00:00:59,919 Well you might want to do that if you have just installed this fancy new GPU card in 13 00:00:59,919 --> 00:01:02,680 your system for instance. 14 00:01:02,680 --> 00:01:07,480 Then your InitRAMFS won't know about it and you need to regenerate it. 15 00:01:07,480 --> 00:01:11,040 Use DRAKUT or DRAKUT-F to force it. 16 00:01:11,040 --> 00:01:16,839 To do the equivalent on Ubuntu, you use MKInitRAMFS. 17 00:01:16,839 --> 00:01:23,160 Now when you are booting, systemd starts systemd-udevd to manage on-demand loading of kernel modules. 18 00:01:23,160 --> 00:01:28,440 So when you plug in a USB thumb drive that contains a VFAT file system which hasn't been 19 00:01:28,440 --> 00:01:35,199 mounted yet, well systemd-udevd makes sure that the VFAT kernel module will be loaded. 20 00:01:35,199 --> 00:01:41,199 And manual loading can be done as well using modprobe and the deprecated insmod command. 21 00:01:41,199 --> 00:01:47,040 But you will notice that the automatic procedure is so good that you rarely will use modprobe 22 00:01:47,040 --> 00:01:50,199 to manually load kernel modules. 23 00:01:50,239 --> 00:01:53,360 Nevertheless, let's discuss how it works. 24 00:01:53,360 --> 00:01:59,320 So if you want to see if manual loading is necessary, first you need to find out if your 25 00:01:59,320 --> 00:02:01,959 device already has a kernel module. 26 00:02:01,959 --> 00:02:06,279 lspci-k is an awesome command to find out. 27 00:02:06,279 --> 00:02:09,279 Next you can get kernel module parameters. 28 00:02:09,279 --> 00:02:12,479 Use modinfo on the kernel module that you want to use. 29 00:02:12,479 --> 00:02:19,759 And then modprobe can be used to manually load the modules including all of their dependencies. 30 00:02:19,759 --> 00:02:22,479 To do the opposite, use modprobe-r. 31 00:02:22,479 --> 00:02:26,639 That will remove manually loaded kernel modules. 32 00:02:26,639 --> 00:02:30,800 And these kernel module dependencies, well there is depmod. 33 00:02:30,800 --> 00:02:37,240 And depmod is a process that runs to automatically generate kernel module dependencies. 34 00:02:37,240 --> 00:02:41,360 Normally you don't have to worry about depmod, but if ever you are loading a kernel module 35 00:02:41,360 --> 00:02:46,080 and you feel you are missing a dependency, it doesn't hurt to run the depmod utility 36 00:02:46,080 --> 00:02:48,279 manually. 37 00:02:48,279 --> 00:02:56,919 In old Linux releases, insmod and rmmod were used, but these really are deprecated nowadays. 38 00:02:56,919 --> 00:03:00,600 Final thing you need to know about kernel modules is that they can come with kernel 39 00:03:00,600 --> 00:03:01,600 module parameters. 40 00:03:01,600 --> 00:03:06,639 Modinfo is what you use to find available parameters. 41 00:03:06,639 --> 00:03:15,160 And you can specify the parameters in etcmodprobe.conf and or in drop-in files in etcmodprobe.d. 42 00:03:15,160 --> 00:03:19,759 And alternatively, you can use the parameter name followed by its value as an argument 43 00:03:19,759 --> 00:03:23,759 while manually loading the parameter. 44 00:03:23,759 --> 00:03:27,000 Now messages about loading parameters are not consistent. 45 00:03:27,000 --> 00:03:32,160 And as a result, it can be hard to find out if your kernel module has correctly identified 46 00:03:32,160 --> 00:03:33,160 the parameter. 47 00:03:33,160 --> 00:03:38,399 But you can give it a try using dmessage or files in sysmodules. 48 00:03:38,399 --> 00:03:43,960 Let me show you and let me show you specifically how we can use kernel module parameters. 49 00:03:43,960 --> 00:03:44,960 I'm using lsmod. 50 00:03:44,960 --> 00:03:51,320 lsmod is giving a list of all the kernel modules that are currently loaded. 51 00:03:51,320 --> 00:03:54,479 And I'm going for cdrom. 52 00:03:54,479 --> 00:03:57,399 That's a relatively innocent kernel module. 53 00:03:57,399 --> 00:04:02,080 We can see this cdrom as a kernel as a lot of dependencies, and we can see them right 54 00:04:02,080 --> 00:04:03,080 here like srmod. 55 00:04:03,080 --> 00:04:09,279 srmod is a SQSY cdrom module, which is backing the cdrom module. 56 00:04:09,279 --> 00:04:13,399 Now if I want to know what is going on, I'm using modinfo. 57 00:04:14,119 --> 00:04:15,119 On cdrom. 58 00:04:15,119 --> 00:04:18,959 And modinfo is showing me a list of parameters. 59 00:04:18,959 --> 00:04:23,200 And I'm going for the parameter debug, which is a boolean. 60 00:04:23,200 --> 00:04:29,000 Debug is logging additional information if anything is happening to the dmessage output. 61 00:04:29,000 --> 00:04:34,640 So I want cdrom to be loaded with the parameter debug is 1. 62 00:04:34,640 --> 00:04:40,079 Boolean is an on-off value, so typically 0 and 1 would work. 63 00:04:40,079 --> 00:04:48,920 I'm going into etcmodprobe.d because etcmodprobe.d contains a couple of example files. 64 00:04:48,920 --> 00:04:52,920 And I do not want anything that is a blacklist. 65 00:04:52,920 --> 00:04:55,720 Oh, we only have blacklists? 66 00:04:55,720 --> 00:04:59,160 Blacklists are to prevent the loading of specific kernel modules. 67 00:04:59,160 --> 00:05:00,480 I don't want them. 68 00:05:00,480 --> 00:05:06,200 So I'm going to have a look at usrlibmodprobe.d. 69 00:05:06,200 --> 00:05:11,040 You remember, etc is for the customization, usrlib is for the standard stuff. 70 00:05:11,040 --> 00:05:15,519 And maybe we have something in the standard configuration that I do like. 71 00:05:15,519 --> 00:05:19,359 And there I can see a potential candidate, this alsa. 72 00:05:19,359 --> 00:05:23,519 This alsa is for the alsa sound module. 73 00:05:23,519 --> 00:05:26,559 And there we can see some options. 74 00:05:26,559 --> 00:05:29,920 Well, honestly, I also don't like it. 75 00:05:29,920 --> 00:05:31,320 Now what are we going to do? 76 00:05:31,320 --> 00:05:38,480 Well, man-kmodprobe, I want to know if there is any decent documentation about modprobe.conf. 77 00:05:38,480 --> 00:05:41,880 So man on modprobe.conf. 78 00:05:41,880 --> 00:05:47,119 Let's check it out to see if we have anything that we can do in here. 79 00:05:47,119 --> 00:05:49,559 So we have install. 80 00:05:49,559 --> 00:05:55,799 I don't care about install because install is for running a specific command. 81 00:05:55,799 --> 00:05:57,320 I care about options. 82 00:05:57,320 --> 00:05:58,440 This is the one I need. 83 00:05:58,480 --> 00:06:02,799 So we need options, cdrom, debug is one, finally. 84 00:06:02,799 --> 00:06:10,160 So vim on etc modprobe.d cdrom.conf. 85 00:06:10,160 --> 00:06:16,160 And I'm going to put in options, cdrom, debug is one. 86 00:06:16,160 --> 00:06:18,480 And that should be doing it. 87 00:06:18,480 --> 00:06:19,320 All right. 88 00:06:19,320 --> 00:06:22,959 Now I'm going to use modprobe minus r cdrom. 89 00:06:22,959 --> 00:06:28,279 I'm trying to unload cdrom, but unfortunately, cdrom is in use. 90 00:06:28,880 --> 00:06:30,000 Okay. 91 00:06:30,000 --> 00:06:34,079 That means that it is automatically started, and I'm going to reboot. 92 00:06:34,079 --> 00:06:40,799 And after the reboot, we are going to see if we can find anything about these options. 93 00:06:40,799 --> 00:06:45,079 So now we are back, and I'm going to use dmessage, pipe less, 94 00:06:45,079 --> 00:06:49,480 because less allows me to search for it, and I'm searching for cdrom. 95 00:06:49,480 --> 00:06:52,839 And here we can see cdrom. 96 00:06:52,839 --> 00:06:57,359 That's not very much information, and n isn't giving me anything either. 97 00:06:57,359 --> 00:07:03,959 Now, as I mentioned before, it's not always easy to find information about parameters. 98 00:07:03,959 --> 00:07:08,519 The other choice that you've got is in the sysmodules file system. 99 00:07:08,519 --> 00:07:15,279 You go to cdrom, and there you might have a subdirectory with the name parameters. 100 00:07:15,279 --> 00:07:20,200 I don't, so apparently this module doesn't clearly keep track of its parameters. 101 00:07:20,200 --> 00:07:22,000 Too bad, but that's the way it is.