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

11.3 12.0 12.1 12.2 gimp3 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 xry111/for-12.3 xry111/llvm18 xry111/spidermonkey128 xry111/xf86-video-removal
Last change on this file since a9bda7c was e8d6204, checked in by Xi Ruoyao <xry111@…>, 21 months ago

grub-setup: rewrite the description for CONFIG_EFI_STUB

Avoid mistakenly using the terminology "EFI handover protocol". With
Linux 6.2 or newer we can enable EFI stub but disable EFI handover
protocol (CONFIG_EFI_HANDOVER_PROTOCOL=n). The help message of this
option also says the upstream GRUB does not use EFI handover protocol,
so it's only needed for some distros with a patched (old) GRUB.

Tested with mainline kernel and CONFIG_EFI_HANDOVER_PROTOCOL disabled.

  • Property mode set to 100644
File size: 19.4 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
12 <title>Using GRUB to Set Up the Boot Process with UEFI</title>
13
14 <sect2>
15 <title>Turn Off Secure Boot</title>
16
17 <para>
18 BLFS does not have the essential packages to support Secure Boot. To
19 set up the boot process with GRUB and UEFI in BLFS, Secure
20 Boot must be turned off from the configuration interface of the
21 firmware. Read the documentation provided by the manufacturer of your
22 system to find out how.
23 </para>
24 </sect2>
25
26 <sect2>
27 <title>Create an Emergency Boot Disk</title>
28
29 <para>
30 Ensure that an emergency boot disk is ready to <quote>rescue</quote>
31 the system in case the system becomes un-bootable. To make an
32 emergency boot disk with GRUB for an EFI based system, find a spare
33 USB flash drive and create a
34 <systemitem class="filesystem">vfat</systemitem> file system on it.
35 Install <xref linkend="dosfstools"/> first, then
36 as the <systemitem class="username">root</systemitem> user:
37 </para>
38
39 <warning>
40 <para>
41 The following command will erase all directories and files in the
42 partition. Make sure your USB flash drive contains no data which
43 will be needed, and change <userinput>sdx1</userinput> to the
44 device node corresponding to the first partition of the USB flash
45 drive. Be careful not to overwrite your hard drive with a typo!
46 </para>
47 </warning>
48
49 <screen role="nodump"><userinput>mkfs.vfat /dev/sdx1</userinput></screen>
50
51 <para>
52 Still as the <systemitem class="username">root</systemitem> user, use
53 the <command>fdisk</command> utility to set the first partition
54 of the USB flash drive to be an <quote>EFI system</quote> partition
55 (change <userinput>sdx</userinput> to the device node corresponding
56 to your USB flash drive):
57 </para>
58
59<screen role="nodump"><userinput>fdisk /dev/sdx</userinput>
60<literal>
61Welcome to fdisk (util-linux 2.38.1).
62Changes will remain in memory only, until you decide to write them.
63Be careful before using the write command.
64
65
66Command (m for help): </literal><userinput>t</userinput>
67<literal>Partition number (1-9, default 9): </literal><userinput>1</userinput>
68<literal>Partition type or alias (type L to list all): </literal><userinput>uefi</userinput>
69<literal>Changed type of partition 'Linux filesystem' to 'EFI System'.
70
71Command (m for help): </literal><userinput>w</userinput>
72<literal>The partition table has been altered.
73Calling ioctl() to re-read partition table.
74Syncing disks.</literal></screen>
75
76 <para>
77 Still as the <systemitem class="username">root</systemitem> user,
78 create a mount point for the EFI partition on the USB flash drive
79 and mount it:
80 </para>
81
82<screen role="nodump"><userinput>mkdir -pv /mnt/rescue &amp;&amp;
83mount -v -t vfat /dev/sdx1 /mnt/rescue</userinput></screen>
84
85 <para>
86 Install GRUB for EFI on the partition:
87 </para>
88
89<screen role="nodump"><userinput>grub-install --target=x86_64-efi --removable --efi-directory=/mnt/rescue --boot-directory=/mnt/rescue</userinput></screen>
90
91 <para>
92 Unmount the partition:
93 </para>
94
95<screen role="nodump"><userinput>umount /mnt/rescue</userinput></screen>
96
97 <para>
98 Now the USB flash drive can be used as an emergency boot disk on any x86-64
99 UEFI platform. It will boot the system and show the GRUB shell. Then you
100 can type commands to boot your operating system from the hard drive.
101 To learn how to select the boot device, read the manual of your
102 motherboard or laptop.
103 </para>
104
105 </sect2>
106
107 <sect2 role="kernel" id="uefi-kernel">
108 <title>Kernel Configuration for UEFI support</title>
109
110 <para>
111 Enable the following options in the kernel configuration and recompile
112 the kernel if necessary:
113 </para>
114
115<screen><literal>Processor type and features ---&gt;
116 [*] EFI runtime service support [CONFIG_EFI]
117 [*] EFI stub support [CONFIG_EFI_STUB]
118Enable the block layer ---&gt;
119 Partition Types ---&gt;
120 [*] Advanced partition selection [CONFIG_PARTITION_ADVANCED]
121 [*] EFI GUID Partition support [CONFIG_EFI_PARTITION]
122Device Drivers ---&gt;
123 Firmware Drivers ---&gt;
124 [*] Mark VGA/VBE/EFI FB as generic system framebuffer [CONFIG_SYSFB_SIMPLEFB]
125 EFI (Extensible Firmware Interface) Support ---&gt;
126 &lt; &gt; EFI Variable Support via sysfs [CONFIG_EFI_VARS]
127 Graphics support ---&gt;
128 &lt;*&gt; Direct Rendering Manager [CONFIG_DRM]
129 [*] Enable legacy fbdev support for your modesetting driver [CONFIG_DRM_FBDEV_EMULATION]
130 &lt;*&gt; Simple framebuffer driver [CONFIG_DRM_SIMPLEDRM]
131 Frame buffer Devices ---&gt;
132 &lt;*&gt; Support for frame buffer devices ---&gt; [CONFIG_FB]
133 Console display driver support ---&gt;
134 [*] Framebuffer Console support [CONFIG_FRAMEBUFFER_CONSOLE]
135File systems ---&gt;
136 &lt;DOS/FAT/EXFAT/NT Filesystems ---&gt;
137 &lt;*/M&gt; VFAT (Windows-95) fs support [CONFIG_VFAT_FS]
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 configuration options:</title>
143
144 <varlistentry>
145 <term><parameter>CONFIG_EFI_STUB</parameter></term>
146 <listitem>
147 <para>On EFI systems, GRUB boots the Linux kernel by invoking the
148 EFI firmware to load it as an EFI application. So, EFI stub is
149 needed to wrap the kernel as an EFI application.</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>
164 <parameter>CONFIG_SYSFB_SIMPLEFB</parameter>,
165 <parameter>CONFIG_DRM</parameter>,
166 <parameter>CONFIG_DRM_FBDEV_EMULATION</parameter>,
167 <parameter>CONFIG_DRM_SIMPLEDRM</parameter>,
168 <parameter>CONFIG_FB</parameter>, and
169 <parameter>CONFIG_FRAMEBUFFER_CONSOLE</parameter></term>
170 <listitem>
171 <para>The combination of these options provides the Linux console
172 support on top of the UEFI framebuffer. To allow the kernel to
173 print debug messages at an early boot stage, they shouldn't be
174 built as kernel modules unless an initramfs will be used.</para>
175 </listitem>
176 </varlistentry>
177
178 </variablelist>
179
180 </sect2>
181
182 <sect2>
183 <title>Find or Create the EFI System Partition</title>
184
185 <para>
186 On EFI based systems, the bootloaders are installed in a special FAT32
187 partition called an <emphasis>EFI System Partition</emphasis> (ESP).
188 If your system supports EFI, and a recent version of some Linux
189 distribution or Windows is pre-installed, it's likely that the ESP
190 has already been created. As the
191 <systemitem class="username">root</systemitem> user, list all the
192 partitions on your hard drive (replace <userinput>sda</userinput>
193 with the device corresponding to the appropriate hard drive):
194 </para>
195
196 <screen role="nodump"><userinput>fdisk -l /dev/sda</userinput></screen>
197
198 <para>
199 The <quote>Type</quote> column of the ESP should be
200 <literal>EFI System</literal>.
201 </para>
202
203 <para>
204 If the system or the hard drive is new, or it's the first
205 installation of a UEFI-booted OS on the system, the ESP may not exist.
206 In that case, create a new partition, make a
207 <systemitem class="filesystem">vfat</systemitem> file system on it,
208 and set the partition type to <quote>EFI system</quote>. See the
209 instructions for the emergency boot device above as a reference.
210 </para>
211
212 <warning>
213 <para>
214 Some (old) UEFI implementations may require the ESP to be the first
215 partition on the disk.
216 </para>
217 </warning>
218
219 <para>
220 Now, as the <systemitem class="username">root</systemitem> user,
221 create the mount point for the ESP, and mount it (replace
222 <userinput>sda1</userinput> with the device node corresponding to
223 the ESP):
224 </para>
225
226<screen role="nodump"><userinput>mkdir -pv /boot/efi &amp;&amp;
227mount -v -t vfat /dev/sda1 /boot/efi</userinput></screen>
228
229 <para>
230 Add an entry for the ESP in
231 <filename>/etc/fstab</filename>, so it will be mounted automatically
232 during system boot:
233 </para>
234
235<screen role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
236<literal>/dev/sda1 /boot/efi vfat defaults 0 1</literal>
237<userinput>EOF</userinput></screen>
238
239 </sect2>
240
241 <sect2>
242 <title>Minimal Boot Configuration with GRUB and EFI</title>
243
244 <para>
245 On UEFI based systems, GRUB works by installing an EFI application
246 (a special kind of executable) into the ESP. The EFI firmware will
247 search boot loaders in EFI applications from boot entries recorded
248 in EFI variables, and additionally a hardcoded path
249 <filename>EFI/BOOT/BOOTX64.EFI</filename>. Normally, a boot loader
250 should be installed into a custom path and the path should be recorded
251 in the EFI variables. The use of the hardcoded path should be
252 avoided if possible. However, in some cases we have to use
253 the hardcoded path:
254 </para>
255
256 <itemizedlist>
257 <listitem>
258 <para>
259 The system is not booted with EFI yet, making EFI variables
260 inaccessible.
261 </para>
262 </listitem>
263 <listitem>
264 <para>
265 The EFI firmware is 64-bit but the LFS system is 32-bit, making
266 EFI variables inaccessible because the kernel cannot invoke EFI
267 runtime services with a different virtual address length.
268 </para>
269 </listitem>
270 <listitem>
271 <para>
272 LFS is built for a Live USB, so we cannot rely on EFI variables,
273 which are stored in NVRAM or EEPROM on the local machine.
274 </para>
275 </listitem>
276 <listitem>
277 <para>
278 You are unable or unwilling to install the
279 <application>efibootmgr</application> for manipulating boot
280 entries in EFI variables.
281 </para>
282 </listitem>
283 </itemizedlist>
284
285 <para>
286 In these cases, follow these instructions to install the GRUB EFI
287 application into the hardcoded path and make a minimal boot
288 configuration. Otherwise it's better to skip ahead and set up the
289 boot configuration normally.
290 </para>
291
292 <para>
293 To install GRUB with the EFI application in the hardcoded
294 path <filename>EFI/BOOT/BOOTX64.EFI</filename>, first ensure the boot
295 partition is mounted at <filename class="directory">/boot</filename>
296 and the ESP is mounted at
297 <filename class="directory">/boot/efi</filename>. Then, as the &root;
298 user, run the command:
299 </para>
300
301 <note>
302 <para>
303 This command will overwrite
304 <filename>/boot/efi/EFI/BOOT/BOOTX64.EFI</filename>. It may break a
305 bootloader already installed there. Back it up if you are not sure.
306 </para>
307 </note>
308
309 <screen role="nodump"><userinput>grub-install --target=x86_64-efi --removable</userinput></screen>
310
311 <para>
312 This command will install the GRUB EFI application into the hardcoded path
313 <filename>/boot/efi/EFI/BOOT/BOOTX64.EFI</filename>, so the EFI
314 firmware can find and load it. The remaining GRUB files are installed
315 in the <filename class="directory">/boot/grub</filename> directory and
316 will be loaded by <filename>BOOTX64.EFI</filename> during system boot.
317 </para>
318
319 <note>
320 <para>
321 The EFI firmware usually prefers the EFI applications with a path
322 stored in EFI variables to the EFI
323 application at the hardcoded path. So you may need to invoke the
324 boot selection menu or firmware setting interface to select the
325 newly installed GRUB manually on the next boot. Read the manual of
326 your motherboard or laptop to learn how.
327 </para>
328 </note>
329
330 <para>
331 If you've followed the instructions in this section and set up a minimal boot
332 configuration, now skip ahead to
333 <quote>Creating the GRUB Configuration File</quote>.
334 </para>
335 </sect2>
336
337 <sect2>
338 <title>Mount the EFI Variable File System</title>
339
340 <para>
341 The installation of GRUB on a UEFI platform requires that the EFI Variable
342 file system, <systemitem class="filesystem">efivarfs</systemitem>, is
343 mounted. As the <systemitem class="username">root</systemitem> user,
344 mount it if it's not already mounted:
345 </para>
346
347<screen role="nodump"><userinput>mountpoint /sys/firmware/efi/efivars || mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars</userinput></screen>
348
349 <note revision="systemd">
350 <para>
351 If the system is booted with UEFI and systemd,
352 <systemitem class="filesystem">efivarfs</systemitem> will be mounted
353 automatically. However, in the LFS chroot environment it still needs to
354 be mounted manually.
355 </para>
356 </note>
357
358 <para revision="sysv">
359 Now add an entry for the
360 <systemitem class="filesystem">efivarfs</systemitem> in
361 <filename>/etc/fstab</filename> so it will be mounted automatically
362 during system boot:
363 </para>
364
365<screen revision="sysv" role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
366<literal>efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 0</literal>
367<userinput>EOF</userinput></screen>
368
369 <warning>
370 <para>
371 If the system is not booted with UEFI, the directory
372 <filename class="directory">/sys/firmware/efi</filename> will be
373 missing. In this case you should boot the system in UEFI mode with
374 the emergency boot disk or using a minimal boot configuration created as
375 above, then mount
376 <systemitem class="filesystem">efivarfs</systemitem> and continue.
377 </para>
378 </warning>
379 </sect2>
380
381 <sect2>
382 <title>Setting Up the Configuration</title>
383
384 <para>
385 On UEFI based systems, GRUB works by installing an EFI application
386 (a special kind of executable) into
387 <filename class="directory">/boot/efi/EFI/[id]/grubx64.efi</filename>,
388 where <filename class="directory">/boot/efi</filename> is the mount
389 point of the ESP, and <literal>[id]</literal> is replaced with an
390 identifier specified in the <command>grub-install</command> command
391 line. GRUB will create an entry in the EFI variables containing
392 the path <literal>EFI/[id]/grubx64.efi</literal> so the EFI firmware
393 can find <filename>grubx64.efi</filename> and load it.
394 </para>
395
396 <para>
397 <filename>grubx64.efi</filename> is very lightweight (136 KB with
398 GRUB-2.06) so it will not use much space in the ESP. A typical ESP
399 size is 100 MB (for Windows boot manager, which uses about 50 MB in
400 the ESP). Once <filename>grubx64.efi</filename> has been loaded by the
401 firmware, it will load GRUB modules from the boot partition.
402 The default location is
403 <filename class="directory">/boot/grub</filename>.
404 </para>
405
406 <para>
407 As the <systemitem class="username">root</systemitem> user, install
408 the GRUB files into <filename>/boot/efi/EFI/LFS/grubx64.efi</filename>
409 and <filename class="directory">/boot/grub</filename>. Then set up the
410 boot entry in the EFI variables:
411 </para>
412
413<screen role="nodump"><userinput>grub-install --bootloader-id=LFS --recheck</userinput></screen>
414
415 <para>
416 If the installation is successful, the output should be:
417 </para>
418
419<screen role="nodump"><literal>Installing for x86_64-efi platform.
420Installation finished. No error reported.</literal></screen>
421
422 <para>
423 Issue the <command>efibootmgr | cut -f 1</command> command to recheck the EFI boot
424 configuration. An example of the output is:
425 </para>
426
427<screen role="nodump"><literal>BootCurrent: 0000
428Timeout: 1 seconds
429BootOrder: 0005,0000,0002,0001,0003,0004
430Boot0000* ARCH
431Boot0001* UEFI:CD/DVD Drive
432Boot0002* Windows Boot Manager
433Boot0003* UEFI:Removable Device
434Boot0004* UEFI:Network Device
435Boot0005* LFS</literal></screen>
436
437 <para>
438 Note that <literal>0005</literal> is the first in the
439 <literal>BootOrder</literal>, and <literal>Boot0005</literal>
440 is <literal>LFS</literal>. This means that on the next boot, the
441 version of GRUB installed by LFS will be used to boot the system.
442 </para>
443
444 </sect2>
445
446 <sect2>
447 <title>Creating the GRUB Configuration File</title>
448
449 <indexterm zone="grub-setup grub-video">
450 <primary sortas="e-boot-grub-grub-cfg">/boot/grub/grub.cfg</primary>
451 </indexterm>
452
453 <para>
454 Generate <filename>/boot/grub/grub.cfg</filename> to configure the
455 boot menu of GRUB:
456 </para>
457
458<screen role="nodump"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
459<literal># Begin /boot/grub/grub.cfg
460set default=0
461set timeout=5
462
463insmod part_gpt
464insmod ext2
465set root=(hd0,2)
466
467if loadfont /boot/grub/fonts/unicode.pf2; then
468 set gfxmode=auto
469 insmod all_video
470 terminal_output gfxterm
471fi
472
473menuentry "GNU/Linux, Linux 5.19.2-lfs-11.2" {
474 linux /boot/vmlinuz-5.19.2-lfs-11.2 root=/dev/sda2 ro
475}
476
477menuentry "Firmware Setup" {
478 fwsetup
479}</literal>
480<userinput>EOF</userinput></screen>
481
482 <para>
483 <literal>(hd0,2)</literal>, <literal>sda2</literal>, and
484 <literal>5.19.2-lfs-11.2</literal> must match your
485 configuration.
486 </para>
487
488 <note>
489 <para>
490 From GRUB's perspective, the files are relative to the partitions
491 used. If you used a separate /boot partition, remove /boot from the
492 above paths (to kernel and to <filename>unicode.pf2</filename>). You
493 will also need to change the "set root" line to point to the boot
494 partition.
495 </para>
496 </note>
497
498 <para>
499 The <literal>Firmware Setup</literal> entry can be used to enter the
500 configuration interface provided by the firmware (sometimes called
501 <quote>BIOS configuration</quote>).
502 </para>
503 </sect2>
504
505 <sect2>
506 <title>Dual-booting with Windows</title>
507
508 <para>
509 Add a menu entry for Windows into <filename>grub.cfg</filename>:
510 </para>
511
512<screen role="nodump"><userinput>cat &gt;&gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
513<literal># Begin Windows addition
514
515menuentry "Windows 11" {
516 insmod fat
517 insmod chain
518 set root=(hd0,1)
519 chainloader /EFI/Microsoft/Boot/bootmgfw.efi
520}</literal>
521<userinput>EOF</userinput></screen>
522
523 <para>
524 <literal>(hd0,1)</literal> should be replaced with the GRUB
525 designated name for the ESP. The <literal>chainloader</literal>
526 directive can be used to tell GRUB to run another EFI executable,
527 in this case the Windows Boot Manager. You may put more usable tools
528 in EFI executable format (for example, an EFI shell) into the ESP and
529 create GRUB entries for them, as well.
530 </para>
531
532 </sect2>
533
534</sect1>
Note: See TracBrowser for help on using the repository browser.