1
00:00:00,005 --> 00:00:03,007
- [Instructor] The Linux kernel is modular.

2
00:00:03,007 --> 00:00:08,004
You can have Loadable Kernel Modules, LKMs.

3
00:00:08,004 --> 00:00:11,003
An LKM is an object file.

4
00:00:11,003 --> 00:00:13,009
It's got a .ko suffix,

5
00:00:13,009 --> 00:00:17,003
and then compressed ones have a .zst after that,

6
00:00:17,003 --> 00:00:20,000
so, .ko.zst.

7
00:00:20,000 --> 00:00:22,007
So these have code,

8
00:00:22,007 --> 00:00:25,001
and that code's going to run in kernel space.

9
00:00:25,001 --> 00:00:28,007
So this gets dynamically linked into the kernel,

10
00:00:28,007 --> 00:00:31,006
and now there's more functions in the kernel.

11
00:00:31,006 --> 00:00:34,003
Usually, these are written in C,

12
00:00:34,003 --> 00:00:38,000
and they're compiled for a particular kernel version.

13
00:00:38,000 --> 00:00:40,008
So you have copies of the modules

14
00:00:40,008 --> 00:00:44,000
for each kernel you have installed.

15
00:00:44,000 --> 00:00:47,007
Kernel modules are not binary compatible

16
00:00:47,007 --> 00:00:48,009
with different kernels.

17
00:00:48,009 --> 00:00:50,008
That's important because data structures

18
00:00:50,008 --> 00:00:52,000
could be different, for example,

19
00:00:52,000 --> 00:00:54,005
in different kernel versions.

20
00:00:54,005 --> 00:00:57,006
it's really nice that the kernel is modular.

21
00:00:57,006 --> 00:00:59,008
That means that the kernel file itself

22
00:00:59,008 --> 00:01:02,007
can be relatively small,

23
00:01:02,007 --> 00:01:06,007
and then you can just add functionality to the kernel

24
00:01:06,007 --> 00:01:08,002
after you boot.

25
00:01:08,002 --> 00:01:09,005
And that's common.

26
00:01:09,005 --> 00:01:15,001
There are lots of modules probably loaded in your kernel.

27
00:01:15,001 --> 00:01:19,004
And it also means that you don't have to build your kernel,

28
00:01:19,004 --> 00:01:21,003
say, with all possible ethernet drivers.

29
00:01:21,003 --> 00:01:26,006
You just add the ones that you need after it's booted.

30
00:01:26,006 --> 00:01:30,007
It makes for a much less memory usage, for example, right?

31
00:01:30,007 --> 00:01:34,001
And you can do a live update, potentially.

32
00:01:34,001 --> 00:01:35,005
Generally, it's not such a good idea

33
00:01:35,005 --> 00:01:41,004
to ever remove a module, because it's kind of risky,

34
00:01:41,004 --> 00:01:43,000
but, certainly, during development,

35
00:01:43,000 --> 00:01:46,005
if you're writing kernel code, and it could be a module,

36
00:01:46,005 --> 00:01:48,008
then you can load your code, give it a try,

37
00:01:48,008 --> 00:01:50,007
"Oh, that didn't work,"

38
00:01:50,007 --> 00:01:53,005
make changes, unload the previous version,

39
00:01:53,005 --> 00:01:55,005
load the new version.

40
00:01:55,005 --> 00:01:57,000
It's really handy.

