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

12.0 12.1 gimp3 ken/TL2024 ken/tuningfonts lazarus plabs/newcss python3.11 rahul/power-profiles-daemon renodr/vulkan-addition trunk xry111/for-12.3 xry111/llvm18 xry111/spidermonkey128
Last change on this file since 9d86c703 was 0f33c8c, checked in by Xi Ruoyao <xry111@…>, 12 months ago

efi/grub-setup: Missed version info update

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