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

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 e2b07edd was c8391c3d, checked in by Pierre Labastie <pierre.labastie@…>, 2 years ago

Spelling and grammar fixes to grub-setup

From the file attached to
https://wiki.linuxfromscratch.org/blfs/ticket/17085
by D Bryant.

  • 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 <sect1info>
12 <date>$Date$</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 and UEFI 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 partition
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.38.1).
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>Partition number (1-9, default 9): </literal><userinput>1</userinput>
71<literal>Partition type or alias (type L to list all): </literal><userinput>uefi</userinput>
72<literal>Changed type of partition 'Linux filesystem' to 'EFI System'.
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 --target=x86_64-efi --removable --efi-directory=/mnt/rescue --boot-directory=/mnt/rescue</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 an emergency boot disk on any 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 system from 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]
121Enable the block layer ---&gt;
122 Partition Types ---&gt;
123 [*] Advanced partition selection [CONFIG_PARTITION_ADVANCED]
124 [*] EFI GUID Partition support [CONFIG_EFI_PARTITION]
125Device Drivers ---&gt;
126 Firmware Drivers ---&gt;
127 [*] Mark VGA/VBE/EFI FB as generic system framebuffer [CONFIG_SYSFB_SIMPLEFB]
128 EFI (Extensible Firmware Interface) Support ---&gt;
129 &lt; &gt; EFI Variable Support via sysfs [CONFIG_EFI_VARS]
130 Graphics support ---&gt;
131 &lt;*&gt; Direct Rendering Manager [CONFIG_DRM]
132 &lt;*&gt; Simple framebuffer driver [CONFIG_DRM_SIMPLEDRM]
133 Frame buffer Devices ---&gt;
134 &lt;*&gt; Support for frame buffer devices ---&gt; [CONFIG_FB]
135 Console display driver support ---&gt;
136 [*] Framebuffer Console support [CONFIG_FRAMEBUFFER_CONSOLE]
137File systems ---&gt;
138 &lt;DOS/FAT/EXFAT/NT Filesystems ---&gt;
139 &lt;*/M&gt; VFAT (Windows-95) fs support [CONFIG_VFAT_FS]
140 Pseudo filesystems ---&gt;
141 &lt;*/M&gt; EFI Variable filesystem [CONFIG_EFIVAR_FS]</literal></screen>
142
143 <variablelist>
144 <title>The meaning of the configuration options:</title>
145
146 <varlistentry>
147 <term><parameter>CONFIG_EFI_STUB</parameter></term>
148 <listitem>
149 <para>Although the EFI stub is designed to boot a kernel directly from
150 the UEFI firmware (without a bootloader like GRUB), GRUB needs the
151 kernel to be loaded to support the EFI handover protocol enabled by
152 this option.</para>
153 </listitem>
154 </varlistentry>
155
156 <varlistentry>
157 <term><parameter>CONFIG_EFI_VARS</parameter></term>
158 <listitem>
159 <para>Don't use this deprecated option because of a 1024-byte
160 variable size limit. Its function is replaced by
161 <parameter>CONFIG_EFIVAR_FS</parameter>.</para>
162 </listitem>
163 </varlistentry>
164
165 <varlistentry>
166 <term>
167 <parameter>CONFIG_SYSFB_SIMPLEFB</parameter>,
168 <parameter>CONFIG_DRM</parameter>,
169 <parameter>CONFIG_DRM_SIMPLEDRM</parameter>,
170 <parameter>CONFIG_FB</parameter>, and
171 <parameter>CONFIG_FRAMEBUFFER_CONSOLE</parameter></term>
172 <listitem>
173 <para>The combination of these options allows the kernel to
174 print debug messages (along with Tux logos) at an early stage of
175 the boot process with UEFI. To ensure they are functional at that early
176 stage, they shouldn't be built as kernel modules unless an
177 initramfs will be used.</para>
178 </listitem>
179 </varlistentry>
180
181 </variablelist>
182
183 </sect2>
184
185 <sect2>
186 <title>Find or Create the EFI System Partition</title>
187
188 <para>
189 On EFI based systems, the bootloaders are installed in a special FAT32
190 partition called an <emphasis>EFI System Partition</emphasis> (ESP).
191 If your system supports EFI, and a recent version of some Linux
192 distribution or Windows is pre-installed, it's likely that the ESP
193 has already been created. As the
194 <systemitem class="username">root</systemitem> user, list all the
195 partitions on your hard drive (replace <userinput>sda</userinput>
196 with the device corresponding to the appropriate hard drive):
197 </para>
198
199 <screen role="nodump"><userinput>fdisk -l /dev/sda</userinput></screen>
200
201 <para>
202 The <quote>Type</quote> column of the ESP should be
203 <literal>EFI System</literal>.
204 </para>
205
206 <para>
207 If the system or the hard drive is new, or it's the first
208 installation of a UEFI-booted OS on the system, the ESP may not exist.
209 In that case, create a new partition, make a
210 <systemitem class="filesystem">vfat</systemitem> file system on it,
211 and set the partition type to <quote>EFI system</quote>. See the
212 instructions for the emergency boot device above as a reference.
213 </para>
214
215 <warning>
216 <para>
217 Some (old) UEFI implementations may require the ESP to be the first
218 partition on the disk.
219 </para>
220 </warning>
221
222 <para>
223 Now, as the <systemitem class="username">root</systemitem> user,
224 create the mount point for the ESP, and mount it (replace
225 <userinput>sda1</userinput> with the device node corresponding to
226 the ESP):
227 </para>
228
229<screen role="nodump"><userinput>mkdir -pv /boot/efi &amp;&amp;
230mount -v -t vfat /dev/sda1 /boot/efi</userinput></screen>
231
232 <para>
233 Add an entry for the ESP in
234 <filename>/etc/fstab</filename>, so it will be mounted automatically
235 during system boot:
236 </para>
237
238<screen role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
239<literal>/dev/sda1 /boot/efi vfat defaults 0 1</literal>
240<userinput>EOF</userinput></screen>
241
242 </sect2>
243
244 <sect2>
245 <title>Minimal Boot Configuration with GRUB and EFI</title>
246
247 <para>
248 On UEFI based systems, GRUB works by installing an EFI application
249 (a special kind of executable) into the ESP. The EFI firmware will
250 search boot loaders in EFI applications from boot entries recorded
251 in EFI variables, and additionally a hardcoded path
252 <filename>EFI/BOOT/BOOTX64.EFI</filename>. Normally, a boot loader
253 should be installed into a custom path and the path should be recorded
254 in the EFI variables. The use of the hardcoded path should be
255 avoided if possible. However, in some cases we have to use
256 the hardcoded path:
257 </para>
258
259 <itemizedlist>
260 <listitem>
261 <para>
262 The system is not booted with EFI yet, making EFI variables
263 inaccessible.
264 </para>
265 </listitem>
266 <listitem>
267 <para>
268 The EFI firmware is 64-bit but the LFS system is 32-bit, making
269 EFI variables inaccessible because the kernel cannot invoke EFI
270 runtime services with a different virtual address length.
271 </para>
272 </listitem>
273 <listitem>
274 <para>
275 LFS is built for a Live USB, so we cannot rely on EFI variables,
276 which are stored in NVRAM or EEPROM on the local machine.
277 </para>
278 </listitem>
279 <listitem>
280 <para>
281 You are unable or unwilling to install the
282 <application>efibootmgr</application> for manipulating boot
283 entries in EFI variables.
284 </para>
285 </listitem>
286 </itemizedlist>
287
288 <para>
289 In these cases, follow these instructions to install the GRUB EFI
290 application into the hardcoded path and make a minimal boot
291 configuration. Otherwise it's better to skip ahead and set up the
292 boot configuration normally.
293 </para>
294
295 <para>
296 To install GRUB with the EFI application in the hardcoded
297 path <filename>EFI/BOOT/BOOTX64.EFI</filename>, first ensure the boot
298 partition is mounted at <filename class="directory">/boot</filename>
299 and the ESP is mounted at
300 <filename class="directory">/boot/efi</filename>. Then, as the &root;
301 user, run the command:
302 </para>
303
304 <note>
305 <para>
306 This command will overwrite
307 <filename>/boot/efi/EFI/BOOT/BOOTX64.EFI</filename>. It may break a
308 bootloader already installed there. Back it up if you are not sure.
309 </para>
310 </note>
311
312 <screen role="nodump"><userinput>grub-install --target=x86_64-efi --removable</userinput></screen>
313
314 <para>
315 This command will install the GRUB EFI application into the hardcoded path
316 <filename>/boot/efi/EFI/BOOT/BOOTX64.EFI</filename>, so the EFI
317 firmware can find and load it. The remaining GRUB files are installed
318 in the <filename class="directory">/boot/grub</filename> directory and
319 will be loaded by <filename>BOOTX64.EFI</filename> during system boot.
320 </para>
321
322 <note>
323 <para>
324 The EFI firmware usually prefers the EFI applications with a path
325 stored in EFI variables to the EFI
326 application at the hardcoded path. So you may need to invoke the
327 boot selection menu or firmware setting interface to select the
328 newly installed GRUB manually on the next boot. Read the manual of
329 your motherboard or laptop to learn how.
330 </para>
331 </note>
332
333 <para>
334 If you've followed the instructions in this section and set up a minimal boot
335 configuration, now skip ahead to
336 <quote>Creating the GRUB Configuration File</quote>.
337 </para>
338 </sect2>
339
340 <sect2>
341 <title>Mount the EFI Variable File System</title>
342
343 <para>
344 The installation of GRUB on a UEFI platform requires that the EFI Variable
345 file system, <systemitem class="filesystem">efivarfs</systemitem>, is
346 mounted. As the <systemitem class="username">root</systemitem> user,
347 mount it if it's not already mounted:
348 </para>
349
350<screen role="nodump"><userinput>mountpoint /sys/firmware/efi/efivars || mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars</userinput></screen>
351
352 <note revision="systemd">
353 <para>
354 If the system is booted with UEFI and systemd,
355 <systemitem class="filesystem">efivarfs</systemitem> will be mounted
356 automatically. However, in the LFS chroot environment it still needs to
357 be mounted manually.
358 </para>
359 </note>
360
361 <para revision="sysv">
362 Now add an entry for the
363 <systemitem class="filesystem">efivarfs</systemitem> in
364 <filename>/etc/fstab</filename> so it will be mounted automatically
365 during system boot:
366 </para>
367
368<screen revision="sysv" role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
369<literal>efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 0</literal>
370<userinput>EOF</userinput></screen>
371
372 <warning>
373 <para>
374 If the system is not booted with UEFI, the directory
375 <filename class="directory">/sys/firmware/efi</filename> will be
376 missing. In this case you should boot the system in UEFI mode with
377 the emergency boot disk or using a minimal boot configuration created as
378 above, then mount
379 <systemitem class="filesystem">efivarfs</systemitem> and continue.
380 </para>
381 </warning>
382 </sect2>
383
384 <sect2>
385 <title>Setting Up the Configuration</title>
386
387 <para>
388 On UEFI based systems, GRUB works by installing an EFI application
389 (a special kind of executable) into
390 <filename class="directory">/boot/efi/EFI/[id]/grubx64.efi</filename>,
391 where <filename class="directory">/boot/efi</filename> is the mount
392 point of the ESP, and <literal>[id]</literal> is replaced with an
393 identifier specified in the <command>grub-install</command> command
394 line. GRUB will create an entry in the EFI variables containing
395 the path <literal>EFI/[id]/grubx64.efi</literal> so the EFI firmware
396 can find <filename>grubx64.efi</filename> and load it.
397 </para>
398
399 <para>
400 <filename>grubx64.efi</filename> is very lightweight (136 KB with
401 GRUB-2.06) so it will not use much space in the ESP. A typical ESP
402 size is 100 MB (for Windows boot manager, which uses about 50 MB in
403 the ESP). Once <filename>grubx64.efi</filename> has been loaded by the
404 firmware, it will load GRUB modules from the boot partition.
405 The default location is
406 <filename class="directory">/boot/grub</filename>.
407 </para>
408
409 <para>
410 As the <systemitem class="username">root</systemitem> user, install
411 the GRUB files into <filename>/boot/efi/EFI/LFS/grubx64.efi</filename>
412 and <filename class="directory">/boot/grub</filename>. Then set up the
413 boot entry in the EFI variables:
414 </para>
415
416<screen role="nodump"><userinput>grub-install --bootloader-id=LFS --recheck</userinput></screen>
417
418 <para>
419 If the installation is successful, the output should be:
420 </para>
421
422<screen role="nodump"><literal>Installing for x86_64-efi platform.
423Installation finished. No error reported.</literal></screen>
424
425 <para>
426 Issue the <command>efibootmgr | cut -f 1</command> command to recheck the EFI boot
427 configuration. An example of the output is:
428 </para>
429
430<screen role="nodump"><literal>BootCurrent: 0000
431Timeout: 1 seconds
432BootOrder: 0005,0000,0002,0001,0003,0004
433Boot0000* ARCH
434Boot0001* UEFI:CD/DVD Drive
435Boot0002* Windows Boot Manager
436Boot0003* UEFI:Removable Device
437Boot0004* UEFI:Network Device
438Boot0005* LFS</literal></screen>
439
440 <para>
441 Note that <literal>0005</literal> is the first in the
442 <literal>BootOrder</literal>, and <literal>Boot0005</literal>
443 is <literal>LFS</literal>. This means that on the next boot, the
444 version of GRUB installed by LFS will be used to boot the system.
445 </para>
446
447 </sect2>
448
449 <sect2>
450 <title>Creating the GRUB Configuration File</title>
451
452 <indexterm zone="grub-setup grub-video">
453 <primary sortas="e-boot-grub-grub-cfg">/boot/grub/grub.cfg</primary>
454 </indexterm>
455
456 <para>
457 Generate <filename>/boot/grub/grub.cfg</filename> to configure the
458 boot menu of GRUB:
459 </para>
460
461<screen role="nodump"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
462<literal># Begin /boot/grub/grub.cfg
463set default=0
464set timeout=5
465
466insmod part_gpt
467insmod ext2
468set root=(hd0,2)
469
470if loadfont /boot/grub/fonts/unicode.pf2; then
471 set gfxmode=auto
472 insmod all_video
473 terminal_output gfxterm
474fi
475
476menuentry "GNU/Linux, Linux 5.19.2-lfs-11.2" {
477 linux /boot/vmlinuz-5.19.2-lfs-11.2 root=/dev/sda2 ro
478}
479
480menuentry "Firmware Setup" {
481 fwsetup
482}</literal>
483<userinput>EOF</userinput></screen>
484
485 <para>
486 <literal>(hd0,2)</literal>, <literal>sda2</literal>, and
487 <literal>5.19.2-lfs-11.2</literal> must match your
488 configuration.
489 </para>
490
491 <note>
492 <para>
493 From GRUB's perspective, the files are relative to the partitions
494 used. If you used a separate /boot partition, remove /boot from the
495 above paths (to kernel and to <filename>unicode.pf2</filename>). You
496 will also need to change the "set root" line to point to the boot
497 partition.
498 </para>
499 </note>
500
501 <para>
502 The <literal>Firmware Setup</literal> entry can be used to enter the
503 configuration interface provided by the firmware (sometimes called
504 <quote>BIOS configuration</quote>).
505 </para>
506 </sect2>
507
508 <sect2>
509 <title>Dual-booting with Windows</title>
510
511 <para>
512 Add a menu entry for Windows into <filename>grub.cfg</filename>:
513 </para>
514
515<screen role="nodump"><userinput>cat &gt;&gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
516<literal># Begin Windows addition
517
518menuentry "Windows 11" {
519 insmod fat
520 insmod chain
521 set root=(hd0,1)
522 chainloader /EFI/Microsoft/Boot/bootmgfw.efi
523}</literal>
524<userinput>EOF</userinput></screen>
525
526 <para>
527 <literal>(hd0,1)</literal> should be replaced with the GRUB
528 designated name for the ESP. The <literal>chainloader</literal>
529 directive can be used to tell GRUB to run another EFI executable,
530 in this case the Windows Boot Manager. You may put more usable tools
531 in EFI executable format (for example, an EFI shell) into the ESP and
532 create GRUB entries for them, as well.
533 </para>
534
535 </sect2>
536
537</sect1>
Note: See TracBrowser for help on using the repository browser.