source: chapter10/grub.xml@ 8f641ee

xry111/arm64 xry111/arm64-12.0
Last change on this file since 8f641ee was 8f641ee, checked in by Xi Ruoyao <xry111@…>, 19 months ago

arm64: grub cfg: add quote to avoid "escaping" Windoge-style loader path

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