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

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 xry111/llvm18 xry111/soup3 xry111/xf86-video-removal
Last change on this file since b38aed5 was b38aed5, checked in by Julien Lepiller <julien@…>, 20 months ago

Fix typos

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