source: chapter10/grub.xml@ b0b9db56

xry111/loongarch xry111/loongarch-12.1 xry111/loongarch-12.2
Last change on this file since b0b9db56 was 33a9421, checked in by Xi Ruoyao <xry111@…>, 8 months ago

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

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