source: chapter10/grub.xml@ 73d91ac

xry111/arm64
Last change on this file since 73d91ac was 64e8131, checked in by Xi Ruoyao <xry111@…>, 11 months ago

Merge remote-tracking branch 'origin/trunk' into xry111/arm64

  • Property mode set to 100644
File size: 13.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="ch-bootable-grub" role="wrap">
9 <?dbhtml filename="grub.html"?>
10
11 <sect1info condition="script">
12 <productname>grub</productname>
13 <productnumber>&grub-version;</productnumber>
14 <address>&grub-url;</address>
15 </sect1info>
16
17 <title>Using GRUB to Set Up the Boot Process</title>
18
19 <note>
20 <para>
21 This section assume your system has UEFI support and you wish to boot
22 LFS with UEFI and GRUB built following the instructions in Chapter 8.
23 </para>
24 <para>
25 If you've installed GRUB for UEFI with optional dependencies following
26 BLFS, you should skip the instructions in this page but still learn the
27 syntax of <filename>grub.cfg</filename> and the method to specify
28 a partition in the file from this page, and configure GRUB with UEFI
29 using the instructions provided in
30 <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS page</ulink>,
31 but replace <parameter>--target=x86_64-efi</parameter> with
32 <parameter>--target=arm64-efi</parameter> for the ARM64 system.
33 </para>
34 <para>
35 If your system does not support UEFI or you don't want to use it,
36 you'll need to figure out how to configure the booting process of
37 the system on your own.
38 </para>
39 </note>
40
41 <sect2>
42 <title>Introduction</title>
43
44 <warning><para>Configuring GRUB incorrectly can render your system
45 inoperable without an alternate boot device such as a CD-ROM or bootable
46 USB drive. This section is not required to boot your LFS system. You may
47 just want to modify your current boot loader, e.g. Grub-Legacy, GRUB2, or
48 LILO.</para></warning>
49
50 <para>Ensure that an emergency boot disk is ready to <quote>rescue</quote>
51 the computer if the computer becomes unusable (un-bootable). If you do not
52 already have a boot device, you can create one. To create a emergency
53 boot device for UEFI, consult section <quote>Create an Emergency Boot
54 Disk</quote> in
55 <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS page</ulink>.</para>
56
57 </sect2>
58
59 <sect2>
60 <title>Turn off Secure Boot</title>
61
62 <para>LFS does not have the essential packages to support Secure Boot.
63 To set up the boot process following the instructions in this section,
64 Secure Boot must be turned off from the configuration interface of the
65 firmware. Read the documentation provided by the manufacturer of your
66 system to find out how.</para>
67 </sect2>
68
69 <sect2>
70 <title>GRUB Naming Conventions</title>
71
72 <para>GRUB uses its own naming structure for drives and partitions in
73 the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
74 is the hard drive number and <emphasis>m</emphasis> is the partition
75 number. The hard drive numbers start from zero, but the partition numbers
76 start from one for normal partitions (from five for extended partitions).
77 Note that this is different from earlier versions where
78 both numbers started from zero. For example, partition <filename
79 class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
80 GRUB and <filename class="partition">sdb3</filename> is
81 <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
82 consider CD-ROM drives to be hard drives. For example, if using a CD
83 on <filename class="partition">hdb</filename> and a second hard drive
84 on <filename class="partition">hdc</filename>, that second hard drive
85 would still be <emphasis>(hd1)</emphasis>.</para>
86
87 </sect2>
88
89 <sect2>
90 <title>Setting Up the Configuration</title>
91
92 <para>GRUB works by creating an EFI executable in the EFI System
93 Partition (ESP). You can find the ESP with:</para>
94
95<screen role="nodump"><userinput>fdisk -l | grep 'EFI System'</userinput></screen>
96
97 <para>If no ESP exists on your hard drive (for example, you are building
98 LFS on a fresh new system with a Live CD as the host distro), read
99 <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS page</ulink>
100 for the instruction to create an ESP on your hard drive.</para>
101
102 <para>If the ESP is not mounted at
103 <filename class="directory">/boot/efi</filename> (in the chroot),
104 mount it now:</para>
105
106<screen role="nodump"><userinput>mkdir -pv /boot/efi
107mount /boot/efi</userinput></screen>
108
109 <note>
110 <para>The path to the device node is intentionally omitted in the
111 command. We expect the entry for mounting the ESP to
112 <filename class="directory">/boot/efi</filename> is already in
113 <filename>/etc/fstab</filename>. Add the entry before running the
114 command if you forgot to create an entry for the ESP in
115 <xref linkend="ch-bootable-fstab"/>.</para>
116 </note>
117
118 <para>The location of the boot partition is a choice of the user that
119 affects the configuration. One recommendation is to have a separate small
120 (suggested size is 200 MB) partition just for boot information. That way
121 each build, whether LFS or some commercial distro, can access the same boot
122 files and access can be made from any booted system. If you choose to do
123 this, you will need to mount the separate partition, move all files in the
124 current <filename class="directory">/boot</filename> directory (e.g. the
125 Linux kernel you just built in the previous section) to the new partition.
126 You will then need to unmount the partition and remount it as <filename
127 class="directory">/boot</filename>. If you do this, be sure to update
128 <filename>/etc/fstab</filename>.</para>
129
130 <para>Leaving <filename class="directory">/boot</filename> on
131 the current LFS partition will also work, but configuration
132 for multiple systems is more difficult.</para>
133
134 <para>Using the above information, determine the appropriate
135 designator for the root partition (or boot partition, if a separate
136 one is used). For the following example, it is assumed that the root
137 (or separate boot) partition is <filename
138 class="partition">sda2</filename>.</para>
139
140 <para>Install the GRUB files into <filename
141 class="directory">/boot/grub</filename> and the GRUB EFI executable into
142 <filename class="directory">/boot/efi/EFI/BOOT/BOOTAA64.EFI</filename>:</para>
143
144 <warning>
145 <para>The following command will overwrite
146 <filename>BOOTAA64.EFI</filename>. Do not run the command if this is
147 not desired, for example, if it contains a third party boot manager.
148 You can backup it with <command>cp</command> as it's a regular
149 file.</para>
150 </warning>
151
152<screen role="nodump"><userinput>grub-install --removable</userinput></screen>
153
154 <note>
155 <para>
156 <parameter>--removable</parameter> may seem strange here. The UEFI
157 firmware searches EFI executables for boot loaders in a hardcoded
158 path, <filename>EFI/BOOT/BOOTAA64.EFI</filename> in the ESP, and other
159 boot loader paths listed in the EFI variables. We've not installed
160 the utilities for manipulating EFI variables so we need to install
161 the EFI executable into the hardcoded path. The hardcoded path is
162 usually used by removable devices (for example, USB thumb devices)
163 so the <command>grub-install</command> option for this purpose is
164 named <parameter>--removable</parameter>.
165 </para>
166 <para>
167 UEFI implementation usually prefers the boot loaders with paths
168 recorded in an EFI variable, to the boot loader with the hardcoded
169 search path. You may need to invoke the boot device selection menu
170 or setting interface of your EFI firmware on next boot to explicitly
171 select the bootloader.
172 </para>
173 <para>
174 Some UEFI implementation may completely skip the hardcoded path if
175 there are other boot loaders in the same hard drive with paths
176 recorded in an EFI variable. Then you need to create an EFI
177 variable for the newly installed boot loader. Install
178 <ulink url="&blfs-book;postlfs/efibootmgr.html">efibootmgr</ulink>,
179 then run the following commands:
180
181<screen role="nodump"><userinput>mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars
182efibootmgr -B -L LFS || true
183efibootmgr -c -L LFS -l '\EFI\BOOT\BOOTAA64.EFI' -d /dev/sda
184umount /sys/firmware/efi/efivars</userinput></screen>
185
186 Replace <filename>/dev/sda</filename> with the device node of the
187 hard drive where you are installing GRUB into. For some UEFI
188 firmwares, <option>-e 3</option> option may be needed for the
189 <command>efibootmgr -c</command> command.
190 </para>
191 </note>
192
193<!-- This does not seem to be true any more
194 <note><para><application>grub-install</application> is a script and calls another
195 program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
196 If so, create a temporary symbolic link from your root partition to /dev/root:</para>
197
198<screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
199
200 <para>The symbolic link will only be present until the system is rebooted.
201 The link is only needed for the installation procedure.
202 </para></note>
203-->
204 </sect2>
205
206 <sect2 id="grub-cfg">
207 <title>Creating the GRUB Configuration File</title>
208
209 <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
210
211 <screen><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
212<literal># Begin /boot/grub/grub.cfg
213set default=0
214set timeout=5
215
216insmod part_gpt
217insmod ext2
218set root=(hd0,2)
219
220insmod all_video
221
222menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
223 linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
224}</literal>
225EOF</userinput></screen>
226
227 <para>
228 The <command>insmod</command> commands load the
229 <application>GRUB</application> modules named
230 <filename>part_gpt</filename> and <filename>ext2</filename>.
231 Despite the naming, <filename>ext2</filename> actually supports
232 <systemitem class='filesystem'>ext2</systemitem>,
233 <systemitem class='filesystem'>ext3</systemitem>, and
234 <systemitem class='filesystem'>ext4</systemitem> filesystems.
235 The <command>grub-install</command> command has embedded some modules
236 into the main <application>GRUB</application> image (installed into
237 the MBR or the GRUB BIOS partition) to access the other modules
238 (in <filename class='directory'>/boot/grub/i386-pc</filename>) without
239 a chicken-or-egg issue, so with a typical configuration these two
240 modules are already embedded and those two <command>insmod</command>
241 commands will do nothing. But they do no harm anyway, and they may
242 be needed with some rare configurations.
243 </para>
244
245 <note><para>From <application>GRUB</application>'s perspective, the
246 kernel files are relative to the partition used. If you
247 used a separate /boot partition, remove /boot from the above
248 <emphasis>linux</emphasis> line. You will also need to change the
249 <emphasis>set root</emphasis> line to point to the boot partition.
250 </para></note>
251
252 <note>
253 <para>The GRUB designator for a partition may change if you added or
254 removed some disks (including removable disks like USB thumb devices).
255 The change may cause boot failure because
256 <filename>grub.cfg</filename> refers to some <quote>old</quote>
257 designators. If you wish to avoid such a problem, you may use
258 the UUID of a partition and the UUID of a filesystem instead of a GRUB designator to
259 specify a device.
260 Run <command>lsblk -o UUID,PARTUUID,PATH,MOUNTPOINT</command> to show
261 the UUIDs of your filesystems (in the <literal>UUID</literal> column) and
262 partitions (in the <literal>PARTUUID</literal> column). Then replace
263 <literal>set root=(hdx,y)</literal> with
264 <literal>search --set=root --fs-uuid <replaceable>&lt;UUID of the filesystem
265 where the kernel is installed&gt;</replaceable></literal>, and replace
266 <literal>root=/dev/sda2</literal> with
267 <literal>root=PARTUUID=<replaceable>&lt;UUID of the partition where LFS
268 is built&gt;</replaceable></literal>.</para>
269 <para>Note that the UUID of a partition is completely different from the
270 UUID of the filesystem in this partition. Some online resources may
271 instruct you to use
272 <literal>root=UUID=<replaceable>&lt;filesystem UUID&gt;</replaceable></literal>
273 instead of
274 <literal>root=PARTUUID=<replaceable>&lt;partition UUID&gt;</replaceable></literal>,
275 but doing so will require an initramfs, which is beyond the scope of
276 LFS.</para>
277 <para>The name of the device node for a partition in
278 <filename class='directory'>/dev</filename> may also change (this is less
279 likely than a GRUB designator change). You can also replace
280 paths to device nodes like <literal>/dev/sda1</literal> with
281 <literal>PARTUUID=<replaceable>&lt;partition UUID&gt;</replaceable></literal>,
282 in <filename>/etc/fstab</filename>, to avoid a potential boot failure
283 in case the device node name has changed.</para>
284 </note>
285
286 <para>GRUB is an extremely powerful program and it provides a tremendous
287 number of options for booting from a wide variety of devices, operating
288 systems, and partition types. There are also many options for customization
289 such as graphical splash screens, playing sounds, mouse input, etc. The
290 details of these options are beyond the scope of this introduction.</para>
291
292 <caution><para>There is a command, <application>grub-mkconfig</application>, that
293 can write a configuration file automatically. It uses a set of scripts in
294 /etc/grub.d/ and will destroy any customizations that you make. These scripts
295 are designed primarily for non-source distributions and are not recommended for
296 LFS. If you install a commercial Linux distribution, there is a good chance
297 that this program will be run. Be sure to back up your grub.cfg file.</para></caution>
298
299 </sect2>
300
301</sect1>
Note: See TracBrowser for help on using the repository browser.