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