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">
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>
17 <title>Using GRUB to Set Up the Boot Process</title>
20 <title>Introduction</title>
22 <warning><para>Configuring GRUB incorrectly can render your system
23 inoperable without an alternate boot device such as a CD-ROM or bootable
24 USB drive. This section is not required to boot your LFS system. You may
25 just want to modify your current boot loader, e.g. Grub-Legacy, GRUB2, or
26 LILO.</para></warning>
28 <para> Ensure that an emergency boot disk is ready to <quote>rescue</quote>
29 the computer if the computer becomes unusable (un-bootable). If you do not
30 already have a boot device, you can create one. In order for the procedure
31 below to work, you need to jump ahead to BLFS and install
32 <userinput>xorriso</userinput> from the <ulink
33 url="&blfs-book;multimedia/libisoburn.html">
34 libisoburn</ulink> package.</para>
36 <screen role="nodump"><userinput>cd /tmp
37 grub-mkrescue --output=grub-img.iso
38 xorriso -as cdrecord -v dev=/dev/cdrw blank=as_needed grub-img.iso</userinput></screen>
42 To boot LFS on host systems that have UEFI enabled, the kernel needs to
43 have been built with the CONFIG_EFI_STUB capability described in the
44 previous section. However, LFS can be booted using GRUB2 without such
45 an addition. To do this, the UEFI Mode and Secure Boot capabilities in
46 the host system's BIOS need to be turned off. For details, see <ulink
47 url="&hints-root;lfs-uefi.txt">
48 the lfs-uefi.txt hint</ulink> at
49 &hints-root;lfs-uefi.txt.
56 <title>GRUB Naming Conventions</title>
58 <para>GRUB uses its own naming structure for drives and partitions in
59 the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
60 is the hard drive number and <emphasis>m</emphasis> is the partition
61 number. The hard drive number starts from zero, but the partition number
62 starts from one for normal partitions and five for extended partitions.
63 Note that this is different from earlier versions where
64 both numbers started from zero. For example, partition <filename
65 class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
66 GRUB and <filename class="partition">sdb3</filename> is
67 <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
68 consider CD-ROM drives to be hard drives. For example, if using a CD
69 on <filename class="partition">hdb</filename> and a second hard drive
70 on <filename class="partition">hdc</filename>, that second hard drive
71 would still be <emphasis>(hd1)</emphasis>.</para>
76 <title>Setting Up the Configuration</title>
78 <para>GRUB works by writing data to the first physical track of the
79 hard disk. This area is not part of any file system. The programs
80 there access GRUB modules in the boot partition. The default location
81 is /boot/grub/.</para>
83 <para>The location of the boot partition is a choice of the user that
84 affects the configuration. One recommendation is to have a separate small
85 (suggested size is 200 MB) partition just for boot information. That way
86 each build, whether LFS or some commercial distro, can access the same boot
87 files and access can be made from any booted system. If you choose to do
88 this, you will need to mount the separate partition, move all files in the
89 current <filename class="directory">/boot</filename> directory (e.g. the
90 linux kernel you just built in the previous section) to the new partition.
91 You will then need to unmount the partition and remount it as <filename
92 class="directory">/boot</filename>. If you do this, be sure to update
93 <filename>/etc/fstab</filename>.</para>
95 <para>Using the current lfs partition will also work, but configuration
96 for multiple systems is more difficult.</para>
98 <para>Using the above information, determine the appropriate
99 designator for the root partition (or boot partition, if a separate
100 one is used). For the following example, it is assumed that the root
101 (or separate boot) partition is <filename
102 class="partition">sda2</filename>.</para>
104 <para>Install the GRUB files into <filename
105 class="directory">/boot/grub</filename> and set up the boot track:</para>
108 <para>The following command will overwrite the current boot loader. Do not
109 run the command if this is not desired, for example, if using a third party
110 boot manager to manage the Master Boot Record (MBR).</para>
113 <screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
116 <para>If the system has been booted using UEFI,
117 <command>grub-install</command> will try to install files for the
118 <emphasis>x86_64-efi</emphasis> target, but those files
119 have not been installed in chapter 6. If this is the case, add
120 <option>--target i386-pc</option> to the command above.</para>
123 <!-- This does not seem to be true any more
124 <note><para><application>grub-install</application> is a script and calls another
125 program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
126 If so, create a temporary symbolic link from your root partition to /dev/root:</para>
128 <screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
130 <para>The symbolic link will only be present until the system is rebooted.
131 The link is only needed for the installation procedure.
136 <sect2 id="grub-cfg">
137 <title>Creating the GRUB Configuration File</title>
139 <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
141 <screen revision="sysv"><userinput>cat > /boot/grub/grub.cfg << "EOF"
142 <literal># Begin /boot/grub/grub.cfg
149 menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
150 linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
152 EOF</userinput></screen>
154 <screen revision="systemd"><userinput>cat > /boot/grub/grub.cfg << "EOF"
155 <literal># Begin /boot/grub/grub.cfg
162 menuentry "GNU/Linux, Linux &linux-version;-lfs-&versiond;" {
163 linux /boot/vmlinuz-&linux-version;-lfs-&versiond; root=/dev/sda2 ro
165 EOF</userinput></screen>
168 <note><para>From <application>GRUB</application>'s perspective, the
169 kernel files are relative to the partition used. If you
170 used a separate /boot partition, remove /boot from the above
171 <emphasis>linux</emphasis> line. You will also need to change the
172 <emphasis>set root</emphasis> line to point to the boot partition.
175 <para>GRUB is an extremely powerful program and it provides a tremendous
176 number of options for booting from a wide variety of devices, operating
177 systems, and partition types. There are also many options for customization
178 such as graphical splash screens, playing sounds, mouse input, etc. The
179 details of these options are beyond the scope of this introduction.</para>
181 <caution><para>There is a command, <application>grub-mkconfig</application>, that
182 can write a configuration file automatically. It uses a set of scripts in
183 /etc/grub.d/ and will destroy any customizations that you make. These scripts
184 are designed primarily for non-source distributions and are not recommended for
185 LFS. If you install a commercial Linux distribution, there is a good chance
186 that this program will be run. Be sure to back up your grub.cfg file.</para></caution>