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

11.0 11.1 11.2 11.3 12.0 12.1 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts lazarus lxqt plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since d5cc78a was d5cc78a, checked in by Bruce Dubbs <bdubbs@…>, 3 years ago

Editorial changes to new evi pages.

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@24395 af4574ff-66df-0310-9fd7-8a98e5e911e0

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