source: chapter10/grub.xml@ c84ec38

Last change on this file since c84ec38 was c84ec38, checked in by Xi Ruoyao <xry111@…>, 9 months ago

arm64: grub cfg: adapt for minimal UEFI boot

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