1
00:00:00,660 --> 00:00:01,680
In this lesson,

2
00:00:01,680 --> 00:00:03,690
you're going to explore some key concepts

3
00:00:03,690 --> 00:00:06,180
and components that make up the Linux kernel

4
00:00:06,180 --> 00:00:07,470
that you need to be able to troubleshoot

5
00:00:07,470 --> 00:00:10,530
and provide solution to, as you work through the system.

6
00:00:10,530 --> 00:00:13,170
Now there's some aspects of Linux that are consistent

7
00:00:13,170 --> 00:00:15,840
but those are typically handled by the kernel.

8
00:00:15,840 --> 00:00:18,990
Now, the kernel is the core of the Linux operating system

9
00:00:18,990 --> 00:00:21,090
and it handles various crucial functions,

10
00:00:21,090 --> 00:00:24,300
such as, the system initialization, process scheduling

11
00:00:24,300 --> 00:00:26,610
and memory and hardware management.

12
00:00:26,610 --> 00:00:28,860
The core of the operating system is called the kernel,

13
00:00:28,860 --> 00:00:29,940
like I just said,

14
00:00:29,940 --> 00:00:33,090
and all the other components are going to rely upon it.

15
00:00:33,090 --> 00:00:36,510
The kernel manages, file system access, it's memory,

16
00:00:36,510 --> 00:00:38,670
its processes, its devices

17
00:00:38,670 --> 00:00:41,670
and the other resource allocation on the system.

18
00:00:41,670 --> 00:00:44,220
The kernel also controls all the hardware devices

19
00:00:44,220 --> 00:00:46,530
that are plugged into a given system.

20
00:00:46,530 --> 00:00:49,470
It is one of the first elements to be loaded up on startup

21
00:00:49,470 --> 00:00:51,510
and it remains the main thing in memory

22
00:00:51,510 --> 00:00:53,580
during your computer's operation.

23
00:00:53,580 --> 00:00:56,430
The kernel also contains system level commands

24
00:00:56,430 --> 00:00:59,790
and other functions that are normally hidden from users.

25
00:00:59,790 --> 00:01:01,800
Now kernel's tend to divide software,

26
00:01:01,800 --> 00:01:04,170
that's running in memory into two spaces.

27
00:01:04,170 --> 00:01:07,590
Namely, the kernel space and the user space.

28
00:01:07,590 --> 00:01:09,750
The kernel space is simply where the kernel

29
00:01:09,750 --> 00:01:12,390
executes the services that it provides.

30
00:01:12,390 --> 00:01:15,240
The user space, on the other hand, is the area of memory

31
00:01:15,240 --> 00:01:18,390
that includes everything outside of the kernel space.

32
00:01:18,390 --> 00:01:21,090
This can include everything from high level applications

33
00:01:21,090 --> 00:01:23,970
that the users interacting with directly, to processes

34
00:01:23,970 --> 00:01:25,410
that are running in the background,

35
00:01:25,410 --> 00:01:27,960
to various low level system libraries.

36
00:01:27,960 --> 00:01:30,960
The split between these two memory regions is useful

37
00:01:30,960 --> 00:01:32,550
because it provides greater stability

38
00:01:32,550 --> 00:01:34,440
and security for our system.

39
00:01:34,440 --> 00:01:37,560
Software in one space cannot necessarily interfere

40
00:01:37,560 --> 00:01:39,990
with software in the other space.

41
00:01:39,990 --> 00:01:42,630
Now kernels can be classified as monolithic

42
00:01:42,630 --> 00:01:44,160
or microkernels.

43
00:01:44,160 --> 00:01:46,950
In a monolithic kernel all system modules,

44
00:01:46,950 --> 00:01:50,040
such as device drivers or file systems run inside

45
00:01:50,040 --> 00:01:51,450
the kernel space.

46
00:01:51,450 --> 00:01:54,600
As a result, a monolithic kernel can interact quickly

47
00:01:54,600 --> 00:01:56,400
with all the different devices.

48
00:01:56,400 --> 00:01:59,610
However, its main disadvantage is its size,

49
00:01:59,610 --> 00:02:02,340
which tends to lead to higher consumption of Ram.

50
00:02:02,340 --> 00:02:05,490
In addition, a failure and a device driver can actually

51
00:02:05,490 --> 00:02:07,800
lead to system instability if you're using

52
00:02:07,800 --> 00:02:09,509
a monolithic kernel.

53
00:02:09,509 --> 00:02:12,240
So, instead a lot of people like to use

54
00:02:12,240 --> 00:02:14,370
a microkernel architecture.

55
00:02:14,370 --> 00:02:16,830
Now when you're using a microkernel architecture,

56
00:02:16,830 --> 00:02:19,830
the kernel itself runs the minimum amount of resources

57
00:02:19,830 --> 00:02:21,810
that are necessary to actually implement

58
00:02:21,810 --> 00:02:24,150
a fully functional operating system.

59
00:02:24,150 --> 00:02:26,040
Compared to a monolithic kernel,

60
00:02:26,040 --> 00:02:28,560
microkernels have smaller kernel spaces

61
00:02:28,560 --> 00:02:31,290
and instead have much larger user spaces.

62
00:02:31,290 --> 00:02:34,980
This means that microkernels are smaller and overised size

63
00:02:34,980 --> 00:02:37,650
and they actually consume much less memory.

64
00:02:37,650 --> 00:02:40,200
In addition, they're actually considered much more stable

65
00:02:40,200 --> 00:02:41,310
and secure.

66
00:02:41,310 --> 00:02:44,940
However, microkernels also tend to offer worse performance

67
00:02:44,940 --> 00:02:47,130
than a monolithic kernel because there's a lot more

68
00:02:47,130 --> 00:02:50,460
switching of things into or out of memory.

69
00:02:50,460 --> 00:02:53,400
The next thing we need to talk about is device drivers.

70
00:02:53,400 --> 00:02:54,810
Essentially, when we talk about

71
00:02:54,810 --> 00:02:58,110
a Linux Kernel device driver, this is a software program

72
00:02:58,110 --> 00:03:00,840
that enables a computer's operating system to identify

73
00:03:00,840 --> 00:03:04,170
the characteristics and functions of a given hardware device

74
00:03:04,170 --> 00:03:05,610
to be able to communicate with it

75
00:03:05,610 --> 00:03:07,500
and control its operations.

76
00:03:07,500 --> 00:03:09,570
The device driver acts as an interface

77
00:03:09,570 --> 00:03:12,540
between the operating system and the hardware devices.

78
00:03:12,540 --> 00:03:14,760
This can include things like, your storage drives,

79
00:03:14,760 --> 00:03:18,570
your printers, your scanners, your monitors, your keyboards

80
00:03:18,570 --> 00:03:20,220
and your network devices.

81
00:03:20,220 --> 00:03:22,890
Device drivers can be included in the operating system

82
00:03:22,890 --> 00:03:26,130
or you can install them on demand afterwards.

83
00:03:26,130 --> 00:03:28,590
Now, when we talk about the Linux kernel, it's important

84
00:03:28,590 --> 00:03:32,280
to remember it's a free and open source monolithic kernel

85
00:03:32,280 --> 00:03:34,950
in general and it manages all the resources

86
00:03:34,950 --> 00:03:36,780
on the operating system.

87
00:03:36,780 --> 00:03:39,720
As a monolithic kernel, device drivers run within

88
00:03:39,720 --> 00:03:43,380
the kernel space and they have full access to the hardware.

89
00:03:43,380 --> 00:03:45,780
The architecture of the Linux Kernel, does provide

90
00:03:45,780 --> 00:03:47,880
for many useful features, including,

91
00:03:47,880 --> 00:03:49,350
virtual memory management,

92
00:03:49,350 --> 00:03:52,710
support for TCP/IP networking, shared libraries

93
00:03:52,710 --> 00:03:54,210
and much more.

94
00:03:54,210 --> 00:03:56,430
Another important quality of the Linux Kernel

95
00:03:56,430 --> 00:03:58,050
is its modularity.

96
00:03:58,050 --> 00:04:00,540
This enables users to configure and extend kernel

97
00:04:00,540 --> 00:04:03,690
functionality to meet their specific needs.

98
00:04:03,690 --> 00:04:05,880
Now there are a lot of changes and new features

99
00:04:05,880 --> 00:04:08,280
merged into the Linux Kernel.

100
00:04:08,280 --> 00:04:11,370
For versions 2.6.39 and prior,

101
00:04:11,370 --> 00:04:15,450
the kernel number format was w.x.y.z.

102
00:04:15,450 --> 00:04:18,877
Where "W" is the major version, such as, version 2.

103
00:04:18,877 --> 00:04:22,837
"X" was the major revision version, such as, 2.6.

104
00:04:22,837 --> 00:04:27,300
"Y' is the minor revision number, 2.6.39

105
00:04:27,300 --> 00:04:29,550
and "Z" is the patch number.

106
00:04:29,550 --> 00:04:33,420
But after version 2.6.39 they actually decided

107
00:04:33,420 --> 00:04:35,400
to shorten the version number format.

108
00:04:35,400 --> 00:04:40,170
And so the next version was version 3.0 after 3.19

109
00:04:40,170 --> 00:04:44,400
rather than going to 3.20, they jumped up to 4.0

110
00:04:44,400 --> 00:04:46,440
and this was for readability purposes,

111
00:04:46,440 --> 00:04:48,990
not due to any real major technical advances

112
00:04:48,990 --> 00:04:51,390
like we used to have with major versions.

113
00:04:51,390 --> 00:04:53,730
Newer versions of the kernel will continue this trend

114
00:04:53,730 --> 00:04:56,910
of avoiding large minor numbers with multiple decimals

115
00:04:56,910 --> 00:05:01,910
like 2.6.39.2 and instead using something like 3.20 or 4.0.

116
00:05:03,750 --> 00:05:06,540
So, how can you figure out what kernel you're running?

117
00:05:06,540 --> 00:05:09,930
Well to do that you use a command known as, uname.

118
00:05:09,930 --> 00:05:13,470
By default, uname will print the name of the kernel Linux

119
00:05:13,470 --> 00:05:15,840
but you can also view the kernel version of the number

120
00:05:15,840 --> 00:05:20,040
to the system you're using by typing in uname-r.

121
00:05:20,040 --> 00:05:24,150
If you enter uname-i, you can view the hardware platform

122
00:05:24,150 --> 00:05:26,340
and to print all the information on the system.

123
00:05:26,340 --> 00:05:29,463
Type in uname-a at the command prompt.

124
00:05:30,330 --> 00:05:33,120
Now going back to our kernel, remember that our kernel

125
00:05:33,120 --> 00:05:35,850
performs various functions to control and manage

126
00:05:35,850 --> 00:05:37,860
the operations of a system.

127
00:05:37,860 --> 00:05:40,380
It's going to be composed of several layers that operate

128
00:05:40,380 --> 00:05:42,090
in the kernel space.

129
00:05:42,090 --> 00:05:45,180
We call this the SCI kernel layer, and this is,

130
00:05:45,180 --> 00:05:47,760
the System Call Interface kernel layer.

131
00:05:47,760 --> 00:05:50,190
It's going to handle the system calls, sent from user

132
00:05:50,190 --> 00:05:52,980
applications that need to go to the kernel.

133
00:05:52,980 --> 00:05:56,340
This enables the user space applications to request services

134
00:05:56,340 --> 00:05:59,280
from the kernel space, things like processing time

135
00:05:59,280 --> 00:06:02,520
and memory allocation and enables the kernel to schedule

136
00:06:02,520 --> 00:06:03,960
and process system calls

137
00:06:03,960 --> 00:06:07,440
and manage multiple system calls simultaneously.

138
00:06:07,440 --> 00:06:09,210
The process management kernel layer,

139
00:06:09,210 --> 00:06:11,340
handles different processes by allocating

140
00:06:11,340 --> 00:06:14,160
separate execution space on the processor

141
00:06:14,160 --> 00:06:16,560
and ensuring that the running of one process

142
00:06:16,560 --> 00:06:19,440
does not interfere with the other processes.

143
00:06:19,440 --> 00:06:22,020
Our memory management kernel layer is going to manage

144
00:06:22,020 --> 00:06:24,030
the computer's memory, which is one of the most

145
00:06:24,030 --> 00:06:27,150
complex tasks that's performed by the kernel.

146
00:06:27,150 --> 00:06:28,800
Just like processor sharing,

147
00:06:28,800 --> 00:06:30,930
the system's memory also needs to be shared

148
00:06:30,930 --> 00:06:33,630
among different user space resources.

149
00:06:33,630 --> 00:06:35,610
The file system management kernel layer,

150
00:06:35,610 --> 00:06:37,470
is going to manage the file system.

151
00:06:37,470 --> 00:06:40,620
This involves storing, organizing and tracking files

152
00:06:40,620 --> 00:06:42,810
and data on a given computer.

153
00:06:42,810 --> 00:06:45,600
The kernel also supports a virtual file system

154
00:06:45,600 --> 00:06:48,750
or VFS that provides this abstraction layer

155
00:06:48,750 --> 00:06:51,120
of the underlying data that's being organized

156
00:06:51,120 --> 00:06:52,620
under complex structures.

157
00:06:52,620 --> 00:06:55,200
So it appears to be a single structure.

158
00:06:55,200 --> 00:06:58,170
The device management kernel layer is going to manage devices

159
00:06:58,170 --> 00:06:59,790
by controlling device access

160
00:06:59,790 --> 00:07:02,100
and interfacing between user applications

161
00:07:02,100 --> 00:07:04,470
and hardware devices on the computer.

162
00:07:04,470 --> 00:07:07,290
When a user space application sends a system call

163
00:07:07,290 --> 00:07:09,900
the kernel is going to read the request and then pass it on

164
00:07:09,900 --> 00:07:11,790
to the drivers that manage the activities

165
00:07:11,790 --> 00:07:13,770
of that particular device.

166
00:07:13,770 --> 00:07:14,700
As you can see,

167
00:07:14,700 --> 00:07:17,520
the kernel really is at the center of everything

168
00:07:17,520 --> 00:07:18,780
and it's where we're going to do all of

169
00:07:18,780 --> 00:07:22,413
the major device handling and processing for our systems.

