[673b0d8] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[b06ca36] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[673b0d8] | 4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
[b78c747] | 7 |
|
---|
[4e82d47] | 8 | <sect1 id="ch-bootable-grub" role="wrap">
|
---|
[b78c747] | 9 | <?dbhtml filename="grub.html"?>
|
---|
| 10 |
|
---|
[4e82d47] | 11 | <sect1info condition="script">
|
---|
| 12 | <productname>grub</productname>
|
---|
| 13 | <productnumber>&grub-version;</productnumber>
|
---|
| 14 | <address>&grub-url;</address>
|
---|
| 15 | </sect1info>
|
---|
| 16 |
|
---|
[f9bcaec] | 17 | <title>Using GRUB to Set Up the Boot Process</title>
|
---|
[4e82d47] | 18 |
|
---|
[f9bcaec] | 19 | <sect2>
|
---|
| 20 | <title>Introduction</title>
|
---|
[4e82d47] | 21 |
|
---|
| 22 | <para>Boot loading can be a complex area, so a few cautionary
|
---|
| 23 | words are in order. Be familiar with the current boot loader and any other
|
---|
| 24 | operating systems present on the hard drive(s) that need to be
|
---|
| 25 | bootable. Make sure that an emergency boot disk is ready to
|
---|
| 26 | <quote>rescue</quote> the computer if the computer becomes
|
---|
| 27 | unusable (un-bootable).</para>
|
---|
| 28 |
|
---|
[699b0f2] | 29 | <para>The procedure involves writing some special GRUB files to specific
|
---|
[f9bcaec] | 30 | locations on the hard drive. We highly recommend creating a GRUB boot
|
---|
| 31 | floppy diskette as a backup. Insert a blank floppy diskette and run the
|
---|
| 32 | following commands:</para>
|
---|
[1561534] | 33 |
|
---|
[f9bcaec] | 34 | <screen role="nodump"><userinput>cd /tmp
|
---|
| 35 | grub-mkrescue --image-type=floppy floppy.img
|
---|
[3d4219a] | 36 | dd if=floppy.img of=/dev/fd0 bs=1440 count=1</userinput></screen>
|
---|
[1561534] | 37 |
|
---|
[4e82d47] | 38 | <para>GRUB uses its own naming structure for drives and partitions in
|
---|
| 39 | the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
|
---|
| 40 | is the hard drive number and <emphasis>m</emphasis> is the partition
|
---|
[920932e] | 41 | number. The hard drive number starts from zero, but the partition number
|
---|
[f9bcaec] | 42 | starts from one for normal partitions and five for extended partitions.
|
---|
[920932e] | 43 | Note that this is different from earlier versions where
|
---|
[f9bcaec] | 44 | both numbers started from zero. For example, partition <filename
|
---|
| 45 | class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
|
---|
| 46 | GRUB and <filename class="partition">sdb3</filename> is
|
---|
| 47 | <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
|
---|
[4e82d47] | 48 | consider CD-ROM drives to be hard drives. For example, if using a CD
|
---|
| 49 | on <filename class="partition">hdb</filename> and a second hard drive
|
---|
| 50 | on <filename class="partition">hdc</filename>, that second hard drive
|
---|
| 51 | would still be <emphasis>(hd1)</emphasis>.</para>
|
---|
| 52 |
|
---|
[f9bcaec] | 53 | <para>You can determine what GRUB thinks your disk devices are by running:</para>
|
---|
| 54 |
|
---|
[6ea017a2] | 55 | <screen role="nodump"><userinput>grub-mkdevicemap --device-map=device.map
|
---|
[f9bcaec] | 56 | cat device.map</userinput></screen>
|
---|
| 57 |
|
---|
| 58 | <para>The location of the boot partition is a choice of the user that
|
---|
| 59 | affects the configuration. One recommendation is to have a separate small
|
---|
| 60 | (suggested size is 100 MB) partition just for boot information. That way
|
---|
| 61 | each build, whether LFS or some commercial distro, can access the same boot
|
---|
| 62 | files and access can be made from any booted system. If you choose to do
|
---|
| 63 | this, you will need to mount the separate partition, move all files in the
|
---|
| 64 | current <filename class="directory">/boot</filename> directory (e.g. the
|
---|
| 65 | linux kernel you just built in the previous section) to the new partition.
|
---|
| 66 | You will then need to unmount the partition and remount it as <filename
|
---|
| 67 | class="directory">/boot</filename>. If you do this, be sure to update
|
---|
| 68 | <filename>/etc/fstab</filename>.</para>
|
---|
| 69 |
|
---|
| 70 | <para>Using the current lfs partition will also work, but configuration
|
---|
| 71 | for multiple systems is more difficult.</para>
|
---|
| 72 | </sect2>
|
---|
| 73 |
|
---|
| 74 | <sect2>
|
---|
| 75 | <title>Setting Up the Configuration</title>
|
---|
| 76 |
|
---|
[4e82d47] | 77 | <para>Using the above information, determine the appropriate
|
---|
| 78 | designator for the root partition (or boot partition, if a separate
|
---|
| 79 | one is used). For the following example, it is assumed that the root
|
---|
| 80 | (or separate boot) partition is <filename
|
---|
[f9bcaec] | 81 | class="partition">sda2</filename>.</para>
|
---|
| 82 |
|
---|
| 83 | <para>Install the GRUB files into <filename
|
---|
| 84 | class="directory">/boot/grub</filename>:</para>
|
---|
| 85 |
|
---|
| 86 | <screen role="nodump"><userinput>grub-install --grub-setup=/bin/true /dev/sda</userinput></screen>
|
---|
| 87 |
|
---|
[66d059b] | 88 | <para>We use --grub-setup=/bin/true for now to prevent updating the
|
---|
[f9bcaec] | 89 | Master Boot Record (MBR). In this way, we can test our installation
|
---|
| 90 | before committing to a change that is hard to revert.</para>
|
---|
| 91 |
|
---|
| 92 | <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
|
---|
| 93 |
|
---|
| 94 | <screen role="nodump"><userinput>grub-mkconfig -o /boot/grub/grub.cfg</userinput></screen>
|
---|
| 95 |
|
---|
| 96 | <para>Here <command>grub-mkconfig</command> uses the files in <filename
|
---|
| 97 | class="directory">/etc/grub.d/</filename> to determine the contents
|
---|
| 98 | of this file. The configuration file will look something like:</para>
|
---|
| 99 | <screen><computeroutput>#
|
---|
| 100 | # DO NOT EDIT THIS FILE
|
---|
| 101 | #
|
---|
| 102 | # It is automatically generated by /usr/sbin/grub-mkconfig using templates
|
---|
| 103 | # from /etc/grub.d and settings from /etc/default/grub
|
---|
| 104 | #
|
---|
| 105 |
|
---|
| 106 | ### BEGIN /etc/grub.d/00_header ###
|
---|
| 107 | set default=0
|
---|
| 108 | set timeout=5
|
---|
| 109 | ### END /etc/grub.d/00_header ###
|
---|
| 110 |
|
---|
| 111 | ### BEGIN /etc/grub.d/10_linux ###
|
---|
| 112 | menuentry "GNU/Linux, Linux 2.6.30.2-lfs65" {
|
---|
| 113 | insmod ext2
|
---|
| 114 | set root=(hd0,2)
|
---|
| 115 | search --no-floppy --fs-uuid --set 915852a7-859e-45a6-9ff0-d3ebfdb5cea2
|
---|
| 116 | linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
---|
| 117 | }
|
---|
| 118 | menuentry "GNU/Linux, Linux 2.6.30.2-lfs65 (recovery mode)" {
|
---|
| 119 | insmod ext2
|
---|
| 120 | set root=(hd0,2)
|
---|
| 121 | search --no-floppy --fs-uuid --set 915852a7-859e-45a6-9ff0-d3ebfdb5cea2
|
---|
| 122 | linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro single
|
---|
| 123 | }
|
---|
| 124 | menuentry "GNU/Linux, Linux 2.6.28-11-server" {
|
---|
| 125 | insmod ext2
|
---|
| 126 | set root=(hd0,2)
|
---|
| 127 | search --no-floppy --fs-uuid --set 6b4c0339-5501-4a85-8351-e398e5252be8
|
---|
| 128 | linux /boot/vmlinuz-2.6.28-11-server root=UUID=6b4c0339-5501-4a85-8351-e398e5252be8 ro
|
---|
| 129 | initrd /boot/initrd.img-2.6.28-11-server
|
---|
| 130 | }
|
---|
| 131 | menuentry "GNU/Linux, Linux 2.6.28-11-server (recovery mode)" {
|
---|
| 132 | insmod ext2
|
---|
| 133 | set root=(hd0,2)
|
---|
| 134 | search --no-floppy --fs-uuid --set 6b4c0339-5501-4a85-8351-e398e5252be8
|
---|
| 135 | linux /boot/vmlinuz-2.6.28-11-server root=UUID=6b4c0339-5501-4a85-8351-e398e5252be8 ro single
|
---|
| 136 | initrd /boot/initrd.img-2.6.28-11-server
|
---|
| 137 | }
|
---|
| 138 | ### END /etc/grub.d/10_linux ###
|
---|
| 139 |
|
---|
| 140 | ### BEGIN /etc/grub.d/30_os-prober ###
|
---|
| 141 | ### END /etc/grub.d/30_os-prober ###
|
---|
| 142 |
|
---|
| 143 | ### BEGIN /etc/grub.d/40_custom ###
|
---|
| 144 | # This file provides an easy way to add custom menu entries. Simply type the
|
---|
| 145 | # menu entries you want to add after this comment. Be careful not to change
|
---|
| 146 | # the 'exec tail' line above.
|
---|
| 147 | ### END /etc/grub.d/40_custom ###
|
---|
| 148 | </computeroutput></screen>
|
---|
| 149 |
|
---|
| 150 | <para>Note that even though there is a warning not to edit the file, you can
|
---|
[21bbf5f] | 151 | do so as long as you do not re-run <command>grub-mkconfig</command>. The
|
---|
[f9bcaec] | 152 | <emphasis>search</emphasis> lines are not meaningful for LFS systems as that
|
---|
| 153 | command needs an initrd image for processing. If installing on a separate
|
---|
| 154 | partition the linux and initrd lines will not have the /boot on the file
|
---|
| 155 | names. In this example the kernel files for a Ubuntu installation are
|
---|
| 156 | also found in <filename class="directory">/boot</filename>.</para>
|
---|
[4e82d47] | 157 |
|
---|
[f9bcaec] | 158 | </sect2>
|
---|
| 159 |
|
---|
| 160 | <sect2>
|
---|
| 161 | <title>Testing the Configuration</title>
|
---|
| 162 |
|
---|
| 163 | <para>The core image of GRUB is also a Multiboot kernel, so if you already
|
---|
| 164 | have GRUB Legacy loaded you can load GRUB-&grub-version; through your old
|
---|
| 165 | boot loader. To accomplish this, you will need to exit the
|
---|
| 166 | <command>chroot</command> environment and re-enter it to finish the
|
---|
| 167 | few remaining portions of the book.</para>
|
---|
| 168 |
|
---|
| 169 | <screen role="nodump"><userinput>/sbin/reboot
|
---|
| 170 | ...
|
---|
| 171 | grub> root (hd0,1)
|
---|
| 172 | grub> kernel /boot/grub/core.img
|
---|
| 173 | grub> boot</userinput></screen>
|
---|
| 174 |
|
---|
| 175 | <para>Note that the GRUB commands above are assumed to be GRUB Legacy.
|
---|
| 176 | At this point the GRUB prompt will appear (very similar to GRUB Legacy) and
|
---|
| 177 | you can explore the interface or boot to one of the systems in the grub.cfg
|
---|
| 178 | file.</para>
|
---|
| 179 |
|
---|
| 180 | </sect2>
|
---|
| 181 |
|
---|
| 182 | <sect2>
|
---|
| 183 | <title>Updating the Master Boot Record</title>
|
---|
| 184 |
|
---|
| 185 | <para>If you tested the GRUB configuration as specified above, re-enter
|
---|
[a26951e] | 186 | the <command>chroot</command> environment.</para>
|
---|
[1561534] | 187 |
|
---|
[4e82d47] | 188 | <warning>
|
---|
| 189 | <para>The following command will overwrite the current boot loader. Do not
|
---|
| 190 | run the command if this is not desired, for example, if using a third party
|
---|
[f9bcaec] | 191 | boot manager to manage the Master Boot Record (MBR).</para>
|
---|
[4e82d47] | 192 | </warning>
|
---|
[81fd230] | 193 |
|
---|
[f9bcaec] | 194 | <para>Update the MBR with:</para>
|
---|
[54ff0b9] | 195 |
|
---|
[312e7dd] | 196 | <screen role="nodump"><userinput>grub-setup '<DEVICE>'</userinput></screen>
|
---|
| 197 |
|
---|
| 198 | <para>Change the DEVICE above to your boot disk, normally '(hd0)' or /dev/sda.
|
---|
| 199 | If using (hd0) be sure to escape the parentheses with backslashes or single
|
---|
| 200 | quotes to prevent the shell from interpreting them as a sub-shell.</para>
|
---|
[1561534] | 201 |
|
---|
[f9bcaec] | 202 | <para>This program uses the following defaults and are correct if you did not
|
---|
| 203 | deviate from the instructions above:</para>
|
---|
[1561534] | 204 |
|
---|
[f9bcaec] | 205 | <itemizedlist>
|
---|
| 206 | <listitem><para>boot image - boot.img </para></listitem>
|
---|
| 207 | <listitem><para>core image - core.img </para></listitem>
|
---|
| 208 | <listitem><para>directory - /boot/grub</para></listitem>
|
---|
| 209 | <listitem><para>device map - device.map</para></listitem>
|
---|
[312e7dd] | 210 | <listitem><para>default root setting - guessed</para></listitem>
|
---|
[f9bcaec] | 211 | </itemizedlist>
|
---|
[1561534] | 212 |
|
---|
[312e7dd] | 213 | <note><para>The root setting is the default value if a 'set root'
|
---|
| 214 | instruction is not found in grub.cfg. This is the partition that is
|
---|
| 215 | searched for the kernel and other supporting files. It is different from
|
---|
| 216 | the 'root=' parameter on the 'linux' line in the configuration line. The
|
---|
[21bbf5f] | 217 | latter is the partition the kernel mounts as '/'. In the example grub.cfg
|
---|
[312e7dd] | 218 | above, both values point to /dev/sda2, but if there is a separate boot
|
---|
| 219 | partition, they will be different.</para></note>
|
---|
| 220 |
|
---|
[f9bcaec] | 221 | </sect2>
|
---|
[4e82d47] | 222 |
|
---|
[955533b] | 223 | </sect1>
|
---|