1
00:00:00,005 --> 00:00:04,006
- [Instructor] Building a kernel is a pretty big deal,

2
00:00:04,006 --> 00:00:07,005
pretty powerful thing to do.

3
00:00:07,005 --> 00:00:09,003
Lots involved.

4
00:00:09,003 --> 00:00:11,007
The build uses a lot of utilities,

5
00:00:11,007 --> 00:00:15,007
so you might need to install quite a few packages.

6
00:00:15,007 --> 00:00:18,004
If you look under the documentation directory,

7
00:00:18,004 --> 00:00:20,009
there's an admin guide

8
00:00:20,009 --> 00:00:25,006
and there's a quickly build trimmed Linux text file there.

9
00:00:25,006 --> 00:00:29,009
And if you look in there, you'll see this sudo apt thing

10
00:00:29,009 --> 00:00:33,002
that it recommends for Ubuntu, for example,

11
00:00:33,002 --> 00:00:35,004
and there's others for other distros and so forth.

12
00:00:35,004 --> 00:00:37,007
So you can look in there to get an idea

13
00:00:37,007 --> 00:00:40,002
of what you need to install.

14
00:00:40,002 --> 00:00:42,007
So typically when you build a kernel, you want

15
00:00:42,007 --> 00:00:46,000
to build a bootable image

16
00:00:46,000 --> 00:00:51,006
for X86, 64, your usual desktops and servers.

17
00:00:51,006 --> 00:00:55,007
Then you want a bzimage, that's a compressed,

18
00:00:55,007 --> 00:00:59,006
stripped kernel file in the appropriate format

19
00:00:59,006 --> 00:01:02,007
for grub to understand, for example.

20
00:01:02,007 --> 00:01:04,005
But there's other images

21
00:01:04,005 --> 00:01:07,006
for other targets like maybe uImage.

22
00:01:07,006 --> 00:01:14,000
There's also just kind of the raw kernel binary vmlinux.

23
00:01:14,000 --> 00:01:16,007
When you make bzimage, it has to make a vmlinux

24
00:01:16,007 --> 00:01:19,000
and then it strips it and compresses it

25
00:01:19,000 --> 00:01:22,002
and adds some header stuff and then you get a bzimage.

26
00:01:22,002 --> 00:01:27,006
So vmlinux will be a byproduct of making bzimage.

27
00:01:27,006 --> 00:01:31,005
The make command supports a minus J for jobs option

28
00:01:31,005 --> 00:01:32,009
where you can give it a number

29
00:01:32,009 --> 00:01:35,008
and that's how many compiles at a time it's going to try

30
00:01:35,008 --> 00:01:37,004
to do in parallel.

31
00:01:37,004 --> 00:01:40,008
So if you have a machine with eight cores,

32
00:01:40,008 --> 00:01:42,000
you can say J eight

33
00:01:42,000 --> 00:01:46,000
and they'll try to be doing eight at a time, For example.

34
00:01:46,000 --> 00:01:50,000
The other common thing you'd probably do is make modules.

35
00:01:50,000 --> 00:01:54,005
When you say make all, it'll typically make bzimage

36
00:01:54,005 --> 00:01:56,009
and make modules, both of them.

37
00:01:56,009 --> 00:02:00,001
So this builds all the .kos for all the things

38
00:02:00,001 --> 00:02:03,006
that you configured your kernel to have as modules.

39
00:02:03,006 --> 00:02:06,002
That might be more than a thousand.

40
00:02:06,002 --> 00:02:08,006
All kinds of modules you'll probably never, ever use.

41
00:02:08,006 --> 00:02:10,006
I mean, how many different ethernet devices

42
00:02:10,006 --> 00:02:12,003
do you have on your system?

43
00:02:12,003 --> 00:02:14,000
So you don't need all the ethernet drivers,

44
00:02:14,000 --> 00:02:16,004
but they're going to get built

45
00:02:16,004 --> 00:02:17,007
and they'll probably get installed

46
00:02:17,007 --> 00:02:22,001
and they'll just sit there, but that makes it flexible.

47
00:02:22,001 --> 00:02:24,005
So building all these modules, that's a lot of code.

48
00:02:24,005 --> 00:02:28,009
This step typically takes quite a while.

49
00:02:28,009 --> 00:02:29,009
Now if you want,

50
00:02:29,009 --> 00:02:31,005
after you've built your modules,

51
00:02:31,005 --> 00:02:35,001
you can install them into your system

52
00:02:35,001 --> 00:02:39,006
or copy this stuff over and install into another system.

53
00:02:39,006 --> 00:02:43,006
So the make modules install copies all the .kos

54
00:02:43,006 --> 00:02:48,004
and populates the lib module's kernel version directory,

55
00:02:48,004 --> 00:02:50,007
and it calls depmod

56
00:02:50,007 --> 00:02:54,006
to create the modules .dep file and so forth.

57
00:02:54,006 --> 00:02:56,009
Now, lib modules is typically not writeable

58
00:02:56,009 --> 00:02:58,008
by an ordinary user.

59
00:02:58,008 --> 00:03:01,007
So when you do a make modules install,

60
00:03:01,007 --> 00:03:05,001
you probably have to do a sudo, right?

61
00:03:05,001 --> 00:03:08,002
So targets with the word install in them

62
00:03:08,002 --> 00:03:09,009
like modules install,

63
00:03:09,009 --> 00:03:11,001
are installing in your system.

64
00:03:11,001 --> 00:03:14,000
And typically you need to run those with sudo.

65
00:03:14,000 --> 00:03:15,008
You need to be root.

66
00:03:15,008 --> 00:03:18,000
Similarly, there's a make install,

67
00:03:18,000 --> 00:03:22,006
which is for installing your kernel into /boot,

68
00:03:22,006 --> 00:03:27,008
and that should rename it vmlinuz,

69
00:03:27,008 --> 00:03:32,004
not be the image, vmlinuz-kernel version.

70
00:03:32,004 --> 00:03:35,004
And hopefully we will update your grub config

71
00:03:35,004 --> 00:03:37,005
and create an initramfs

72
00:03:37,005 --> 00:03:41,005
or initrdimage if you need that.

73
00:03:41,005 --> 00:03:44,000
Maybe not, it depends on the distro,

74
00:03:44,000 --> 00:03:46,009
but make install is at least an important

75
00:03:46,009 --> 00:03:49,009
step in getting that done.

76
00:03:49,009 --> 00:03:52,002
There's also clean targets.

77
00:03:52,002 --> 00:03:56,000
Make clean removes the stuff you built,

78
00:03:56,000 --> 00:03:58,004
the kernel file, the object files.

79
00:03:58,004 --> 00:04:00,003
So that's a pretty big deal.

80
00:04:00,003 --> 00:04:04,000
If you want to just clean part of the tree,

81
00:04:04,000 --> 00:04:07,008
you can use M=$PWD

82
00:04:07,008 --> 00:04:12,004
and minus C options to make to say where you want to clean

83
00:04:12,004 --> 00:04:16,001
or M equals a directory where you want to clean.

84
00:04:16,001 --> 00:04:18,002
Make clean does not remove your .config.

85
00:04:18,002 --> 00:04:22,003
So you don't lose all that work of configuring your kernel,

86
00:04:22,003 --> 00:04:24,003
but make mrproper does.

87
00:04:24,003 --> 00:04:28,001
Mrproper is a more thorough cleaning.

88
00:04:28,001 --> 00:04:32,001
Also because the lens kernel has been ported to a bunch

89
00:04:32,001 --> 00:04:35,001
of architectures, you can clearly cross compile it

90
00:04:35,001 --> 00:04:37,002
for other architectures.

91
00:04:37,002 --> 00:04:42,008
So typically that would involve installing a cross compiler,

92
00:04:42,008 --> 00:04:45,003
setting, an environment variable, cross compile

93
00:04:45,003 --> 00:04:48,002
to be the prefix for that cross compiler,

94
00:04:48,002 --> 00:04:49,008
make file will use that.

95
00:04:49,008 --> 00:04:51,007
And then you do a make,

96
00:04:51,007 --> 00:04:55,003
and there's that capital ARCH equals architecture space

97
00:04:55,003 --> 00:04:57,005
and the name of the image to make.

98
00:04:57,005 --> 00:05:02,000
For arm, it's often uImage, not bzimage, for example.

