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 init-ramfs or init-rd while you are booting.

4
00:00:21,959 --> 00:00:27,100
Init-ramfs or init-rd are system specific and they are automatically generated at the

5
00:00:27,100 --> 00:00:31,900
end of the installation to make sure that you have all the configuration that you need

6
00:00:31,900 --> 00:00:32,900
inside.

7
00:00:32,900 --> 00:00:38,740
Where init-ramfs is what you will find on Red Hat oriented Linux and init-rd is the

8
00:00:38,740 --> 00:00:40,939
equivalent on Ubuntu.

9
00:00:40,939 --> 00:00:44,099
You can find the result in the slash boot directory.

10
00:00:44,099 --> 00:00:49,419
If ever you need to manually trigger the generation of an init-ramfs, you use DRAKUT.

11
00:00:49,419 --> 00:00:51,820
That's a Red Hat utility.

12
00:00:51,820 --> 00:00:54,340
Now the big question is, why would you want to do that?

13
00:00:54,340 --> 00:00:59,900
Well, you might want to do that if you have just installed this fancy new GPU card in

14
00:00:59,900 --> 00:01:02,660
your system, for instance.

15
00:01:02,660 --> 00:01:07,459
Then your init-ramfs won't know about it and you need to regenerate it.

16
00:01:07,459 --> 00:01:11,019
Use DRAKUT or DRAKUT-F to force it.

17
00:01:11,019 --> 00:01:16,779
To do the equivalent on Ubuntu, you use mkinitramfs.

18
00:01:16,779 --> 00:01:23,139
Now when you are booting, systemd starts systemd-udevd to manage on-demand loading of kernel modules.

19
00:01:23,139 --> 00:01:28,419
So when you plug in a USB thumb drive that contains a VFAT file system which hasn't been

20
00:01:28,419 --> 00:01:35,180
mounted yet, well, systemd-udevd makes sure that the VFAT kernel module will be loaded.

21
00:01:35,180 --> 00:01:41,180
And manual loading can be done as well using modprobe and the deprecated intmod command.

22
00:01:41,180 --> 00:01:47,019
But you will notice that the automatic procedure is so good that you rarely will use modprobe

23
00:01:47,019 --> 00:01:50,099
to manually load kernel modules.

24
00:01:50,139 --> 00:01:53,339
Nevertheless, let's discuss how it works.

25
00:01:53,339 --> 00:01:59,300
So if you want to see if manual loading is necessary, first you need to find out if your

26
00:01:59,300 --> 00:02:01,860
device already has a kernel module.

27
00:02:01,860 --> 00:02:06,260
lspci-k is an awesome command to find out.

28
00:02:06,260 --> 00:02:09,259
Next you can get kernel module parameters.

29
00:02:09,259 --> 00:02:12,460
Use modinfo on the kernel module that you want to use.

30
00:02:12,460 --> 00:02:19,740
And then modprobe can be used to manually load the modules, including all of their dependencies.

31
00:02:19,740 --> 00:02:22,460
To do the opposite, use modprobe-r.

32
00:02:22,460 --> 00:02:26,619
That will remove manually loaded kernel modules.

33
00:02:26,619 --> 00:02:30,779
And these kernel module dependencies, well, there is depmod.

34
00:02:30,779 --> 00:02:37,220
And depmod is a process that runs to automatically generate kernel module dependencies.

35
00:02:37,220 --> 00:02:41,339
Normally you don't have to worry about depmod, but if ever you are loading a kernel module

36
00:02:41,339 --> 00:02:46,100
and you feel you are missing a dependency, it doesn't hurt to run the depmod utility

37
00:02:46,100 --> 00:02:48,259
manually.

38
00:02:48,259 --> 00:02:56,899
In old Linux releases, insmod and rmmod were used, but these really are deprecated nowadays.

39
00:02:56,899 --> 00:03:00,619
Final thing you need to know about kernel modules is that they can come with kernel

40
00:03:00,619 --> 00:03:01,619
module parameters.

41
00:03:01,619 --> 00:03:06,619
Modinfo is what you use to find available parameters.

42
00:03:06,619 --> 00:03:15,139
And you can specify the parameters in etcmodprobe.conf and or in drop-in files in etcmodprobe.d.

43
00:03:15,139 --> 00:03:19,740
And alternatively, you can use a parameter name followed by its value as an argument

44
00:03:19,740 --> 00:03:23,779
while manually loading the parameter.

45
00:03:23,779 --> 00:03:27,020
Now messages about loading parameters are not consistent.

46
00:03:27,020 --> 00:03:32,139
And as a result, it can be hard to find out if your kernel module has correctly identified

47
00:03:32,139 --> 00:03:33,139
the parameter.

48
00:03:33,139 --> 00:03:38,399
But you can give it a try using dmessage or files in sysmodules.

49
00:03:38,399 --> 00:03:43,979
Let me show you, and let me show you specifically how we can use kernel module parameters.

50
00:03:43,979 --> 00:03:44,979
I'm using lsmod.

51
00:03:44,979 --> 00:03:51,300
lsmod is giving a list of all the kernel modules that are currently loaded.

52
00:03:51,300 --> 00:03:54,460
And I'm going for cdrom.

53
00:03:54,460 --> 00:03:57,380
That's a relatively innocent kernel module.

54
00:03:57,380 --> 00:04:02,059
We can see the cdrom as a kernel as a lot of dependencies, and we can see them right

55
00:04:02,059 --> 00:04:03,059
here, like srmod.

56
00:04:03,059 --> 00:04:09,300
srmod is a SCSI cdrom module, which is backing the cdrom module.

57
00:04:09,300 --> 00:04:13,419
Now if I want to know what is going on, I'm using modinfo.

58
00:04:13,860 --> 00:04:18,940
On cdrom, and modinfo is showing me a list of parameters.

59
00:04:18,940 --> 00:04:23,179
And I'm going for the parameter debug, which is a boolean.

60
00:04:23,179 --> 00:04:29,019
Debug is logging additional information if anything is happening to the dmessage output.

61
00:04:29,019 --> 00:04:34,660
So I want cdrom to be loaded with the parameter debug is 1.

62
00:04:34,660 --> 00:04:40,059
Boolean is an on-off value, so typically 0 and 1 would work.

63
00:04:40,059 --> 00:04:48,940
I'm going into etcmodprobe.d because etcmodprobe.d contains a couple of example files.

64
00:04:48,940 --> 00:04:52,899
And I do not want anything that is a blacklist.

65
00:04:52,899 --> 00:04:55,739
Oh, we only have blacklists?

66
00:04:55,739 --> 00:04:59,179
Blacklists are to prevent the loading of specific kernel modules.

67
00:04:59,179 --> 00:05:00,459
I don't want them.

68
00:05:00,459 --> 00:05:06,220
So I'm going to have a look at usrlibmodprobe.d.

69
00:05:06,220 --> 00:05:08,779
So remember, etc is for the customization.

70
00:05:08,779 --> 00:05:10,899
Usrlib is for the standard stuff.

71
00:05:10,899 --> 00:05:15,420
And maybe we have something in the standard configuration that I do like.

72
00:05:15,420 --> 00:05:19,179
And there I can see a potential candidate, this ALSA.

73
00:05:19,179 --> 00:05:23,059
This ALSA is for the ALSA sound module.

74
00:05:23,059 --> 00:05:26,660
And there we can see some options.

75
00:05:26,660 --> 00:05:29,820
Well, honestly, I also don't like it.

76
00:05:29,820 --> 00:05:31,339
Now what are we going to do?

77
00:05:31,339 --> 00:05:38,500
Well, man-kmodprobe, I want to know if there is any decent documentation about modprobe.conf.

78
00:05:38,500 --> 00:05:41,899
So man on modprobe.conf.

79
00:05:41,899 --> 00:05:47,140
Let's check it out to see if we have anything that we can do in here.

80
00:05:47,140 --> 00:05:49,579
So we have install.

81
00:05:49,579 --> 00:05:55,820
I don't care about install because install is for running a specific command.

82
00:05:55,820 --> 00:05:57,339
I care about options.

83
00:05:57,339 --> 00:05:58,459
This is the one I need.

84
00:05:58,459 --> 00:06:02,779
So we need options, CD-ROM debug is one, finally.

85
00:06:02,779 --> 00:06:10,140
So vim on etc modprobe.d CD-ROM.conf.

86
00:06:10,140 --> 00:06:16,140
And I'm going to put in options, CD-ROM debug is one.

87
00:06:16,140 --> 00:06:18,459
And that should be doing it.

88
00:06:18,459 --> 00:06:19,299
All right.

89
00:06:19,299 --> 00:06:22,940
Now I'm going to use modprobe-r CD-ROM.

90
00:06:22,940 --> 00:06:28,260
I'm trying to unload CD-ROM, but unfortunately, CD-ROM is in use.

91
00:06:28,859 --> 00:06:29,980
Okay.

92
00:06:29,980 --> 00:06:34,059
That means that it is automatically started and I'm going to reboot.

93
00:06:34,059 --> 00:06:40,779
And after the reboot, we are going to see if we can find anything about these options.

94
00:06:40,779 --> 00:06:45,059
So now we are back and I'm going to use dmessage, pipe less,

95
00:06:45,059 --> 00:06:47,260
because less allows me to search for it.

96
00:06:47,260 --> 00:06:49,459
And I'm searching for CD-ROM.

97
00:06:49,459 --> 00:06:54,779
And here we can see CD-ROM, that's not very much information.

98
00:06:54,779 --> 00:06:57,339
And N isn't giving me anything either.

99
00:06:57,339 --> 00:07:03,940
Now, as I mentioned before, it's not always easy to find information about parameters.

100
00:07:03,940 --> 00:07:08,500
The other choice that you've got is in the sysmodules file system.

101
00:07:08,500 --> 00:07:15,260
You go to CD-ROM and there you might have a subdirectory with the name parameters.

102
00:07:15,260 --> 00:07:20,179
I don't, so apparently this module doesn't clearly keep track of its parameters.

103
00:07:20,179 --> 00:07:21,980
Too bad, but that's the way it is.

