1
00:00:06,728 --> 00:00:09,030
- Now that we know how grub is organized,

2
00:00:09,030 --> 00:00:11,870
let's do some grub troubleshooting.

3
00:00:11,870 --> 00:00:13,220
Let me create some trouble.

4
00:00:14,246 --> 00:00:17,246
(keyboard clacking)

5
00:00:21,350 --> 00:00:23,690
This command will override

6
00:00:24,995 --> 00:00:26,990
the boot checker, the mass boot record,

7
00:00:26,990 --> 00:00:30,090
the part that contains
the grub configuration.

8
00:00:30,090 --> 00:00:33,580
Look, if you do an xxd -l 512

9
00:00:33,580 --> 00:00:35,963
on dev/sda, there's nothing to boot from.

10
00:00:38,297 --> 00:00:40,400
Notice that I did not
wipe the partition table.

11
00:00:40,400 --> 00:00:45,182
That would bring me a completely
different range of problems

12
00:00:45,182 --> 00:00:46,830
Now I'm going to reboot,

13
00:00:46,830 --> 00:00:49,180
and first we are going
to see what's happening.

14
00:00:54,910 --> 00:00:56,200
So, this is what's happening

15
00:00:56,200 --> 00:00:59,170
if you don't have a massive
boot record anymore.

16
00:00:59,170 --> 00:01:01,630
The system cannot boot
from your hard drive

17
00:01:01,630 --> 00:01:03,890
and the power on self disk will look

18
00:01:03,890 --> 00:01:05,580
for the next bootable device.

19
00:01:05,580 --> 00:01:08,100
And the bootable device, in this case,

20
00:01:08,100 --> 00:01:10,970
is the installation disk.

21
00:01:10,970 --> 00:01:14,450
Which is nice because this
is the only thing that I can

22
00:01:15,460 --> 00:01:17,520
use to get out of this situation.

23
00:01:17,520 --> 00:01:19,733
We need to boot a rescue system.

24
00:01:21,210 --> 00:01:23,823
So, I'm selecting a
rescue sent to a system.

25
00:01:25,020 --> 00:01:26,750
And we'll start booting from there.

26
00:01:26,750 --> 00:01:27,860
We need to give it a minute

27
00:01:27,860 --> 00:01:30,223
to load the entire rescue environment.

28
00:01:35,760 --> 00:01:38,320
So, we need to select step one,

29
00:01:38,320 --> 00:01:41,870
which will look for the
partition or logical volume

30
00:01:41,870 --> 00:01:43,743
containing the root file system.

31
00:01:47,663 --> 00:01:49,900
And yes, we want to
mount it on mnt/sysimage

32
00:01:49,900 --> 00:01:52,720
so let's press RETURN,

33
00:01:52,720 --> 00:01:54,653
the old way to press ENTER.

34
00:01:56,378 --> 00:01:59,317
And now we can use chroot/mnt/sysimage

35
00:02:00,260 --> 00:02:02,800
We need to do that anyway.

36
00:02:02,800 --> 00:02:06,123
Now we need to type mount to
figure out what is mounted.

37
00:02:08,209 --> 00:02:10,850
And very nice, we can se
that /devmapper/centos-root

38
00:02:10,850 --> 00:02:13,730
is mounted on xfs, it's
a root file system.

39
00:02:13,730 --> 00:02:17,000
We can also see that
/dev/sda1 is mounted on /boot

40
00:02:17,930 --> 00:02:19,560
which is a requirement, as well,

41
00:02:19,560 --> 00:02:21,793
because that is the boot partition.

42
00:02:22,870 --> 00:02:25,420
And we need to reinstall grub

43
00:02:25,420 --> 00:02:26,986
and in order to reinstall grub

44
00:02:26,986 --> 00:02:29,686
you need access to the
contents of the boot partition.

45
00:02:32,360 --> 00:02:35,160
So, how are we going to reinstall grub?

46
00:02:35,160 --> 00:02:38,530
Well, that will be one
of the grub2 utilities.

47
00:02:38,530 --> 00:02:42,020
You can see that grub2 has many utilities.

48
00:02:42,020 --> 00:02:43,840
Most of them you will never use.

49
00:02:43,840 --> 00:02:47,300
But in this case we are
going to use grub2-install

50
00:02:48,851 --> 00:02:50,270
on /dev/sda

51
00:02:50,270 --> 00:02:54,970
Obviously, you have verified
the name of your disk device

52
00:02:54,970 --> 00:02:56,550
before you do so.

53
00:02:56,550 --> 00:02:58,850
And here we can see that it has installed.

54
00:02:58,850 --> 00:03:02,020
Installation finished, no error reported.

55
00:03:02,020 --> 00:03:07,020
So, let's see if we can
do xxd -L 512 on /dev/sva

56
00:03:07,790 --> 00:03:10,700
And that looks like boot code.

57
00:03:10,700 --> 00:03:14,640
This is the good old grub boot
logger as we have seen before

58
00:03:14,640 --> 00:03:17,170
So, from here we can type exit

59
00:03:17,170 --> 00:03:19,330
and next we can reboot

60
00:03:19,330 --> 00:03:24,220
and verify that the grub
recovery was successful.

61
00:03:24,220 --> 00:03:25,840
We see a grub boot menu again.

62
00:03:25,840 --> 00:03:27,623
So, this was successful.

63
00:03:29,900 --> 00:03:31,900
Another thing that you need to know about

64
00:03:31,900 --> 00:03:35,540
is manually booting from the grub2 prompt.

65
00:03:35,540 --> 00:03:37,940
I've summarized the
procedure on the slide.

66
00:03:37,940 --> 00:03:39,960
So, let's walk through the slide

67
00:03:39,960 --> 00:03:43,170
before I will tell you how to do this

68
00:03:43,170 --> 00:03:44,550
from a live system.

69
00:03:44,550 --> 00:03:46,677
So, in the grub2 prompt,
first step is that

70
00:03:46,677 --> 00:03:49,590
you need to load the required modules.

71
00:03:49,590 --> 00:03:52,240
These modules provide
access to your storage.

72
00:03:52,240 --> 00:03:56,280
Typically that will be xfs, lvm, and ext4.

73
00:03:56,280 --> 00:03:57,960
Then you will use the ls command

74
00:03:57,960 --> 00:04:00,220
to check the current disk layout.

75
00:04:00,220 --> 00:04:02,690
And based on the current disk layout,

76
00:04:02,690 --> 00:04:07,690
you can prompt for the contents
of the /boot directory.

77
00:04:07,770 --> 00:04:12,620
For a change in this slide,
I've used ls on hd0,gpt1

78
00:04:12,620 --> 00:04:16,660
which is a gui partition number one.

79
00:04:16,660 --> 00:04:19,400
In my demo I will do it on a bios system

80
00:04:19,400 --> 00:04:23,550
so we will have hd0, MSdos1.

81
00:04:23,550 --> 00:04:26,240
Next, we will look for
the kernel, the initramfs,

82
00:04:26,240 --> 00:04:28,070
as well as the root partition.

83
00:04:28,070 --> 00:04:30,080
And we will set the root like this.

84
00:04:30,080 --> 00:04:34,530
set root is lvm/fedora at -root

85
00:04:34,530 --> 00:04:36,600
And then we can declare the kernel.

86
00:04:36,600 --> 00:04:40,327
So, the kernel is linux
which is on hd0,gpt1

87
00:04:41,380 --> 00:04:44,400
And which has the name /vmlinuz whatever

88
00:04:44,400 --> 00:04:48,513
Use Tab completion to
make that name complete.

89
00:04:49,360 --> 00:04:51,200
Following that there is root

90
00:04:51,200 --> 00:04:53,750
which specifies the root volume to,

91
00:04:53,750 --> 00:04:56,530
in this case /dev/fedora/root

92
00:04:56,530 --> 00:04:59,150
And then you continue by
loading the /initramfs

93
00:05:00,760 --> 00:05:03,540
Once you have loaded kernel
as well as /initramfs

94
00:05:04,594 --> 00:05:05,851
you can type boot.

95
00:05:05,851 --> 00:05:07,200
And if you like what you have just done,

96
00:05:07,200 --> 00:05:09,470
once you are in the
operational system again,

97
00:05:09,470 --> 00:05:14,183
you can type grub2-mkconfig
-o /boot/grub2/grub.cfg

98
00:05:15,540 --> 00:05:19,220
And then your system will
be fully functional again.

99
00:05:19,220 --> 00:05:20,783
Let me show you how to do this.

100
00:05:21,940 --> 00:05:25,130
So, if you want to manually boot grub,

101
00:05:25,130 --> 00:05:28,380
from the grub menu,
provided that you see it,

102
00:05:28,380 --> 00:05:29,510
you can type C

103
00:05:30,620 --> 00:05:33,130
In some scenarios, you
will automatically drop

104
00:05:33,130 --> 00:05:34,323
in the grub shell.

105
00:05:35,731 --> 00:05:37,380
The help command is
useful, and it's giving you

106
00:05:37,380 --> 00:05:40,350
an overview of all that is
possible from the grub shell.

107
00:05:40,350 --> 00:05:42,950
And as you can see, there's
quite a lot of commands.

108
00:05:43,840 --> 00:05:47,880
Now, what we are going to do is insmod.

109
00:05:47,880 --> 00:05:50,030
So, insmod xfs

110
00:05:50,030 --> 00:05:51,250
to start it.

111
00:05:51,250 --> 00:05:54,460
Then insmod lvm

112
00:05:54,460 --> 00:05:57,810
And well, I don't really
need it, but for completeness

113
00:05:57,810 --> 00:05:59,965
let's include it, as well:

114
00:05:59,965 --> 00:06:01,230
insmod ext4

115
00:06:01,230 --> 00:06:03,870
Oh, we don't have an ext4 module.

116
00:06:03,870 --> 00:06:06,420
Alright, let's do it without ext4.

117
00:06:06,420 --> 00:06:09,660
Depends on the system
configuration, of course.

118
00:06:09,660 --> 00:06:11,830
Next, you will use ls.

119
00:06:11,830 --> 00:06:14,070
ls is quite important because it will

120
00:06:14,070 --> 00:06:17,160
reveal the current disk layout.

121
00:06:17,160 --> 00:06:21,230
So, we can see that bios
recognizes one drive: hd0

122
00:06:21,230 --> 00:06:23,730
And another drive: hd1

123
00:06:23,730 --> 00:06:28,110
And it shows us the partitioning
that exists on the drive.

124
00:06:28,110 --> 00:06:30,607
So hd0 MSdos1

125
00:06:30,607 --> 00:06:32,440
and hd0 MSdos2.

126
00:06:32,440 --> 00:06:35,993
That's probably what we're
going to need in order to boot.

127
00:06:37,000 --> 00:06:39,063
If you are not sure which one you need,

128
00:06:40,173 --> 00:06:43,460
then just use ls to figure
out what is available.

129
00:06:43,460 --> 00:06:48,460
So, ls hd0, MSdos2/

130
00:06:48,701 --> 00:06:51,170
It's giving us unknown filesystem.

131
00:06:51,170 --> 00:06:53,430
So, that's probably not what we need.

132
00:06:53,430 --> 00:06:57,110
Or, maybe you haven't loaded
the appropriate module.

133
00:06:57,110 --> 00:06:59,280
Let's try the same on MSdos1

134
00:06:59,280 --> 00:07:02,410
and on MSdos1 we can see the contents

135
00:07:02,410 --> 00:07:03,653
of this filesystem.

136
00:07:05,370 --> 00:07:07,260
And if you look carefully,
you can recognize this

137
00:07:07,260 --> 00:07:10,220
as the contents of the boot directory.

138
00:07:10,220 --> 00:07:12,750
So, we need to look for initramfs

139
00:07:13,652 --> 00:07:14,890
and vmlinuz.

140
00:07:14,890 --> 00:07:18,420
You can see them in the list
of files listed right here.

141
00:07:18,420 --> 00:07:20,690
So, that is what we are going to access.

142
00:07:20,690 --> 00:07:23,620
But also, before going there we need to

143
00:07:23,620 --> 00:07:25,730
set the root filesystem.

144
00:07:26,800 --> 00:07:29,640
So, set root =

145
00:07:29,640 --> 00:07:31,330
set root = what?

146
00:07:31,330 --> 00:07:33,770
Well, look a couple of lines above

147
00:07:33,770 --> 00:07:35,910
in the result of the ls command.

148
00:07:35,910 --> 00:07:39,063
We need to specify the lvm logical volume.

149
00:07:40,454 --> 00:07:43,660
In grub compatible notation.

150
00:07:43,660 --> 00:07:47,490
So, lvm/centos-root

151
00:07:47,490 --> 00:07:49,490
That is going to be the root filesystem.

152
00:07:50,850 --> 00:07:54,813
And now we can specify
which kernel we want to use.

153
00:07:54,813 --> 00:07:58,480
So, the kernel is going
to be on hd0, MSdos1

154
00:08:00,075 --> 00:08:02,850
/ vmlinuz

155
00:08:02,850 --> 00:08:06,663
I'm using tab completion because
it's way more convenient.

156
00:08:08,705 --> 00:08:11,470
3. Most recent version

157
00:08:11,470 --> 00:08:14,363
is 21 and that is the kernel.

158
00:08:15,380 --> 00:08:17,170
You know that the kernel can be loaded

159
00:08:17,170 --> 00:08:19,430
with a couple of different arguments.

160
00:08:19,430 --> 00:08:22,960
There is only one argument
that is really required,

161
00:08:22,960 --> 00:08:26,123
and that is the specification
of the root filesystem.

162
00:08:27,466 --> 00:08:31,090
So that will be root=/dev/centos

163
00:08:33,220 --> 00:08:35,340
/root

164
00:08:35,340 --> 00:08:38,430
Notice that at this point
there is no tab completion

165
00:08:39,277 --> 00:08:41,070
because the kernel hasn't been loaded yet.

166
00:08:41,070 --> 00:08:43,480
And the root that we specify here

167
00:08:43,480 --> 00:08:45,220
is a kernel name.

168
00:08:45,220 --> 00:08:46,053
Press ENTER

169
00:08:47,054 --> 00:08:48,030
and if it doesn't complain

170
00:08:48,030 --> 00:08:50,680
then hopefully it will be
happy and you can continue.

171
00:08:51,600 --> 00:08:54,520
Now that the kernel has been specified

172
00:08:54,520 --> 00:08:56,843
we can specify the initramfs

173
00:08:58,710 --> 00:09:01,700
initrd, which is the
old name for initramfs,

174
00:09:01,700 --> 00:09:03,200
its initram drive.

175
00:09:05,385 --> 00:09:06,635
So, hd0, MSdos1

176
00:09:10,046 --> 00:09:12,100
/ which brings us to
the root of the contents

177
00:09:12,100 --> 00:09:13,793
of this last boot directory.

178
00:09:16,437 --> 00:09:18,360
initramfs TAB

179
00:09:18,360 --> 00:09:19,440
So, what do we need?

180
00:09:19,440 --> 00:09:22,340
We need the 3. whatever image

181
00:09:22,340 --> 00:09:27,340
subversion 21, and press ENTER
to initialize that, as well.

182
00:09:27,470 --> 00:09:29,440
And if all was successful at this point

183
00:09:29,440 --> 00:09:30,663
you can type boot.

184
00:09:32,220 --> 00:09:33,800
That looks like a booting system,

185
00:09:33,800 --> 00:09:36,220
so probably we're good.

186
00:09:36,220 --> 00:09:37,470
And now I'm sure that we are good

187
00:09:37,470 --> 00:09:39,680
because you can see that right now

188
00:09:39,680 --> 00:09:42,933
it is processing the different
system, the unit files.

189
00:09:48,300 --> 00:09:51,730
So, as we have manually
booted the system now,

190
00:09:51,730 --> 00:09:53,370
I can log in

191
00:09:53,370 --> 00:09:55,850
and finally open a root shell to make

192
00:09:55,850 --> 00:09:57,733
the new configuration persistent.

193
00:10:08,267 --> 00:10:11,267
(keyboard clacking)

194
00:10:12,560 --> 00:10:15,170
So, to make the new
configuration persistent,

195
00:10:15,170 --> 00:10:17,760
use grub2-mkconfig

196
00:10:18,840 --> 00:10:21,623
You know what happens if
you don't specify the -o?

197
00:10:23,002 --> 00:10:24,530
It writes to the standard out.

198
00:10:24,530 --> 00:10:27,280
So, it has just written
the grub configuration

199
00:10:27,280 --> 00:10:28,690
to your screen.

200
00:10:28,690 --> 00:10:30,760
That might be very interesting to see,

201
00:10:30,760 --> 00:10:31,810
but it's not useful.

202
00:10:31,810 --> 00:10:34,060
Because you cannot boot from a screen.

203
00:10:34,060 --> 00:10:37,500
In order to boot, you
need to write the output

204
00:10:37,500 --> 00:10:38,850
to the configuration file.

205
00:10:38,850 --> 00:10:40,820
Which is -o for output /boot/grub2

206
00:10:43,090 --> 00:10:44,490
/grub.cfg

207
00:10:46,320 --> 00:10:49,380
Now it has created the
grub configuration file

208
00:10:49,380 --> 00:10:51,820
and at this point you are ready to boot

209
00:10:51,820 --> 00:10:54,020
from this new configuration.

210
00:10:54,020 --> 00:10:56,460
Which brings us to the
end of this section.

211
00:10:56,460 --> 00:10:59,850
I have a lab for you, a lab
without a solution this time.

212
00:10:59,850 --> 00:11:01,920
The lab is to use the grub2 prompt

213
00:11:01,920 --> 00:11:04,360
to start your system manually.

214
00:11:04,360 --> 00:11:05,830
If you want to verify it,

215
00:11:05,830 --> 00:11:08,350
it's the procedure that
we have just discovered.

216
00:11:08,350 --> 00:11:09,183
Good luck!

