1
00:00:00,005 --> 00:00:02,007
- [Instructor] We're going to talk about the Linux kernel,

2
00:00:02,007 --> 00:00:04,009
a lot about the Linux kernel,

3
00:00:04,009 --> 00:00:08,006
and one of the important roles of the kernel is dealing

4
00:00:08,006 --> 00:00:12,004
with hardware, providing utilities, interfaces,

5
00:00:12,004 --> 00:00:14,009
protection for hardware.

6
00:00:14,009 --> 00:00:16,005
So let's just take a couple minutes

7
00:00:16,005 --> 00:00:20,004
and talk about some commands related to hardware,

8
00:00:20,004 --> 00:00:24,000
and these commands will often get information

9
00:00:24,000 --> 00:00:26,003
via the kernel.

10
00:00:26,003 --> 00:00:31,002
An application can call into the Linux kernel

11
00:00:31,002 --> 00:00:34,007
to give data or get data

12
00:00:34,007 --> 00:00:36,007
through functions like read and write,

13
00:00:36,007 --> 00:00:41,000
but those functions are implemented in a library

14
00:00:41,000 --> 00:00:43,001
for many binaries.

15
00:00:43,001 --> 00:00:46,000
They use the standard C library.

16
00:00:46,000 --> 00:00:51,002
And it's the library that knows how to invoke the kernel,

17
00:00:51,002 --> 00:00:56,003
and that involves typically architecture-dependent,

18
00:00:56,003 --> 00:00:58,002
similar language instruction approaches,

19
00:00:58,002 --> 00:01:01,002
doing a system call, a similar language instruction say

20
00:01:01,002 --> 00:01:04,003
to trap into the kernel.

21
00:01:04,003 --> 00:01:09,009
And the kernel is what controls devices typically.

22
00:01:09,009 --> 00:01:15,009
So the device drivers and Linux usually are in the kernel.

23
00:01:15,009 --> 00:01:18,006
So here's a few commands that might be handy

24
00:01:18,006 --> 00:01:20,009
to get information about hardware.

25
00:01:20,009 --> 00:01:24,003
So the commands would get information

26
00:01:24,003 --> 00:01:26,001
from the kernel somehow.

27
00:01:26,001 --> 00:01:31,000
List hardware, list PCI devices, list USB devices,

28
00:01:31,000 --> 00:01:34,007
list block devices, list CPU information,

29
00:01:34,007 --> 00:01:40,003
list other device informations like interrupt handler stuff.

30
00:01:40,003 --> 00:01:43,000
Now not all distros might have all these commands,

31
00:01:43,000 --> 00:01:46,004
but maybe yours does.

32
00:01:46,004 --> 00:01:50,003
You can also control hardware from the command line,

33
00:01:50,003 --> 00:01:52,009
asking the colonel to do things.

34
00:01:52,009 --> 00:01:58,005
The hdparm command is for getting information

35
00:01:58,005 --> 00:02:05,000
and setting tunables, controlling, discs.

36
00:02:05,000 --> 00:02:10,002
There's also lots of files underneath proc, dev,

37
00:02:10,002 --> 00:02:15,003
and the assist file system that the kernel provides.

38
00:02:15,003 --> 00:02:18,004
These are all pseudo file systems.

39
00:02:18,004 --> 00:02:23,004
The kernel provides information there about devices

40
00:02:23,004 --> 00:02:25,009
and many files there are writeable

41
00:02:25,009 --> 00:02:30,000
so that you can change configurations

42
00:02:30,000 --> 00:02:33,003
or tuneable values in the kernel.

43
00:02:33,003 --> 00:02:35,001
And there's also kind

44
00:02:35,001 --> 00:02:38,000
of classic lower level functionality like inb

45
00:02:38,000 --> 00:02:40,006
and outb for talking to special kind

46
00:02:40,006 --> 00:02:43,008
of input devices like keyboards.

47
00:02:43,008 --> 00:02:46,009
And there's even utilities to deal more directly

48
00:02:46,009 --> 00:02:50,002
with PCI devices, set PCI for example.

49
00:02:50,002 --> 00:02:54,007
So you can do much of what a PCI device driver would do,

50
00:02:54,007 --> 00:02:58,000
you know, from the command line in a shell script.

51
00:02:58,000 --> 00:03:00,006
Let's look at the commands little bit.

52
00:03:00,006 --> 00:03:04,001
All right, so some of these you want to do as root.

53
00:03:04,001 --> 00:03:08,000
So we'll do a sudo, list hardware.

54
00:03:08,000 --> 00:03:12,000
This got an idea of how many lines will come out.

55
00:03:12,000 --> 00:03:14,006
282 lines. So there's quite a bit of stuff there.

56
00:03:14,006 --> 00:03:19,009
We'll just look at this a bit.

57
00:03:19,009 --> 00:03:24,002
All right, so at the top there's the name of this VM.

58
00:03:24,002 --> 00:03:26,005
Thinks it's a desktop computer.

59
00:03:26,005 --> 00:03:29,002
We're looking at motherboard and firmware

60
00:03:29,002 --> 00:03:33,004
and CPU information and lots more.

61
00:03:33,004 --> 00:03:37,006
For PCI devices, I often do the minus V

62
00:03:37,006 --> 00:03:40,004
for verbose, get a little more information.

63
00:03:40,004 --> 00:03:43,009
And on this VM, it thinks there's only one PCI device,

64
00:03:43,009 --> 00:03:50,007
ethernet device and block devices.

65
00:03:50,007 --> 00:03:53,007
We got the loop devices, which are not really devices,

66
00:03:53,007 --> 00:04:00,009
and then we got discs, SDA, SDB, SDC, SDD.

67
00:04:00,009 --> 00:04:07,008
So this VM has a bunch of discs.

68
00:04:07,008 --> 00:04:12,004
Let's do LSCPU, find out about our CPUs.

69
00:04:12,004 --> 00:04:14,006
And you know, lots of information there.

70
00:04:14,006 --> 00:04:15,009
There's even some information

71
00:04:15,009 --> 00:04:22,008
about CPU vulnerabilities reported, LS dev.

72
00:04:22,008 --> 00:04:24,004
So this is device information.

73
00:04:24,004 --> 00:04:28,009
You can see 'em listed and IO ports.

74
00:04:28,009 --> 00:04:33,004
Let's see the difference when we use sudo.

75
00:04:33,004 --> 00:04:37,005
Then we get real addresses, IO ports, so forth.

76
00:04:37,005 --> 00:04:41,000
IO ports is what you could manipulate with the NB

77
00:04:41,000 --> 00:04:43,008
and LB stuff, but that's pretty ancient sort

78
00:04:43,008 --> 00:04:44,009
of things to do.

79
00:04:44,009 --> 00:04:50,004
But we got timers, we've got a real time clock and so forth.

80
00:04:50,004 --> 00:04:54,008
Let's find out information about a disc with hdparm,

81
00:04:54,008 --> 00:05:00,001
so the capital I option.

82
00:05:00,001 --> 00:05:02,006
And we see some information about there.

83
00:05:02,006 --> 00:05:04,004
Not a whole lot.

84
00:05:04,004 --> 00:05:09,003
This is a VM, but hdparm has lots of options,

85
00:05:09,003 --> 00:05:12,000
so you could do quite a lot there.

86
00:05:12,000 --> 00:05:17,000
And then as an example of a tuneable down

87
00:05:17,000 --> 00:05:23,002
in the sys file system, we can try one.

88
00:05:23,002 --> 00:05:27,005
So way underneath, sys devices, yada, yada, yada,

89
00:05:27,005 --> 00:05:32,004
there is a file called max retries

90
00:05:32,004 --> 00:05:36,000
that has to do with how many times a file system

91
00:05:36,000 --> 00:05:38,009
or a driver will retry an operation

92
00:05:38,009 --> 00:05:40,007
on that disc if it fails.

93
00:05:40,007 --> 00:05:45,000
And we can see here it's currently set to try five times.

94
00:05:45,000 --> 00:05:45,008
There you go.

95
00:05:45,008 --> 00:05:47,000
That was a quick look

96
00:05:47,000 --> 00:05:51,009
at a few hardware related utilities, sort of things

97
00:05:51,009 --> 00:05:55,000
that ask the colonel for help.

