[fcc02767] | 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 |
|
---|
[1c16a05] | 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 config 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 |
|
---|
[fcc02767] | 28 | <sect2>
|
---|
| 29 | <title>Introduction</title>
|
---|
| 30 |
|
---|
| 31 | <warning><para>Configuring GRUB incorrectly can render your system
|
---|
[37b5ac1] | 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
|
---|
[fcc02767] | 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 |
|
---|
[9cea9a2] | 45 | <screen role="nodump"><userinput>cd /tmp
|
---|
| 46 | grub-mkrescue --output=grub-img.iso
|
---|
[fcc02767] | 47 | xorriso -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 number starts from zero, but the partition number
|
---|
| 58 | starts from one for normal partitions and 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>The location of the boot partition is a choice of the user that
|
---|
| 80 | affects the configuration. One recommendation is to have a separate small
|
---|
[37b5ac1] | 81 | (suggested size is 200 MB) partition just for boot information. That way
|
---|
[fcc02767] | 82 | each build, whether LFS or some commercial distro, can access the same boot
|
---|
| 83 | files and access can be made from any booted system. If you choose to do
|
---|
| 84 | this, you will need to mount the separate partition, move all files in the
|
---|
| 85 | current <filename class="directory">/boot</filename> directory (e.g. the
|
---|
| 86 | linux kernel you just built in the previous section) to the new partition.
|
---|
| 87 | You will then need to unmount the partition and remount it as <filename
|
---|
| 88 | class="directory">/boot</filename>. If you do this, be sure to update
|
---|
| 89 | <filename>/etc/fstab</filename>.</para>
|
---|
| 90 |
|
---|
| 91 | <para>Using the current lfs partition will also work, but configuration
|
---|
| 92 | for multiple systems is more difficult.</para>
|
---|
| 93 |
|
---|
| 94 | <para>Using the above information, determine the appropriate
|
---|
| 95 | designator for the root partition (or boot partition, if a separate
|
---|
| 96 | one is used). For the following example, it is assumed that the root
|
---|
| 97 | (or separate boot) partition is <filename
|
---|
| 98 | class="partition">sda2</filename>.</para>
|
---|
| 99 |
|
---|
| 100 | <para>Install the GRUB files into <filename
|
---|
| 101 | class="directory">/boot/grub</filename> and set up the boot track:</para>
|
---|
| 102 |
|
---|
| 103 | <warning>
|
---|
| 104 | <para>The following command will overwrite the current boot loader. Do not
|
---|
| 105 | run the command if this is not desired, for example, if using a third party
|
---|
| 106 | boot manager to manage the Master Boot Record (MBR).</para>
|
---|
| 107 | </warning>
|
---|
| 108 |
|
---|
| 109 | <screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
|
---|
| 110 |
|
---|
| 111 | <note>
|
---|
| 112 | <para>If the system has been booted using UEFI,
|
---|
| 113 | <command>grub-install</command> will try to install files for the
|
---|
| 114 | <emphasis>x86_64-efi</emphasis> target, but those files
|
---|
[cefb4c9] | 115 | have not been installed in <xref linkend="chapter-building-system"/>.
|
---|
| 116 | If this is the case, add <option>--target i386-pc</option> to the
|
---|
| 117 | command above.</para>
|
---|
[fcc02767] | 118 | </note>
|
---|
| 119 |
|
---|
| 120 | <!-- This does not seem to be true any more
|
---|
| 121 | <note><para><application>grub-install</application> is a script and calls another
|
---|
| 122 | program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
|
---|
| 123 | If so, create a temporary symbolic link from your root partition to /dev/root:</para>
|
---|
| 124 |
|
---|
| 125 | <screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
|
---|
| 126 |
|
---|
| 127 | <para>The symbolic link will only be present until the system is rebooted.
|
---|
| 128 | The link is only needed for the installation procedure.
|
---|
| 129 | </para></note>
|
---|
| 130 | -->
|
---|
| 131 | </sect2>
|
---|
| 132 |
|
---|
| 133 | <sect2 id="grub-cfg">
|
---|
| 134 | <title>Creating the GRUB Configuration File</title>
|
---|
| 135 |
|
---|
| 136 | <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
|
---|
| 137 |
|
---|
[3d7b4f6] | 138 | <screen><userinput>cat > /boot/grub/grub.cfg << "EOF"
|
---|
[fcc02767] | 139 | <literal># Begin /boot/grub/grub.cfg
|
---|
| 140 | set default=0
|
---|
| 141 | set timeout=5
|
---|
| 142 |
|
---|
| 143 | insmod ext2
|
---|
| 144 | set root=(hd0,2)
|
---|
| 145 |
|
---|
| 146 | menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
|
---|
| 147 | linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
---|
| 148 | }</literal>
|
---|
| 149 | EOF</userinput></screen>
|
---|
| 150 |
|
---|
| 151 | <note><para>From <application>GRUB</application>'s perspective, the
|
---|
| 152 | kernel files are relative to the partition used. If you
|
---|
| 153 | used a separate /boot partition, remove /boot from the above
|
---|
| 154 | <emphasis>linux</emphasis> line. You will also need to change the
|
---|
| 155 | <emphasis>set root</emphasis> line to point to the boot partition.
|
---|
| 156 | </para></note>
|
---|
| 157 |
|
---|
| 158 | <para>GRUB is an extremely powerful program and it provides a tremendous
|
---|
| 159 | number of options for booting from a wide variety of devices, operating
|
---|
| 160 | systems, and partition types. There are also many options for customization
|
---|
| 161 | such as graphical splash screens, playing sounds, mouse input, etc. The
|
---|
| 162 | details of these options are beyond the scope of this introduction.</para>
|
---|
| 163 |
|
---|
| 164 | <caution><para>There is a command, <application>grub-mkconfig</application>, that
|
---|
| 165 | can write a configuration file automatically. It uses a set of scripts in
|
---|
| 166 | /etc/grub.d/ and will destroy any customizations that you make. These scripts
|
---|
| 167 | are designed primarily for non-source distributions and are not recommended for
|
---|
| 168 | LFS. If you install a commercial Linux distribution, there is a good chance
|
---|
| 169 | that this program will be run. Be sure to back up your grub.cfg file.</para></caution>
|
---|
| 170 |
|
---|
| 171 | </sect2>
|
---|
| 172 |
|
---|
| 173 | </sect1>
|
---|