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

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 df373d2 was aebcd92c, checked in by Xi Ruoyao <xry111@…>, 2 years ago

update to efibootmgr-18

Add "| cut -f 1" to efibootmgr command for checking the configuration,
so long boring paths will not show up.

Update unifont version, and kernel version (in example) by the way.

  • Property mode set to 100644
File size: 15.6 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 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>
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.37.4).
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 --removable --efi-directory=/mnt/rescue --boot-directory=/mnt/rescue/grub</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 a emergency boot disk on 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 systems on 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 [*] Export efi runtime maps to sysfs [CONFIG_EFI_RUNTIME_MAP]
131 Graphics support ---&gt;
132 &lt;*&gt; Direct Rendering Manager [CONFIG_DRM]
133 &lt;*&gt; Simple framebuffer driver [CONFIG_SIMPLEDRM]
134 Frame buffer Devices ---&gt;
135 &lt;*&gt; Support for frame buffer devices ---&gt; [CONFIG_FB]
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>
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
151 this option.</para>
152 </listitem>
153 </varlistentry>
154
155 <varlistentry>
156 <term><parameter>CONFIG_EFI_VARS</parameter></term>
157 <listitem>
158 <para>Don't use this deprecated option because of a 1024-byte
159 variable size limit. Its function is replaced by
160 <parameter>CONFIG_EFIVAR_FS</parameter>.</para>
161 </listitem>
162 </varlistentry>
163
164 <varlistentry>
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>
171 <listitem>
172 <para>The combination of these options allows the kernel to
173 print debug messages (along with Tux logos) at the early stage of
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>
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
189 partition called an <emphasis>EFI System Partition</emphasis> (ESP).
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>
195 with the device corresponding to the appropriate hard drive):
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>
206 If the system or the hard drive is new, or it's a first time
207 install an UEFI booted OS on the system, the ESP may not exist.
208 In that case, create a new partition, make a
209 <systemitem class="filesystem">vfat</systemitem> file system on it,
210 and set the partition type to <quote>EFI system</quote>. See the
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>
232 Add an entry for the ESP in
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
243 <sect2>
244 <title>Mount the EFI Variable File System</title>
245
246 <para>
247 The installation of GRUB on a UEFI platform requires that the EFI Variable
248 file system, <systemitem class="filesystem">efivarfs</systemitem>, to be
249 mounted. As the <systemitem class="username">root</systemitem> user,
250 mount it if it's not already mounted:
251 </para>
252
253<screen role="nodump"><userinput>mountpoint /sys/firmware/efi/efivars || mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars</userinput></screen>
254
255 <note revision="systemd">
256 <para>
257 If the system is booted with UEFI and systemd,
258 <systemitem class="filesystem">efivarfs</systemitem> will be mounted
259 automatically. However in the LFS chroot environment it still needs to
260 be mounted manually.
261 </para>
262 </note>
263
264 <para revision="sysv">
265 Now add an entry for the
266 <systemitem class="filesystem">efivarfs</systemitem> in
267 <filename>/etc/fstab</filename> so it will be mounted automatically
268 during system boot:
269 </para>
270
271<screen revision="sysv" role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
272<literal>efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 0</literal>
273<userinput>EOF</userinput></screen>
274
275 <warning>
276 <para>
277 If the system is not booted with UEFI, the directory
278 <filename class="directory">/sys/firmware/efi</filename> will be
279 missing. In this case you should boot the system in UEFI mode with
280 the emergency boot disk created as above.
281 </para>
282 </warning>
283 </sect2>
284
285 <sect2>
286 <title>Setting Up the Configuration</title>
287
288 <para>
289 On UEFI based systems, GRUB works by installing an EFI application
290 (a special kind of executable) into
291 <filename class="directory">/boot/efi/EFI/[id]/grubx64.efi</filename>,
292 where <filename class="directory">/boot/efi</filename> is the mount
293 point of the ESP, and <literal>[id]</literal> is replaced with an
294 identifier specified in the <command>grub-install</command> command
295 line. GRUB will create an entry in the EFI variables containing
296 the path <literal>EFI/[id]/grubx64.efi</literal> so the EFI firmware
297 can find <filename>grubx64.efi</filename> and load it.
298 </para>
299
300 <para>
301 <filename>grubx64.efi</filename> is very lightweight (136 KB with
302 GRUB-2.06~rc1) so it will not use much space in the ESP. A typical ESP
303 size is 100 MB (for Windows boot manager, which uses about 50 MB in
304 the ESP). Once <filename>grubx64.efi</filename> loaded by the
305 firmware, it will load GRUB modules in the boot partition.
306 The default location is
307 <filename class="directory">/boot/grub</filename>.
308 </para>
309
310 <para>
311 As the <systemitem class="username">root</systemitem> user, install
312 the GRUB files into <filename>/boot/efi/EFI/LFS/grubx64.efi</filename>
313 and <filename class="directory">/boot/grub</filename>. Then set up the
314 boot entry in the EFI variables:
315 </para>
316
317<screen role="nodump"><userinput>grub-install --bootloader-id=LFS --recheck</userinput></screen>
318
319 <para>
320 If the installation is successful, the output should be:
321 </para>
322
323<screen role="nodump"><literal>Installing for x86_64-efi platform.
324Installation finished. No error reported.</literal></screen>
325
326 <para>
327 Issue <command>efibootmgr | cut -f 1</command> to recheck the EFI boot
328 configuration. An example of the output is:
329 </para>
330
331<screen role="nodump"><literal>BootCurrent: 0000
332Timeout: 1 seconds
333BootOrder: 0005,0000,0002,0001,0003,0004
334Boot0000* ARCH
335Boot0001* UEFI:CD/DVD Drive
336Boot0002* Windows Boot Manager
337Boot0003* UEFI:Removable Device
338Boot0004* UEFI:Network Device
339Boot0005* LFS</literal></screen>
340
341 <para>
342 Note that <literal>0005</literal> is the first in the
343 <literal>BootOrder</literal>, and <literal>Boot0005</literal>
344 is <literal>LFS</literal>. This means that on the next boot, the
345 version of GRUB installed by LFS will be used to boot the system.
346 </para>
347
348 </sect2>
349
350 <sect2>
351 <title>Creating the GRUB Configuration File</title>
352
353 <indexterm zone="grub-setup grub-video">
354 <primary sortas="e-boot-grub-grub-cfg">/boot/grub/grub.cfg</primary>
355 </indexterm>
356
357 <para>
358 Generate <filename>/boot/grub/grub.cfg</filename> to configure the
359 boot menu of GRUB:
360 </para>
361
362<screen role="nodump"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
363<literal># Begin /boot/grub/grub.cfg
364set default=0
365set timeout=5
366
367insmod part_gpt
368insmod ext2
369set root=(hd0,2)
370
371if loadfont /boot/grub/fonts/unicode.pf2; then
372 set gfxmode=auto
373 insmod all_video
374 terminal_output gfxterm
375fi
376
377menuentry "GNU/Linux, Linux 5.18.8-lfs-r11.1-147" {
378 linux /boot/vmlinuz-5.18.8-lfs-r11.1-147 root=/dev/sda2 ro
379}
380
381menuentry "Firmware Setup" {
382 fwsetup
383}</literal>
384<userinput>EOF</userinput></screen>
385
386 <para>
387 <literal>(hd0,2)</literal>, <literal>sda2</literal>, and
388 <literal>5.18.8-lfs-r11.1-147</literal> should be replaced to match your
389 configuration.
390 </para>
391
392 <note>
393 <para>
394 From GRUB's perspective, the files are relative to the partition
395 are used. If you used a separate /boot partition, remove /boot from the
396 above paths (to kernel and to <filename>unicode.pf2</filename>). You
397 will also need to change the set root line to point to the boot
398 partition.
399 </para>
400 </note>
401
402 <para>
403 The <literal>Firmware Setup</literal> entry can be used to enter the
404 configuration interface provided by the firmware (sometimes called
405 <quote>BIOS configuration</quote>).
406 </para>
407 </sect2>
408
409 <sect2>
410 <title>Dual-booting with Windows</title>
411
412 <para>
413 Add a menu entry for Windows into <filename>grub.cfg</filename>:
414 </para>
415
416<screen role="nodump"><userinput>cat &gt;&gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
417<literal># Begin Windows addition
418
419menuentry "Windows 10" {
420 insmod fat
421 insmod chain
422 set root=(hd0,1)
423 chainloader /EFI/Microsoft/Boot/bootmgfw.efi
424}</literal>
425<userinput>EOF</userinput></screen>
426
427 <para>
428 <literal>(hd0,1)</literal> should be replaced with the GRUB
429 designated name for the ESP. The <literal>chainloader</literal>
430 directive can be used to tell GRUB to run another EFI executable,
431 in this case the Windows Boot Manager. You may put more usable tools
432 in EFI executable format (for example, an EFI shell) into the ESP and
433 create GRUB entries for them.
434 </para>
435
436 </sect2>
437
438</sect1>
Note: See TracBrowser for help on using the repository browser.