source: chapter10/grub.xml@ 9e76c64

xry111/clfs-ng
Last change on this file since 9e76c64 was 9e76c64, checked in by Xi Ruoyao <xry111@…>, 7 months ago

Merge remote-tracking branch 'origin/trunk' into xry111/clfs-ng

  • Property mode set to 100644
File size: 9.2 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 If your system has UEFI support and you wish to boot LFS with UEFI,
22 you should skip the instructions in this page but still learn the
23 syntax of <filename>grub.cfg</filename> and the method to specify
24 a partition in the file from this page, and configure GRUB with UEFI
25 support using the instructions provided in
26 <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS page</ulink>.
27 </para>
28 </note>
29
30 <sect2>
31 <title>Introduction</title>
32
33 <warning><para>Configuring GRUB incorrectly can render your system
34 inoperable without an alternate boot device such as a CD-ROM or bootable
35 USB drive. This section is not required to boot your LFS system. You may
36 just want to modify your current boot loader, e.g. Grub-Legacy, GRUB2, or
37 LILO.</para></warning>
38
39 <para> Ensure that an emergency boot disk is ready to <quote>rescue</quote>
40 the computer if the computer becomes unusable (un-bootable). If you do not
41 already have a boot device, you can create one. In order for the procedure
42 below to work, you need to jump ahead to BLFS and install
43 <userinput>xorriso</userinput> from the <ulink
44 url="&blfs-book;multimedia/libisoburn.html">
45 libisoburn</ulink> package.</para>
46
47<screen role="nodump"><userinput>cd /tmp
48grub-mkrescue --output=grub-img.iso
49xorriso -as cdrecord -v dev=/dev/cdrw blank=as_needed grub-img.iso</userinput></screen>
50
51 </sect2>
52
53 <sect2>
54 <title>GRUB Naming Conventions</title>
55
56 <para>GRUB uses its own naming structure for drives and partitions in
57 the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
58 is the hard drive number and <emphasis>m</emphasis> is the partition
59 number. The hard drive numbers start from zero, but the partition numbers
60 start from one for normal partitions (from five for extended partitions).
61 Note that this is different from earlier versions where
62 both numbers started from zero. For example, partition <filename
63 class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
64 GRUB and <filename class="partition">sdb3</filename> is
65 <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
66 consider CD-ROM drives to be hard drives. For example, if using a CD
67 on <filename class="partition">hdb</filename> and a second hard drive
68 on <filename class="partition">hdc</filename>, that second hard drive
69 would still be <emphasis>(hd1)</emphasis>.</para>
70
71 </sect2>
72
73 <sect2>
74 <title>Setting Up the Configuration</title>
75
76 <para>GRUB works by writing data to the first physical track of the
77 hard disk. This area is not part of any file system. The programs
78 there access GRUB modules in the boot partition. The default location
79 is /boot/grub/.</para>
80
81 <para>For the following example, it is assumed that the root
82 partition is <filename class="partition">sda3</filename>, and the
83 seperate boot partition is
84 <filename class="partition">sda2</filename>. Replace
85 <replaceable>sda</replaceable> to the name of the device node for your
86 disk where LFS is being built.</para>
87
88 <para>Install the GRUB files into <filename
89 class="directory">/boot/grub</filename> and set up the boot track:</para>
90
91 <warning>
92 <para>The following command will overwrite the current boot loader. Do not
93 run the command if this is not desired, for example, if using a third party
94 boot manager to manage the Master Boot Record (MBR).</para>
95 </warning>
96
97<screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
98
99 <note>
100 <para>If the system has been booted using UEFI,
101 <command>grub-install</command> will try to install files for the
102 <emphasis>x86_64-efi</emphasis> target, but those files
103 have not been installed in <xref linkend="chapter-building-system"/>.
104 If this is the case, add <option>--target i386-pc</option> to the
105 command above.</para>
106 </note>
107
108 </sect2>
109
110 <sect2 id="grub-cfg">
111 <title>Creating the GRUB Configuration File</title>
112
113 <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
114
115 <screen><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
116<literal># Begin /boot/grub/grub.cfg
117set default=0
118set timeout=5
119
120insmod part_gpt
121insmod ext2
122set root=(hd0,2)
123
124menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
125 linux /vmlinuz-&linux-version;-lfs-&version; root=/dev/sda3 ro
126}</literal>
127EOF</userinput></screen>
128
129 <para>
130 The <command>insmod</command> commands load the
131 <application>GRUB</application> modules named
132 <filename>part_gpt</filename> and <filename>ext2</filename>.
133 Despite the naming, <filename>ext2</filename> actually supports
134 <systemitem class='filesystem'>ext2</systemitem>,
135 <systemitem class='filesystem'>ext3</systemitem>, and
136 <systemitem class='filesystem'>ext4</systemitem> filesystems.
137 The <command>grub-install</command> command has embedded some modules
138 into the main <application>GRUB</application> image (installed into
139 the MBR or the GRUB BIOS partition) to access the other modules
140 (in <filename class='directory'>/boot/grub/i386-pc</filename>) without
141 a chicken-or-egg issue, so with a typical configuration these two
142 modules are already embedded and those two <command>insmod</command>
143 commands will do nothing. But they do no harm anyway, and they may
144 be needed with some rare configurations.
145 </para>
146
147 <note><para>From <application>GRUB</application>'s perspective, the
148 kernel files are relative to the partition used. If you
149 used a separate /boot partition, remove /boot from the above
150 <emphasis>linux</emphasis> line. You will also need to change the
151 <emphasis>set root</emphasis> line to point to the boot partition.
152 </para></note>
153
154 <note>
155 <para>The GRUB designator for a partition may change if you added or
156 removed some disks (including removable disks like USB thumb devices).
157 The change may cause boot failure because
158 <filename>grub.cfg</filename> refers to some <quote>old</quote>
159 designators. If you wish to avoid such a problem, you may use
160 the UUID of a partition and the UUID of a filesystem instead of a GRUB designator to
161 specify a device.
162 Run <command>lsblk -o UUID,PARTUUID,PATH,MOUNTPOINT</command> to show
163 the UUIDs of your filesystems (in the <literal>UUID</literal> column) and
164 partitions (in the <literal>PARTUUID</literal> column). Then replace
165 <literal>set root=(hdx,y)</literal> with
166 <literal>search --set=root --fs-uuid <replaceable>&lt;UUID of the filesystem
167 where the kernel is installed&gt;</replaceable></literal>, and replace
168 <literal>root=/dev/sda2</literal> with
169 <literal>root=PARTUUID=<replaceable>&lt;UUID of the partition where LFS
170 is built&gt;</replaceable></literal>.</para>
171 <para>Note that the UUID of a partition is completely different from the
172 UUID of the filesystem in this partition. Some online resources may
173 instruct you to use
174 <literal>root=UUID=<replaceable>&lt;filesystem UUID&gt;</replaceable></literal>
175 instead of
176 <literal>root=PARTUUID=<replaceable>&lt;partition UUID&gt;</replaceable></literal>,
177 but doing so will require an initramfs, which is beyond the scope of
178 LFS.</para>
179 <para>The name of the device node for a partition in
180 <filename class='directory'>/dev</filename> may also change (this is less
181 likely than a GRUB designator change). You can also replace
182 paths to device nodes like <literal>/dev/sda1</literal> with
183 <literal>PARTUUID=<replaceable>&lt;partition UUID&gt;</replaceable></literal>,
184 in <filename>/etc/fstab</filename>, to avoid a potential boot failure
185 in case the device node name has changed.</para>
186 </note>
187
188 <para>GRUB is an extremely powerful program and it provides a tremendous
189 number of options for booting from a wide variety of devices, operating
190 systems, and partition types. There are also many options for customization
191 such as graphical splash screens, playing sounds, mouse input, etc. The
192 details of these options are beyond the scope of this introduction.</para>
193
194 <caution><para>There is a command, <application>grub-mkconfig</application>, that
195 can write a configuration file automatically. It uses a set of scripts in
196 /etc/grub.d/ and will destroy any customizations that you make. These scripts
197 are designed primarily for non-source distributions and are not recommended for
198 LFS. If you install a commercial Linux distribution, there is a good chance
199 that this program will be run. Be sure to back up your grub.cfg file.</para></caution>
200
201 </sect2>
202
203</sect1>
Note: See TracBrowser for help on using the repository browser.