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

11.0 11.1 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 upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since 6ca17c82 was 6ca17c82, checked in by Xi Ruoyao <xry111@…>, 3 years ago

grub efi setup: fsck order of efivarfs should be 0

It does not make any sense to fsck a pseudo filesystem.

  • Property mode set to 100644
File size: 15.0 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 parition
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.36.2).
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>Selected partition 1
71Hex code or alias (type L to list all): </literal><userinput>ef</userinput>
72<literal>Changed type of partition 'Linux' to 'EFI (FAT-12/16/32)'.
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]
121Firmware Drivers ---&gt;
122 EFI (Extensible Firmware Interface) Support ---&gt;
123 &lt; &gt; EFI Variable Support via sysfs [CONFIG_EFI_VARS]
124 [*] Export efi runtime maps to sysfs [CONFIG_EFI_RUNTIME_MAP]
125Enable the block layer ---&gt;
126 Partition Types ---&gt;
127 [*] Advanced partition selection [CONFIG_PARTITION_ADVANCED]
128 [*] EFI GUID Partition support [CONFIG_EFI_PARTITION]
129Device Drivers ---&gt;
130 Graphics support ---&gt;
131 Frame buffer Devices ---&gt;
132 Support for frame buffer devices ---&gt; [CONFIG_FB]
133 [*] EFI-based Framebuffer support [CONFIG_FB_EFI]
134 Console display driver support ---&gt;
135 [*] Framebuffer Console support [CONFIG_FRAMEBUFFER_CONSOLE]
136File systems ---&gt;
137 Pseudo filesystems ---&gt;
138 &lt;*/M&gt; EFI Variable filesystem [CONFIG_EFIVAR_FS]</literal></screen>
139
140 <variablelist>
141 <title>The meaning of the configure options:</title>
142
143 <varlistentry>
144 <term><parameter>CONFIG_EFI_STUB</parameter></term>
145 <listitem>
146 <para>Although the EFI stub is designed to boot a kernel directly from
147 the UEFI firmware (without a bootloader like GRUB), GRUB needs the
148 kernel to be loaded to support the EFI handover protocol enabled by
149 this option.</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><parameter>CONFIG_FB_EFI</parameter> and <parameter>CONFIG_FRAMEBUFFER_CONSOLE</parameter></term>
164 <listitem>
165 <para>The combination of these two options allows the kernel to
166 print debug messages (along with Tux logos) at the early stage of
167 the boot process with UEFI.</para>
168 </listitem>
169 </varlistentry>
170
171 </variablelist>
172
173 </sect2>
174
175 <sect2>
176 <title>Find or Create the EFI System Partition</title>
177
178 <para>
179 On EFI based system, the bootloaders are installed in a special FAT32
180 partition called an <emphasis>EFI System Partition</emphasis> (ESP).
181 If your system supports EFI, and a recent version of Linux
182 distribution or Windows is pre-installed, it's likely that the ESP
183 is already created. As the
184 <systemitem class="username">root</systemitem> user, list all the
185 partitions on your hard drive (replace <userinput>sda</userinput>
186 with the device corresponding to the appropriate hard drive):
187 </para>
188
189 <screen role="nodump"><userinput>fdisk -l /dev/sda</userinput></screen>
190
191 <para>
192 The <quote>Type</quote> column of the ESP should be
193 <literal>EFI System</literal>.
194 </para>
195
196 <para>
197 If the system or the hard drive is new, or it's a first time
198 install an UEFI booted OS on the system, the ESP may not exist.
199 In that case, create a new partition, make a
200 <systemitem class="filesystem">vfat</systemitem> file system on it,
201 and set the partition type to <quote>EFI system</quote>. See the
202 instructions for the emergency boot device above as a reference.
203 </para>
204
205 <warning>
206 <para>
207 Some (old) UEFI implementations may demand the ESP to be the first
208 partition on the disk.
209 </para>
210 </warning>
211
212 <para>
213 Now, as the <systemitem class="username">root</systemitem> user,
214 create the mount point for the ESP, and mount it (replace
215 <userinput>sda1</userinput> with the device node corresponding to
216 the ESP):
217 </para>
218
219<screen role="nodump"><userinput>mkdir -pv /boot/efi &amp;&amp;
220mount -v -t vfat /dev/sda1 /boot/efi</userinput></screen>
221
222 <para>
223 Add an entry for the ESP in
224 <filename>/etc/fstab</filename>, so it will be mounted automatically
225 during system boot:
226 </para>
227
228<screen role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
229<literal>/dev/sda1 /boot/efi vfat defaults 0 1</literal>
230<userinput>EOF</userinput></screen>
231
232 </sect2>
233
234 <sect2>
235 <title>Mount the EFI Variable File System</title>
236
237 <para>
238 The installation of GRUB on a UEFI platform requires that the EFI Variable
239 file system, <systemitem class="filesystem">efivarfs</systemitem>, to be
240 mounted. As the <systemitem class="username">root</systemitem> user,
241 mount it if it's not already mounted:
242 </para>
243
244<screen role="nodump"><userinput>mountpoint /sys/firmware/efi/efivars || mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars</userinput></screen>
245
246 <note revision="systemd">
247 <para>
248 If the system is booted with UEFI and systemd,
249 <systemitem class="filesystem">efivarfs</systemitem> will be mounted
250 automatically. However in the LFS chroot environment it still needs to
251 be mounted manually.
252 </para>
253 </note>
254
255 <para revision="sysv">
256 Now add an entry for the
257 <systemitem class="filesystem">efivarfs</systemitem> in
258 <filename>/etc/fstab</filename> so it will be mounted automatically
259 during system boot:
260 </para>
261
262<screen revision="sysv" role="nodump"><userinput>cat &gt;&gt; /etc/fstab &lt;&lt; EOF</userinput>
263<literal>efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 0</literal>
264<userinput>EOF</userinput></screen>
265
266 <warning>
267 <para>
268 If the system is not booted with UEFI, the directory
269 <filename class="directory">/sys/firmware/efi</filename> will be
270 missing. In this case you should boot the system in UEFI mode with
271 the emergency boot disk created as above.
272 </para>
273 </warning>
274 </sect2>
275
276 <sect2>
277 <title>Setting Up the Configuration</title>
278
279 <para>
280 On UEFI based systems, GRUB works by installing an EFI application
281 (a special kind of executable) into
282 <filename class="directory">/boot/efi/EFI/[id]/grubx64.efi</filename>,
283 where <filename class="directory">/boot/efi</filename> is the mount
284 point of the ESP, and <literal>[id]</literal> is replaced with an
285 identifier specified in the <command>grub-install</command> command
286 line. GRUB will create an entry in the EFI variables containing
287 the path <literal>EFI/[id]/grubx64.efi</literal> so the EFI firmware
288 can find <filename>grubx64.efi</filename> and load it.
289 </para>
290
291 <para>
292 <filename>grubx64.efi</filename> is very lightweight (136 KB with
293 GRUB-2.06~rc1) so it will not use much space in the ESP. A typical ESP
294 size is 100 MB (for Windows boot manager, which uses about 50 MB in
295 the ESP). Once <filename>grubx64.efi</filename> loaded by the
296 firmware, it will load GRUB modules in the boot partition.
297 The default location is
298 <filename class="directory">/boot/grub</filename>.
299 </para>
300
301 <para>
302 As the <systemitem class="username">root</systemitem> user, install
303 the GRUB files into <filename>/boot/efi/EFI/LFS/grubx64.efi</filename>
304 and <filename class="directory">/boot/grub</filename>. Then set up the
305 boot entry in the EFI variables:
306 </para>
307
308<screen role="nodump"><userinput>grub-install --bootloader-id=LFS --recheck</userinput></screen>
309
310 <para>
311 If the installation is successful, the output should be:
312 </para>
313
314<screen role="nodump"><literal>Installing for x86_64-efi platform.
315Installation finished. No error reported.</literal></screen>
316
317 <para>
318 Issue <command>efibootmgr</command> to recheck the EFI boot
319 configuration. An example of the output is:
320 </para>
321
322<screen role="nodump"><literal>BootCurrent: 0000
323Timeout: 1 seconds
324BootOrder: 0005,0000,0002,0001,0003,0004
325Boot0000* ARCH
326Boot0001* UEFI:CD/DVD Drive
327Boot0002* Windows Boot Manager
328Boot0003* UEFI:Removable Device
329Boot0004* UEFI:Network Device
330Boot0005* LFS</literal></screen>
331
332 <para>
333 Note that <literal>0005</literal> is the first in the
334 <literal>BootOrder</literal>, and <literal>Boot0005</literal>
335 is <literal>LFS</literal>. This means that on the next boot, the
336 version of GRUB installed by LFS will be used to boot the system.
337 </para>
338
339 </sect2>
340
341 <sect2>
342 <title>Creating the GRUB Configuration File</title>
343
344 <indexterm zone="grub-setup grub-video">
345 <primary sortas="e-boot-grub-grub-cfg">/boot/grub/grub.cfg</primary>
346 </indexterm>
347
348 <para>
349 Generate <filename>/boot/grub/grub.cfg</filename> to configure the
350 boot menu of GRUB:
351 </para>
352
353<screen role="nodump"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
354<literal># Begin /boot/grub/grub.cfg
355set default=0
356set timeout=5
357
358insmod part_gpt
359insmod ext2
360set root=(hd0,2)
361
362if loadfont /boot/grub/fonts/unicode.pf2; then
363 set gfxmode=auto
364 insmod all_video
365 terminal_output gfxterm
366fi
367
368menuentry "GNU/Linux, Linux 5.10.17-lfs-10.1" {
369 linux /boot/vmlinuz-5.10.17-lfs-10.1 root=/dev/sda2 ro
370}
371
372menuentry "Firmware Setup" {
373 fwsetup
374}</literal>
375<userinput>EOF</userinput></screen>
376
377 <para>
378 <literal>(hd0,2)</literal>, <literal>sda2</literal>, and
379 <literal>5.10.17-lfs-10.1</literal> should be replaced to match your
380 configuration.
381 </para>
382
383 <note>
384 <para>
385 From GRUB's perspective, the files are relative to the partition
386 are used. If you used a separate /boot partition, remove /boot from the
387 above paths (to kernel and to <filename>unicode.pf2</filename>). You
388 will also need to change the set root line to point to the boot
389 partition.
390 </para>
391 </note>
392
393 <para>
394 The <literal>Firmware Setup</literal> entry can be used to enter the
395 configuration interface provided by the firmware (sometimes called
396 <quote>BIOS configuration</quote>).
397 </para>
398 </sect2>
399
400 <sect2>
401 <title>Dual-booting with Windows</title>
402
403 <para>
404 Add a menu entry for Windows into <filename>grub.cfg</filename>:
405 </para>
406
407<screen role="nodump"><userinput>cat &gt;&gt; /boot/grub/grub.cfg &lt;&lt; EOF</userinput>
408<literal># Begin Windows addition
409
410menuentry "Windows 10" {
411 insmod fat
412 insmod chain
413 set root=(hd0,1)
414 chainloader /EFI/Microsoft/Boot/bootmgfw.efi
415}</literal>
416<userinput>EOF</userinput></screen>
417
418 <para>
419 <literal>(hd0,1)</literal> should be replaced with the GRUB
420 designated name for the ESP. The <literal>chainloader</literal>
421 directive can be used to tell GRUB to run another EFI executable,
422 in this case the Windows Boot Manager. You may put more usable tools
423 in EFI executable format (for example, an EFI shell) into the ESP and
424 create GRUB entries for them.
425 </para>
426
427 </sect2>
428
429</sect1>
Note: See TracBrowser for help on using the repository browser.