1
00:00:00,000 --> 00:00:17,839
Hey guys and welcome back. So in the previous nugget we happened to mention that the kernel

2
00:00:17,839 --> 00:00:25,600
was modular, meaning that it relied on modules. So let's now dig in and discuss a little bit

3
00:00:25,600 --> 00:00:31,920
more about this subject. Now one thing to say that off the bat is that generally speaking you're

4
00:00:31,920 --> 00:00:37,520
not going to have to worry about loading particular modules with the kernel, this is going to be an

5
00:00:37,520 --> 00:00:44,719
automatic process. However there may be times where you want to manually intervene and take

6
00:00:44,719 --> 00:00:52,560
particular control of a particular module i.e to load that module or to remove that module and as such

7
00:00:52,560 --> 00:00:58,400
it is important that we do have a strong understanding of what that process would actually look like. So

8
00:00:58,400 --> 00:01:04,159
let's dive in and discuss some things we have to know then shall we. So in the previous nugget I

9
00:01:04,159 --> 00:01:10,480
happened to mention that if we go into the lib directory and then go into the modules directory

10
00:01:10,480 --> 00:01:18,079
within here we're going to have a folder for all of our kernels. Simply put each kernel has its own

11
00:01:18,079 --> 00:01:24,959
sub directory so this kernel here has its own sub directory whereas this one here has another one

12
00:01:24,959 --> 00:01:31,920
with its modules so on so forth and we learned the command we can use to identify the kernel

13
00:01:31,920 --> 00:01:37,920
running on our system is the uname command with the dash r flag to try to remember that command.

14
00:01:37,920 --> 00:01:44,640
So let's go into the folder or the sub directory of the kernel we are currently using and if we do

15
00:01:44,640 --> 00:01:51,519
an ls in fact let me long list this you're actually going to see we have a directory called kernel

16
00:01:51,519 --> 00:01:58,000
right here if i go into this directory and i list again we can see a whole bunch of sub directories

17
00:01:58,000 --> 00:02:04,400
relating to modules for particular features such as drivers network modules so on so forth. So if

18
00:02:04,400 --> 00:02:10,719
we wanted to see modules related to the file system we would go into the fs directory for file system

19
00:02:10,800 --> 00:02:18,159
and we do an ls we have some modules right here which end in .ko and as we can see here we actually

20
00:02:18,159 --> 00:02:25,520
have further directories relating to our file system so i could go into say for example ntfs

21
00:02:25,520 --> 00:02:33,919
to an ls and we can see the ntfs file system module for the kernel right here again with that .ko

22
00:02:33,919 --> 00:02:39,599
extension. Now the reason why you want to know the location of these particular modules is that if

23
00:02:39,599 --> 00:02:45,919
you want to load in a particular module certain tools will require you to specify the module's

24
00:02:45,919 --> 00:02:50,319
particular location so you have to be able to identify it. Now one thing to say is that when

25
00:02:50,319 --> 00:02:55,840
we want to copy a particular module there is a very specific command that we have to be aware of

26
00:02:55,840 --> 00:03:02,959
and that is called the depth mod command let me just clear my screen that will be depth mod so

27
00:03:02,960 --> 00:03:11,600
depth mod now what this command actually does it ultimately looks into the lib modules directory

28
00:03:11,600 --> 00:03:17,040
which we just saw and then the directory for that particular kernel number so that would be if i

29
00:03:17,040 --> 00:03:23,760
actually move back a few let me see the directory here looks in lib modules and then the subdirectory

30
00:03:23,760 --> 00:03:30,400
for the particular kernel and then it's going to ultimately grab all of the modules within the kernel

31
00:03:30,400 --> 00:03:37,360
directory within this folder so everything within here and it is going to generate what is called a

32
00:03:37,360 --> 00:03:43,920
modules .depth file now this file happens to be really quite important we do want to be remembering

33
00:03:43,920 --> 00:03:50,400
this one for sure and what it does it basically gives us a list of all the kernel modules and

34
00:03:50,400 --> 00:03:58,319
those module dependencies a dependency meaning that a module may actually rely on another module

35
00:03:58,319 --> 00:04:04,479
to operate so pretty much everything we actually need i.e all the modules and the modules which

36
00:04:04,479 --> 00:04:11,199
rely upon those modules will actually be specified within this modules .depth file that has been

37
00:04:11,199 --> 00:04:17,519
generated now one thing i really really want to highlight with respect to the depth mod command

38
00:04:17,519 --> 00:04:24,000
is that this command is only going to execute with respect to the current kernel in play so you

39
00:04:24,000 --> 00:04:29,759
know how i do have other kernels on my system again if i go back we do an ls we can see these

40
00:04:29,759 --> 00:04:36,879
three different kernel options the only one i happen to be running right now is 5.13.0.28 so

41
00:04:36,879 --> 00:04:43,120
it's only going to act within this directory right here and probe for the modules within

42
00:04:43,120 --> 00:04:50,399
this directory and its subsequent subdirectories now when a module happens to be loaded into memory

43
00:04:50,399 --> 00:04:56,479
we actually have a bunch of commands that we can do to ultimately check and manage these modules the

44
00:04:56,479 --> 00:05:04,079
first one we can do is the ls mod command this is going to allow us to list i.e ls the modules to

45
00:05:04,079 --> 00:05:10,879
check this out if i happen to run this command and i say ls mod we're going to get a whole bunch

46
00:05:10,879 --> 00:05:16,079
of output now if i scroll up to the very top here we can actually see the module name on the left

47
00:05:16,079 --> 00:05:24,000
hand side right here and the size of that particular module as well as any dependencies i.e what is this

48
00:05:24,000 --> 00:05:34,799
actually used by so we can see here btrfs actually uses the raid6pq module whereas the hfs module

49
00:05:34,799 --> 00:05:41,120
no additional modules are actually reliant upon this module and i suppose i should actually mention

50
00:05:41,120 --> 00:05:47,280
is that the size here we're actually looking at this is in bytes just for clarity there now if you

51
00:05:47,280 --> 00:05:53,920
want to be able to remove or unload a particular module you're going to have to make sure that this

52
00:05:53,920 --> 00:06:00,399
particular module has the value zero in the third column that means that it's not being used by something

53
00:06:00,399 --> 00:06:08,079
else therefore it can be successfully removed whereas if we try to remove this module right here

54
00:06:08,159 --> 00:06:14,399
we can see it's been used by vbox video therefore we're not going to be able to do such a thing now

55
00:06:14,399 --> 00:06:22,079
if i want to be able to manually remove a particular module i can use the rm mod commander again

56
00:06:22,079 --> 00:06:29,360
these commands are quite appropriately named rm typically in linux is for remove such as rm a

57
00:06:29,360 --> 00:06:37,120
particular file and we want to remove a particular module so rm mod the name itself is quite descriptive

58
00:06:37,120 --> 00:06:43,040
once you actually understand the linux jargon so if i examine some of the output right here take

59
00:06:43,040 --> 00:06:50,480
for example this one right here pata acpi what i can do is actually remove this then okay so first

60
00:06:50,480 --> 00:06:56,480
thing i will do is i will say ls mod that gives us a listing and what i'm going to do is i will

61
00:06:56,480 --> 00:07:04,240
actually grip for pata so we can clearly see it's loaded but if i happen to say rm mod and then say

62
00:07:04,240 --> 00:07:11,600
pata acpi and notice one thing i should have actually pointed out when we are making these

63
00:07:11,600 --> 00:07:17,360
kernel changes this is going to require super user privileges so what i'll actually do is i will just

64
00:07:17,360 --> 00:07:23,920
become the root user type in the old passwords there we go so i'm now the root user let's try

65
00:07:23,920 --> 00:07:31,840
this command again say ls mod grip pata it's still loaded if i now say rm mod and then give the name

66
00:07:31,839 --> 00:07:39,759
of the module pata acpi if i hit enter this module will now be removed if i actually check again

67
00:07:40,319 --> 00:07:48,239
notice the output of the ls mod command we actually don't have any output for pata acpi it has been

68
00:07:48,239 --> 00:07:56,559
successfully removed now if i want to actually insert a particular module we have a command called

69
00:07:56,560 --> 00:08:04,000
insmod so insmod insert module again really quite easy to remember once you understand the jargon

70
00:08:04,000 --> 00:08:11,840
the difference here is that if i just happen to say insmod you know like pata acpi notice it's

71
00:08:11,840 --> 00:08:19,680
saying there is no such file or directory we have to be able to identify where about this particular

72
00:08:19,680 --> 00:08:24,800
module is so what i can do though is i can clear the screen and i can try to clear the screen by not

73
00:08:24,800 --> 00:08:30,240
mashing the keyboard and i'll use our trusty fine command we learned about this command in the lpik

74
00:08:30,240 --> 00:08:36,560
one examination so what i will do here is i will search for absolutely everything which we can see

75
00:08:36,560 --> 00:08:41,600
here but i'll stop this right now and instead i will actually grip for what i'm looking for so

76
00:08:41,600 --> 00:08:48,879
i'll grip for pata acpi notice we actually see the output here we need to pick the one which

77
00:08:48,879 --> 00:08:56,639
corresponds to our particular kernel so i'll say uname dash r so it will be in this one right here

78
00:08:56,639 --> 00:09:05,600
5 13028 folder and i can use this with the insmod command so i can say insmod and i will just copy

79
00:09:05,600 --> 00:09:12,000
this location right here paste it in again with the dot ko extension this is what we have for

80
00:09:12,000 --> 00:09:18,639
our modules for the kernel if i now hit enter this should now reload this module back into the kernel

81
00:09:18,879 --> 00:09:26,559
and again if i happen to run my ls mod command and to enter notice this module has been successfully

82
00:09:26,559 --> 00:09:32,480
loaded once again and in fact if i just run the ls mod command on itself this module should

83
00:09:32,480 --> 00:09:37,519
actually be at the very top of the output you see that right here because it was the last one loaded

84
00:09:37,519 --> 00:09:43,519
in so if you want to load in a particular module manually you can use the insmod command this is

85
00:09:43,600 --> 00:09:49,519
kind of deemed the more difficult way because again we have to manually identify the particular

86
00:09:49,519 --> 00:09:56,480
location of the module itself but we do have a more modern approach and in my opinion a much

87
00:09:56,480 --> 00:10:02,799
better approach and we can do this using the mod probe command this is deemed the much easier

88
00:10:02,799 --> 00:10:10,000
and simpler way to handle such a task so previously we were removing and re-adding the pata acpi

89
00:10:10,559 --> 00:10:15,360
module we can do the same thing using mod probe so what i will do is i'll say mod probe and i will

90
00:10:15,360 --> 00:10:22,399
say dash r this is for removing and now i just give the name of this particular module and that

91
00:10:22,399 --> 00:10:29,360
should it be now removed if i do an ls mod it will no longer be there again if i grip for pata

92
00:10:29,360 --> 00:10:36,080
it is no longer there now this time when i want to reload this module using the mod probe command

93
00:10:36,080 --> 00:10:43,280
i don't have to specify an absolute path i can just say mod probe pata acpi and hit enter

94
00:10:43,280 --> 00:10:51,120
and if i check my ls mod notice it has been loaded in once again now why is it the mod probe command

95
00:10:51,120 --> 00:10:57,600
is able to almost magically and automatically handle this process is that mod probe is getting

96
00:10:57,600 --> 00:11:03,520
this information from whereabouts well it was the information we talked about when we run the

97
00:11:03,519 --> 00:11:11,840
dep mod command what does that command actually generate it generates a modules dot d e b file

98
00:11:11,840 --> 00:11:18,399
in which case this ultimately tells us all of our modules and our module dependencies so mod probe

99
00:11:18,399 --> 00:11:24,799
is looking into this file and just by simply giving the module name it can solve all the other issues

100
00:11:24,799 --> 00:11:31,679
itself directly so way way way easier than having to manually provide full pass yourself but like i

101
00:11:31,679 --> 00:11:37,839
say you are way more likely to never actually have to need to use these tools because the kernel will

102
00:11:37,839 --> 00:11:44,559
handle the loading and removing of these modules on the fly automatically but in the event that maybe

103
00:11:44,559 --> 00:11:50,639
a particular module is causing an error maybe you have to manually intervene and remove and maybe

104
00:11:50,639 --> 00:11:57,279
reload that module or perhaps you just want to free up additional memory by proactively going in

105
00:11:57,279 --> 00:12:02,799
and removing modules which have been automatically loaded which you have deemed unnecessary for the

106
00:12:02,799 --> 00:12:08,159
operation of your system in which case being able to understand these tools are really going to be

107
00:12:08,159 --> 00:12:15,120
advantageous to you as you manage your linux system okay doc so that is us for our introduction into

108
00:12:15,120 --> 00:12:20,399
the modules of the kernel and i hope this has been informative for you and i'd like to thank you for viewing

