source: chapter10/grub.xml@ 985d253

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

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

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