source: postlfs/filesystems/uefi-bootloaders/grub-setup.xml@ 45ab6c7

11.0 qt5new trunk
Last change on this file since 45ab6c7 was 45ab6c7, checked in by Xi Ruoyao <xry111@…>, 5 months ago

more SVN prop clean up

Remove "$LastChanged$" everywhere, and also some unused $Date$

  • Property mode set to 100644
File size: 15.0 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="grub-setup" xreflabel="Using GRUB to Set Up the Boot Process with UEFI">
9 <?dbhtml filename="grub-setup.html"?>
10
11 <sect1info>
12 <date>$Date: 2021-02-21 03:35:58 +0800 (日, 2021-02-21) $</date>
13 </sect1info>
14
15 <title>Using GRUB to Set Up the Boot Process with UEFI</title>
16
17 <sect2>
18 <title>Turn Off Secure Boot</title>
19
20 <para>
21 BLFS does not have the essential packages to support Secure Boot. To
22 set up the boot process with GRUB for UEFI installed in BLFS, Secure
23 Boot must be turned off from the configuration interface of the
24 firmware. Read the documentation provided by the manufacturer of your
25 system to find out how.
26 </para>
27 </sect2>
28
29 <sect2>
30 <title>Create an Emergency Boot Disk</title>
31
32 <para>
33 Ensure that an emergency boot disk is ready to <quote>rescue</quote>
34 the system in case the system becomes un-bootable. To make an
35 emergency boot disk with GRUB for an EFI based system, find a spare
36 USB flash drive and create a
37 <systemitem class="filesystem">vfat</systemitem> file system on it.
38 Install <xref linkend="dosfstools"/> first, then
39 as the <systemitem class="username">root</systemitem> user:
40 </para>
41
42 <warning>
43 <para>
44 The following command will erase all directories and files in the
45 partition. Make sure your USB flash drive contains no data which
46 will be needed, and change <userinput>sdx1</userinput> to the
47 device node corresponding to the first partition of the USB flash
48 drive. Be careful not to overwrite your hard drive with a typo!
49 </para>
50 </warning>
51
52 <screen role="nodump"><userinput>mkfs.vfat /dev/sdx1</userinput></screen>
53
54 <para>
55 Still as the <systemitem class="username">root</systemitem> user, use
56 the <command>fdisk</command> utility to set the first parition
57 of the USB flash drive to be an <quote>EFI system</quote> partition
58 (change <userinput>sdx</userinput> to the device node corresponding
59 to your USB flash drive):
60 </para>
61
62<screen role="nodump"><userinput>fdisk /dev/sdx</userinput>
63<literal>
64Welcome to fdisk (util-linux 2.36.2).
65Changes will remain in memory only, until you decide to write them.
66Be careful before using the write command.
67
68
69Command (m for help): </literal><userinput>t</userinput>
70<literal>Selected partition 1
71Hex code or alias (type L to list all): </literal><userinput>ef</userinput>
72<literal>Changed type of partition 'Linux' to 'EFI (FAT-12/16/32)'.
73
74Command (m for help): </literal><userinput>w</userinput>
75<literal>The partition table has been altered.
76Calling ioctl() to re-read partition table.
77Syncing disks.</literal></screen>
78
79 <para>
80 Still as the <systemitem class="username">root</systemitem> user,
81 create a mount point for the EFI partition on the USB flash drive
82 and mount it:
83 </para>
84
85<screen role="nodump"><userinput>mkdir -pv /mnt/rescue &amp;&amp;
86mount -v -t vfat /dev/sdx1 /mnt/rescue</userinput></screen>
87
88 <para>
89 Install GRUB for EFI on the partition:
90 </para>
91
92<screen role="nodump"><userinput>grub-install --removable --efi-directory=/mnt/rescue --boot-directory=/mnt/rescue/grub</userinput></screen>
93
94 <para>
95 Unmount the partition:
96 </para>
97
98<screen role="nodump"><userinput>umount /mnt/rescue</userinput></screen>
99
100 <para>
101 Now the USB flash drive can be used as a emergency boot disk on x86-64
102 UEFI platform. It will boot the system and show the GRUB shell. Then you
103 can type commands to boot your operating systems on the hard drive.
104 To learn how to select the boot device, read the manual of your
105 motherboard or laptop.
106 </para>
107
108 </sect2>
109
110 <sect2 role="kernel" id="uefi-kernel">
111 <title>Kernel Configuration for UEFI support</title>
112
113 <para>
114 Enable the following options in the kernel configuration and recompile
115 the kernel if necessary:
116 </para>
117
118<screen><literal>Processor type and features ---&gt;
119 [*] EFI runtime service support [CONFIG_EFI]
120 [*] EFI stub support [CONFIG_EFI_STUB]
121Firmware Drivers ---&gt;
122 EFI (Extensible Firmware Interface) Support ---&gt;
123 &lt; &gt; EFI Variable Support via sysfs [CONFIG_EFI_VARS]
124 [*] Export efi runtime maps to sysfs [CONFIG_EFI_RUNTIME_MAP]
125Enable the block layer ---&gt;
126 Partition Types ---&gt;
127 [*] Advanced partition selection [CONFIG_PARTITION_ADVANCED]
128 [*] EFI GUID Partition support [CONFIG_EFI_PARTITION]
129Device Drivers ---&gt;
130 Graphics support ---&gt;
131 Frame buffer Devices ---&gt;
132 Support for frame buffer devices ---&gt; [CONFIG_FB]
133 [*] EFI-based Framebuffer support [CONFIG_FB_EFI]
134 Console display driver support ---&gt;
135 [*] Framebuffer Console support [CONFIG_FRAMEBUFFER_CONSOLE]
136File systems ---&gt;
137 Pseudo filesystems ---&gt;
138 &lt;*/M&gt; EFI Variable filesystem [CONFIG_EFIVAR_FS]</literal></screen>
139
140 <variablelist>
141 <title>The meaning of the configure options:</title>
142
143 <varlistentry>
144 <term><parameter>CONFIG_EFI_STUB</parameter></term>
145 <listitem>
146 <para>Although the EFI stub is designed to boot a kernel directly from
147 the UEFI firmware (without a bootloader like GRUB), GRUB needs the
148 kernel to be loaded to support the EFI handover protocol enabled by
149 this option.</para>
150 </listitem>
151 </varlistentry>
152
153 <varlistentry>
154 <term><parameter>CONFIG_EFI_VARS</parameter></term>
155 <listitem>
156 <para>Don't use this deprecated option because of a 1024-byte
157 variable size limit. Its function is replaced by
158 <parameter>CONFIG_EFIVAR_FS</parameter>.</para>
159 </listitem>
160 </varlistentry>
161
162 <varlistentry>
163 <term><parameter>CONFIG_FB_EFI</parameter> and <parameter>CONFIG_FRAMEBUFFER_CONSOLE</parameter></term>
164 <listitem>
165 <para>The combination of these two options allows the kernel to
166 print debug messages (along with Tux logos) at the early stage of boot
167 the process with UEFI.</para>
168 </listitem>
169 </varlistentry>
170
171 </variablelist>
172
173 </sect2>
174
175 <sect2>
176 <title>Find or Create the EFI System Partition</title>
177
178 <para>
179 On EFI based system, the bootloaders are installed in a special FAT32
180 partition called an <emphasis>EFI System Partition</emphasis> (ESP).
181 If your system supports EFI, and a recent version of Linux
182 distribution or Windows is pre-installed, it's likely that the ESP
183 is already created. As the
184 <systemitem class="username">root</systemitem> user, list all the
185 partitions on your hard drive (replace <userinput>sda</userinput>
186 with the device corresponding to the appropriate hard drive):
187 </para>
188
189 <screen role="nodump"><userinput>fdisk -l /dev/sda</userinput></screen>
190
191 <para>
192 The <quote>Type</quote> column of the ESP should be
193 <literal>EFI System</literal>.
194 </para>
195
196 <para>
197 If the system or the hard drive is new, or it's a first time
198 install an UEFI booted OS on the system, the ESP may not exist.
199 In that case, create a new partition, make a
200 <systemitem class="filesystem">vfat</systemitem> file system on it,
201 and set the partition type to <quote>EFI system</quote>. See the
202 instructions for the emergency boot device above as a reference.
203 </para>
204
205 <warning>
206 <para>
207 Some (old) UEFI implementations may demand the ESP to be the first
208 partition on the disk.
209 </para>
210 </warning>
211
212 <para>
213 Now, as the <systemitem class="username">root</systemitem> user,
214 create the mount point for the ESP, and mount it (replace
215 <userinput>sda1</userinput> with the device node corresponding to
216 the ESP):
217 </para>
218
219<screen role="nodump"><userinput>mkdir -pv /boot/efi &amp;&amp;
220mount -v -t vfat /dev/sda1 /boot/efi</userinput></screen>
221
222 <para>
223 Add an entry for the ESP in
224 <filename>/etc/fstab</filename>, so it will be mounted automatically
225 during system boot:
226 </para>
227
228<screen role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
229<literal>/dev/sda1 /boot/efi vfat defaults 0 1</literal>
230<userinput>EOF</userinput></screen>
231
232 </sect2>
233
234 <sect2>
235 <title>Mount the EFI Variable File System</title>
236
237 <para>
238 The installation of GRUB on a UEFI platform requires that the EFI Variable
239 file system, <systemitem class="filesystem">efivarfs</systemitem>, to be
240 mounted. As the <systemitem class="username">root</systemitem> user:
241 </para>
242
243<screen role="nodump"><userinput>mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars</userinput></screen>
244
245 <note revision="systemd">
246 <para>
247 If the system is booted with UEFI and systemd,
248 <systemitem class="filesystem">efivarfs</systemitem> will be mounted
249 automatically. However in the LFS chroot environment it still needs to
250 be mounted manually.
251 </para>
252 </note>
253
254 <para revision="sysv">
255 Now add an entry for the
256 <systemitem class="filesystem">efivarfs</systemitem> in
257 <filename>/etc/fstab</filename> so it will be mounted automatically
258 during system boot:
259 </para>
260
261<screen revision="sysv" role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
262<literal>efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 1</literal>
263<userinput>EOF</userinput></screen>
264
265 <warning>
266 <para>
267 If the system is not booted with UEFI, the directory
268 <filename class="directory">/sys/firmware/efi</filename> will be
269 missing. In this case you should boot the system in UEFI mode with
270 the emergency boot disk created as above.
271 </para>
272 </warning>
273 </sect2>
274
275 <sect2>
276 <title>Setting Up the Configuration</title>
277
278 <para>
279 On UEFI based systems, GRUB works by installing an EFI application
280 (a special kind of executable) into
281 <filename class="directory">/boot/efi/EFI/[id]/grubx64.efi</filename>,
282 where <filename class="directory">/boot/efi</filename> is the mount
283 point of the ESP, and <literal>[id]</literal> is replaced with an
284 identifier specified in the <command>grub-install</command> command
285 line. GRUB will create an entry in the EFI variables containing
286 the path <literal>EFI/[id]/grubx64.efi</literal> so the EFI firmware
287 can find <filename>grubx64.efi</filename> and load it.
288 </para>
289
290 <para>
291 <filename>grubx64.efi</filename> is very lightweight (136 KB with
292 GRUB-2.06~rc1) so it will not use much space in the ESP. A typical ESP
293 size is 100 MB (for Windows boot manager, which uses about 50 MB in
294 the ESP). Once <filename>grubx64.efi</filename> loaded by the
295 firmware, it will load GRUB modules in the boot partition.
296 The default location is
297 <filename class="directory">/boot/grub</filename>.
298 </para>
299
300 <para>
301 As the <systemitem class="username">root</systemitem> user, install
302 the GRUB files into <filename>/boot/efi/EFI/LFS/grubx64.efi</filename>
303 and <filename class="directory">/boot/grub</filename>. Then set up the
304 boot entry in the EFI variables:
305 </para>
306
307<screen role="nodump"><userinput>grub-install --bootloader-id=LFS --recheck</userinput></screen>
308
309 <para>
310 If the installation is successful, the output should be:
311 </para>
312
313<screen role="nodump"><literal>Installing for x86_64-efi platform.
314Installation finished. No error reported.</literal></screen>
315
316 <para>
317 Issue <command>efibootmgr</command> to recheck the EFI boot
318 configuration. An example of the output is:
319 </para>
320
321<screen role="nodump"><literal>BootCurrent: 0000
322Timeout: 1 seconds
323BootOrder: 0005,0000,0002,0001,0003,0004
324Boot0000* ARCH
325Boot0001* UEFI:CD/DVD Drive
326Boot0002* Windows Boot Manager
327Boot0003* UEFI:Removable Device
328Boot0004* UEFI:Network Device
329Boot0005* LFS</literal></screen>
330
331 <para>
332 Note that <literal>0005</literal> is the first in the
333 <literal>BootOrder</literal>, and <literal>Boot0005</literal>
334 is <literal>LFS</literal>. This means that on the next boot, the
335 version of GRUB installed by LFS will be used to boot the system.
336 </para>
337
338 </sect2>
339
340 <sect2>
341 <title>Creating the GRUB Configuration File</title>
342
343 <indexterm zone="grub-setup grub-video">
344 <primary sortas="e-boot-grub-grub-cfg">/boot/grub/grub.cfg</primary>
345 </indexterm>
346
347 <para>
348 Generate <filename>/boot/grub/grub.cfg</filename> to configure the
349 boot menu of GRUB:
350 </para>
351
352<screen role="nodump"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
353<literal># Begin /boot/grub/grub.cfg
354set default=0
355set timeout=5
356
357insmod part_gpt
358insmod ext2
359set root=(hd0,2)
360
361if loadfont /boot/grub/fonts/unicode.pf2; then
362 set gfxmode=auto
363 insmod all_video
364 terminal_output gfxterm
365fi
366
367menuentry "GNU/Linux, Linux 5.10.17-lfs-10.1" {
368 linux /boot/vmlinuz-5.10.17-lfs-10.1 root=/dev/sda2 ro
369}
370
371menuentry "Firmware Setup" {
372 fwsetup
373}</literal>
374<userinput>EOF</userinput></screen>
375
376 <para>
377 <literal>(hd0,2)</literal>, <literal>sda2</literal>, and
378 <literal>5.10.17-lfs-10.1</literal> should be replaced to match your
379 configuration.
380 </para>
381
382 <note>
383 <para>
384 From GRUB's perspective, the files are relative to the partition
385 are used. If you used a separate /boot partition, remove /boot from the
386 above paths (to kernel and to <filename>unicode.pf2</filename>). You
387 will also need to change the set root line to point to the boot
388 partition.
389 </para>
390 </note>
391
392 <para>
393 The <literal>Firmware Setup</literal> entry can be used to enter the
394 configuration interface provided by the firmware (sometimes called
395 <quote>BIOS configuration</quote>).
396 </para>
397 </sect2>
398
399 <sect2>
400 <title>Dual-booting with Windows</title>
401
402 <para>
403 Add a menu entry for Windows into <filename>grub.cfg</filename>:
404 </para>
405
406<screen role="nodump"><userinput>cat &gt;&gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
407<literal># Begin Windows addition
408
409menuentry "Windows 10" {
410 insmod fat
411 insmod chain
412 set root=(hd0,1)
413 chainloader /EFI/Microsoft/Boot/bootmgfw.efi
414}</literal>
415<userinput>EOF</userinput></screen>
416
417 <para>
418 <literal>(hd0,1)</literal> should be replaced with the GRUB
419 designated name for the ESP. The <literal>chainloader</literal>
420 directive can be used to tell GRUB to run another EFI executable,
421 in this case the Windows Boot Manager. You may put more usable tools
422 in EFI executable format (for example, an EFI shell) into the ESP and
423 create GRUB entries for them.
424 </para>
425
426 </sect2>
427
428</sect1>
Note: See TracBrowser for help on using the repository browser.