1
00:00:00,480 --> 00:00:01,530
In this lesson,

2
00:00:01,530 --> 00:00:03,540
you're going to learn about GRUB 2,

3
00:00:03,540 --> 00:00:06,210
which is a popular boot loader in Linux.

4
00:00:06,210 --> 00:00:07,470
We've previously discussed

5
00:00:07,470 --> 00:00:09,120
the various essential components

6
00:00:09,120 --> 00:00:11,640
that make up the Linux boot process.

7
00:00:11,640 --> 00:00:13,740
Your existing knowledge of those concepts

8
00:00:13,740 --> 00:00:15,600
are going to help you leverage boot options

9
00:00:15,600 --> 00:00:18,690
as well as gain control over a how Linux boots.

10
00:00:18,690 --> 00:00:20,880
So now that you're familiar with the role of a boot loader

11
00:00:20,880 --> 00:00:22,680
inside the boot process,

12
00:00:22,680 --> 00:00:24,150
you can now be able to learn

13
00:00:24,150 --> 00:00:26,850
how to configure the primary Linux boot loader,

14
00:00:26,850 --> 00:00:30,300
which at the time of this recording is known as GRUB 2.

15
00:00:30,300 --> 00:00:33,030
Understanding how to configure GRUB and GRUB 2

16
00:00:33,030 --> 00:00:35,490
is really important for you to be able to recover from

17
00:00:35,490 --> 00:00:38,370
or to circumvent various types of problems and issues

18
00:00:38,370 --> 00:00:41,010
you may encounter as a system administrator.

19
00:00:41,010 --> 00:00:42,960
There are several boot loaders out there,

20
00:00:42,960 --> 00:00:45,210
but Linux usually uses GRUB,

21
00:00:45,210 --> 00:00:48,870
which is the GNU GRand Unified Bootloader.

22
00:00:48,870 --> 00:00:52,290
This is by far the most popular boot loader out there.

23
00:00:52,290 --> 00:00:53,640
And there's various versions of it,

24
00:00:53,640 --> 00:00:55,950
known as GRUB and GRUB 2.

25
00:00:55,950 --> 00:00:58,740
GRUB enables users to choose which operating system

26
00:00:58,740 --> 00:01:00,690
or kernel version they want to boot

27
00:01:00,690 --> 00:01:03,300
inside this multi-platform environment.

28
00:01:03,300 --> 00:01:04,890
Although the original version of GRUB

29
00:01:04,890 --> 00:01:07,590
was the primary boot loader for Linux distributions,

30
00:01:07,590 --> 00:01:09,300
it had several limitations,

31
00:01:09,300 --> 00:01:11,250
and eventually, it was phased out

32
00:01:11,250 --> 00:01:14,970
in favor of the new version of GRUB known as GRUB 2.

33
00:01:14,970 --> 00:01:17,730
Now, GRUB 2 is usually just called GRUB

34
00:01:17,730 --> 00:01:19,860
and it's more than just a simple newer version

35
00:01:19,860 --> 00:01:21,090
of GRUB, though.

36
00:01:21,090 --> 00:01:24,330
It's also a completely redesigned and rewritten version

37
00:01:24,330 --> 00:01:26,040
of the GRUB system.

38
00:01:26,040 --> 00:01:28,110
GRUB 2 offers administrators

39
00:01:28,110 --> 00:01:30,480
with more control over the boot process,

40
00:01:30,480 --> 00:01:33,000
the boot devices, and the boot behavior.

41
00:01:33,000 --> 00:01:36,630
GRUB 2 supports non-86 architecture platforms,

42
00:01:36,630 --> 00:01:39,540
things like RISC processors and ARM processors,

43
00:01:39,540 --> 00:01:42,240
as well as supports booting an OS from storage media

44
00:01:42,240 --> 00:01:44,880
and running the OS entirely in memory.

45
00:01:44,880 --> 00:01:45,713
You can do this

46
00:01:45,713 --> 00:01:47,730
without even installing the Linux operating system

47
00:01:47,730 --> 00:01:49,710
and run the entire thing from RAM.

48
00:01:49,710 --> 00:01:52,260
That's one of the things that GRUB 2 offers.

49
00:01:52,260 --> 00:01:54,960
It also supports partition UUIDs

50
00:01:54,960 --> 00:01:56,340
and supports loading modules

51
00:01:56,340 --> 00:01:58,350
to extend GRUB's functionality.

52
00:01:58,350 --> 00:02:01,170
In addition to all that, GRUB 2 also has the ability

53
00:02:01,170 --> 00:02:02,610
to configure the boot loader

54
00:02:02,610 --> 00:02:04,020
through the use of scripts.

55
00:02:04,020 --> 00:02:05,850
And it will attempt to fix boot issues

56
00:02:05,850 --> 00:02:08,100
like corrupted and missing configurations,

57
00:02:08,100 --> 00:02:09,539
as well as having other features

58
00:02:09,539 --> 00:02:11,790
to customize your user experience.

59
00:02:11,790 --> 00:02:14,250
This includes things like background wallpapers,

60
00:02:14,250 --> 00:02:16,470
different font, and more things like that

61
00:02:16,470 --> 00:02:18,330
to personalize your system.

62
00:02:18,330 --> 00:02:19,800
Because of these improvements,

63
00:02:19,800 --> 00:02:22,080
GRUB 2 has become the default boot loader

64
00:02:22,080 --> 00:02:24,990
on almost all modern Linux distributions.

65
00:02:24,990 --> 00:02:26,610
GRUB 2 can also be installed

66
00:02:26,610 --> 00:02:29,130
even if you're currently booting into the OS.

67
00:02:29,130 --> 00:02:31,980
Just execute the grub2-install command

68
00:02:31,980 --> 00:02:34,710
against the device or the partition you desire.

69
00:02:34,710 --> 00:02:36,570
It'll copy over the GRUB 2 files

70
00:02:36,570 --> 00:02:39,510
into the /boot/GRUB2 directory,

71
00:02:39,510 --> 00:02:41,340
and on some platforms,

72
00:02:41,340 --> 00:02:44,070
it'll install GRUB 2 into the boot sector.

73
00:02:44,070 --> 00:02:48,420
However, grub2-install applies to BIOS-based systems,

74
00:02:48,420 --> 00:02:50,250
not UEFI systems.

75
00:02:50,250 --> 00:02:52,980
If you want to install GRUB 2 on a UEFI system,

76
00:02:52,980 --> 00:02:54,810
you're going to have to use a package manager

77
00:02:54,810 --> 00:02:58,050
to install the grub2-efi package.

78
00:02:58,050 --> 00:03:00,750
Installing this package will copy GRUB 2 files

79
00:03:00,750 --> 00:03:04,320
onto the EFI system partition or the ESP

80
00:03:04,320 --> 00:03:08,190
inside of the /boot/efi directory.

81
00:03:08,190 --> 00:03:10,320
Now, to use grub2-install,

82
00:03:10,320 --> 00:03:12,180
you have to use the right syntax,

83
00:03:12,180 --> 00:03:16,140
and the syntax for this is grub2-install, the options,

84
00:03:16,140 --> 00:03:17,610
and the device name.

85
00:03:17,610 --> 00:03:19,530
Now, there's several different options you can use

86
00:03:19,530 --> 00:03:21,870
with the grub2-install command.

87
00:03:21,870 --> 00:03:26,280
For example, you can use --modules in the module names.

88
00:03:26,280 --> 00:03:27,480
This option will allow you

89
00:03:27,480 --> 00:03:29,700
to reload the specified kernel modules

90
00:03:29,700 --> 00:03:31,620
with the GRUB 2 boot loader.

91
00:03:31,620 --> 00:03:36,030
If you use the --install-modules and module names option,

92
00:03:36,030 --> 00:03:39,000
this is going to be used to install only the specified modules

93
00:03:39,000 --> 00:03:40,290
and their dependencies

94
00:03:40,290 --> 00:03:44,160
rather than the default of installing all available modules.

95
00:03:44,160 --> 00:03:47,760
If you use --directory and the directory name option,

96
00:03:47,760 --> 00:03:49,590
this is going to be used to install files

97
00:03:49,590 --> 00:03:51,180
from the specified directory

98
00:03:51,180 --> 00:03:53,550
rather than from the default directory.

99
00:03:53,550 --> 00:03:57,180
If you use --target and the target platform option,

100
00:03:57,180 --> 00:03:59,880
this is going to be used to specify the target platform

101
00:03:59,880 --> 00:04:01,650
that you want to install GRUB 2 for

102
00:04:01,650 --> 00:04:03,030
instead of using the platform

103
00:04:03,030 --> 00:04:04,920
that you're currently running on.

104
00:04:04,920 --> 00:04:08,340
The --boot-directory, directory name option

105
00:04:08,340 --> 00:04:10,680
is going to be used to specify the boot directory

106
00:04:10,680 --> 00:04:13,050
that you want to install GRUB 2 files to

107
00:04:13,050 --> 00:04:17,140
rather than using the default /bootdirectory or /boot/GRUB2.

108
00:04:18,810 --> 00:04:22,320
The -force option is going to be used to install GRUB 2

109
00:04:22,320 --> 00:04:24,840
regardless of any detected issues.

110
00:04:24,840 --> 00:04:26,700
Now, the main configuration file

111
00:04:26,700 --> 00:04:31,290
for your GRUB 2 boot loader is known as grub.cfg.

112
00:04:31,290 --> 00:04:34,200
This is a file that you're going to use on BIOS systems,

113
00:04:34,200 --> 00:04:38,220
and it's going to be located in /boot/grub2.

114
00:04:38,220 --> 00:04:39,840
If you're on a UEFI system,

115
00:04:39,840 --> 00:04:44,760
it's going to be located in /boot/efi/EFI

116
00:04:44,760 --> 00:04:46,680
and then you're going to have your file there.

117
00:04:46,680 --> 00:04:49,440
Now, this file is an executable shell script

118
00:04:49,440 --> 00:04:52,050
that is not recommended to be edited directly,

119
00:04:52,050 --> 00:04:54,360
because it's generated using specific commands

120
00:04:54,360 --> 00:04:56,910
that leverage configuration scripts stored elsewhere

121
00:04:56,910 --> 00:04:58,770
on the file system.

122
00:04:58,770 --> 00:05:03,770
Another important directory is the /etc/grub.d directory.

123
00:05:04,410 --> 00:05:05,520
This contains scripts

124
00:05:05,520 --> 00:05:09,030
that are used to build the main grub.config file.

125
00:05:09,030 --> 00:05:11,850
Each script provides various functions to GRUB 2,

126
00:05:11,850 --> 00:05:13,920
and it's numbered so that the scripts can execute

127
00:05:13,920 --> 00:05:15,120
in a sequence.

128
00:05:15,120 --> 00:05:18,090
It's usually not a good idea to edit the existing scripts

129
00:05:18,090 --> 00:05:19,470
in this directory.

130
00:05:19,470 --> 00:05:21,240
If you want to add a custom script,

131
00:05:21,240 --> 00:05:23,040
you should place this in the directory

132
00:05:23,040 --> 00:05:26,730
with a number number underscore as a file name prefixed,

133
00:05:26,730 --> 00:05:29,310
depending on the order you want the script to be executed in

134
00:05:29,310 --> 00:05:31,260
within your current directory.

135
00:05:31,260 --> 00:05:32,430
You could also add your script

136
00:05:32,430 --> 00:05:35,310
to the existing 40_custom file,

137
00:05:35,310 --> 00:05:38,790
because that way, it will execute last by default.

138
00:05:38,790 --> 00:05:41,820
Now, speaking of this 40_custom file,

139
00:05:41,820 --> 00:05:42,930
this is going to be located

140
00:05:42,930 --> 00:05:47,930
at /etc/grub.d/40_custom.

141
00:05:48,480 --> 00:05:51,540
And this file enables the customization of the menu

142
00:05:51,540 --> 00:05:52,950
that's presented to the user

143
00:05:52,950 --> 00:05:54,660
during the boot process.

144
00:05:54,660 --> 00:05:57,570
The GRUB 2 system is going to offer the user a menu

145
00:05:57,570 --> 00:06:00,180
of installed operating systems to choose from.

146
00:06:00,180 --> 00:06:01,560
This choice is really useful

147
00:06:01,560 --> 00:06:03,330
if you're multi booting your system

148
00:06:03,330 --> 00:06:04,950
and you have more than one operating system

149
00:06:04,950 --> 00:06:06,120
on the computer.

150
00:06:06,120 --> 00:06:07,080
For example,

151
00:06:07,080 --> 00:06:08,940
you might have different Linux kernels there,

152
00:06:08,940 --> 00:06:12,180
or you have Linux and Windows on the same system,

153
00:06:12,180 --> 00:06:14,940
or you might want to boot into rescue mode.

154
00:06:14,940 --> 00:06:17,340
The menu contents here can be customized

155
00:06:17,340 --> 00:06:22,203
by editing the /etc/grub.d/40_custom file

156
00:06:23,250 --> 00:06:24,660
and enabling an administrator

157
00:06:24,660 --> 00:06:27,030
to specify the order of the menu choices,

158
00:06:27,030 --> 00:06:28,590
provide user friendly names,

159
00:06:28,590 --> 00:06:31,290
and password protect different menu entries.

160
00:06:31,290 --> 00:06:33,270
You can also generate a password hash

161
00:06:33,270 --> 00:06:34,710
to protect your boot menu

162
00:06:34,710 --> 00:06:39,710
by using grub2-mkpasswd

163
00:06:39,877 --> 00:06:44,430
pbkdf2 at the command line.

164
00:06:44,430 --> 00:06:47,820
The /etc/default/grub file

165
00:06:47,820 --> 00:06:50,730
is going to contain the GRUB 2 display menu settings

166
00:06:50,730 --> 00:06:54,780
that are read by the /etc/grub.d scripts.

167
00:06:54,780 --> 00:06:58,410
And they're going to be built in to your grub.config file.

168
00:06:58,410 --> 00:07:00,300
It's going to enable you to change options

169
00:07:00,300 --> 00:07:03,540
such as how many seconds the GRUB 2 loader is going to wait

170
00:07:03,540 --> 00:07:06,570
before it automatically selects the default boot option,

171
00:07:06,570 --> 00:07:07,800
whether or not the GRUB 2

172
00:07:07,800 --> 00:07:09,750
will actually order kernel versions

173
00:07:09,750 --> 00:07:10,980
in a sub menu

174
00:07:10,980 --> 00:07:13,440
or whether or not GRUB 2 will display the menu

175
00:07:13,440 --> 00:07:14,850
in a graphical terminal

176
00:07:14,850 --> 00:07:16,740
and many other options.

177
00:07:16,740 --> 00:07:21,330
The grub2-mkconfig command or the make config command

178
00:07:21,330 --> 00:07:23,760
will generate a new GRUB configuration file

179
00:07:23,760 --> 00:07:27,210
or update the existing GRUB configuration file.

180
00:07:27,210 --> 00:07:28,680
This command is going to combine

181
00:07:28,680 --> 00:07:30,480
the configuration file templates

182
00:07:30,480 --> 00:07:34,230
inside of the /etc/grub.d directory

183
00:07:34,230 --> 00:07:38,580
with the settings in the /etc/default/grub,

184
00:07:38,580 --> 00:07:42,900
as well as to generate the grub.cfg configuration file.

185
00:07:42,900 --> 00:07:47,900
To run this, type grub2-mkconfig-o and the file name.

186
00:07:49,290 --> 00:07:52,290
If you simply need to update your GRUB 2 configuration file

187
00:07:52,290 --> 00:07:53,820
instead of making a new one,

188
00:07:53,820 --> 00:07:56,043
you can use the update-grub2 command too.

