[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
|
---|
[154c0ce] | 35 | grub-mkrescue --output=grub-img.iso
|
---|
| 36 | dd if=grub-img.iso of=/dev/fd0 bs=1440 count=1</userinput></screen>
|
---|
| 37 |
|
---|
| 38 | <para>Alternatively, a boot CD can be created by using your host system's
|
---|
| 39 | CD burning tools to burn the <filename>grub-img.iso</filename> on to a
|
---|
| 40 | blank CD.</para>
|
---|
[1561534] | 41 |
|
---|
[4e82d47] | 42 | <para>GRUB uses its own naming structure for drives and partitions in
|
---|
| 43 | the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
|
---|
| 44 | is the hard drive number and <emphasis>m</emphasis> is the partition
|
---|
[920932e] | 45 | number. The hard drive number starts from zero, but the partition number
|
---|
[f9bcaec] | 46 | starts from one for normal partitions and five for extended partitions.
|
---|
[920932e] | 47 | Note that this is different from earlier versions where
|
---|
[f9bcaec] | 48 | both numbers started from zero. For example, partition <filename
|
---|
| 49 | class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
|
---|
| 50 | GRUB and <filename class="partition">sdb3</filename> is
|
---|
| 51 | <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
|
---|
[4e82d47] | 52 | consider CD-ROM drives to be hard drives. For example, if using a CD
|
---|
| 53 | on <filename class="partition">hdb</filename> and a second hard drive
|
---|
| 54 | on <filename class="partition">hdc</filename>, that second hard drive
|
---|
| 55 | would still be <emphasis>(hd1)</emphasis>.</para>
|
---|
| 56 |
|
---|
[f9bcaec] | 57 | <para>You can determine what GRUB thinks your disk devices are by running:</para>
|
---|
| 58 |
|
---|
[6ea017a2] | 59 | <screen role="nodump"><userinput>grub-mkdevicemap --device-map=device.map
|
---|
[f9bcaec] | 60 | cat device.map</userinput></screen>
|
---|
| 61 |
|
---|
| 62 | <para>The location of the boot partition is a choice of the user that
|
---|
| 63 | affects the configuration. One recommendation is to have a separate small
|
---|
| 64 | (suggested size is 100 MB) partition just for boot information. That way
|
---|
| 65 | each build, whether LFS or some commercial distro, can access the same boot
|
---|
| 66 | files and access can be made from any booted system. If you choose to do
|
---|
| 67 | this, you will need to mount the separate partition, move all files in the
|
---|
| 68 | current <filename class="directory">/boot</filename> directory (e.g. the
|
---|
| 69 | linux kernel you just built in the previous section) to the new partition.
|
---|
| 70 | You will then need to unmount the partition and remount it as <filename
|
---|
| 71 | class="directory">/boot</filename>. If you do this, be sure to update
|
---|
| 72 | <filename>/etc/fstab</filename>.</para>
|
---|
| 73 |
|
---|
| 74 | <para>Using the current lfs partition will also work, but configuration
|
---|
| 75 | for multiple systems is more difficult.</para>
|
---|
| 76 | </sect2>
|
---|
| 77 |
|
---|
| 78 | <sect2>
|
---|
| 79 | <title>Setting Up the Configuration</title>
|
---|
| 80 |
|
---|
[4e82d47] | 81 | <para>Using the above information, determine the appropriate
|
---|
| 82 | designator for the root partition (or boot partition, if a separate
|
---|
| 83 | one is used). For the following example, it is assumed that the root
|
---|
| 84 | (or separate boot) partition is <filename
|
---|
[f9bcaec] | 85 | class="partition">sda2</filename>.</para>
|
---|
| 86 |
|
---|
| 87 | <para>Install the GRUB files into <filename
|
---|
| 88 | class="directory">/boot/grub</filename>:</para>
|
---|
| 89 |
|
---|
| 90 | <screen role="nodump"><userinput>grub-install --grub-setup=/bin/true /dev/sda</userinput></screen>
|
---|
| 91 |
|
---|
[66d059b] | 92 | <para>We use --grub-setup=/bin/true for now to prevent updating the
|
---|
[f9bcaec] | 93 | Master Boot Record (MBR). In this way, we can test our installation
|
---|
| 94 | before committing to a change that is hard to revert.</para>
|
---|
| 95 |
|
---|
| 96 | <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
|
---|
| 97 |
|
---|
| 98 | <screen role="nodump"><userinput>grub-mkconfig -o /boot/grub/grub.cfg</userinput></screen>
|
---|
| 99 |
|
---|
| 100 | <para>Here <command>grub-mkconfig</command> uses the files in <filename
|
---|
| 101 | class="directory">/etc/grub.d/</filename> to determine the contents
|
---|
| 102 | of this file. The configuration file will look something like:</para>
|
---|
| 103 | <screen><computeroutput>#
|
---|
| 104 | # DO NOT EDIT THIS FILE
|
---|
| 105 | #
|
---|
| 106 | # It is automatically generated by /usr/sbin/grub-mkconfig using templates
|
---|
| 107 | # from /etc/grub.d and settings from /etc/default/grub
|
---|
| 108 | #
|
---|
| 109 |
|
---|
| 110 | ### BEGIN /etc/grub.d/00_header ###
|
---|
| 111 | set default=0
|
---|
| 112 | set timeout=5
|
---|
| 113 | ### END /etc/grub.d/00_header ###
|
---|
| 114 |
|
---|
| 115 | ### BEGIN /etc/grub.d/10_linux ###
|
---|
[1b8d78b] | 116 | menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
|
---|
[f9bcaec] | 117 | insmod ext2
|
---|
| 118 | set root=(hd0,2)
|
---|
| 119 | search --no-floppy --fs-uuid --set 915852a7-859e-45a6-9ff0-d3ebfdb5cea2
|
---|
| 120 | linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
---|
| 121 | }
|
---|
[1b8d78b] | 122 | menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" (recovery mode)" {
|
---|
[f9bcaec] | 123 | insmod ext2
|
---|
| 124 | set root=(hd0,2)
|
---|
| 125 | search --no-floppy --fs-uuid --set 915852a7-859e-45a6-9ff0-d3ebfdb5cea2
|
---|
| 126 | linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro single
|
---|
| 127 | }
|
---|
| 128 | menuentry "GNU/Linux, Linux 2.6.28-11-server" {
|
---|
| 129 | insmod ext2
|
---|
| 130 | set root=(hd0,2)
|
---|
| 131 | search --no-floppy --fs-uuid --set 6b4c0339-5501-4a85-8351-e398e5252be8
|
---|
| 132 | linux /boot/vmlinuz-2.6.28-11-server root=UUID=6b4c0339-5501-4a85-8351-e398e5252be8 ro
|
---|
| 133 | initrd /boot/initrd.img-2.6.28-11-server
|
---|
| 134 | }
|
---|
| 135 | menuentry "GNU/Linux, Linux 2.6.28-11-server (recovery mode)" {
|
---|
| 136 | insmod ext2
|
---|
| 137 | set root=(hd0,2)
|
---|
| 138 | search --no-floppy --fs-uuid --set 6b4c0339-5501-4a85-8351-e398e5252be8
|
---|
| 139 | linux /boot/vmlinuz-2.6.28-11-server root=UUID=6b4c0339-5501-4a85-8351-e398e5252be8 ro single
|
---|
| 140 | initrd /boot/initrd.img-2.6.28-11-server
|
---|
| 141 | }
|
---|
| 142 | ### END /etc/grub.d/10_linux ###
|
---|
| 143 |
|
---|
| 144 | ### BEGIN /etc/grub.d/30_os-prober ###
|
---|
| 145 | ### END /etc/grub.d/30_os-prober ###
|
---|
| 146 |
|
---|
| 147 | ### BEGIN /etc/grub.d/40_custom ###
|
---|
| 148 | # This file provides an easy way to add custom menu entries. Simply type the
|
---|
| 149 | # menu entries you want to add after this comment. Be careful not to change
|
---|
| 150 | # the 'exec tail' line above.
|
---|
| 151 | ### END /etc/grub.d/40_custom ###
|
---|
| 152 | </computeroutput></screen>
|
---|
| 153 |
|
---|
[6541b70] | 154 | <note>
|
---|
| 155 | <itemizedlist>
|
---|
| 156 | <listitem><para>Even though there is a warning not to edit the file, you
|
---|
| 157 | can do so as long as you do not re-run
|
---|
| 158 | <command>grub-mkconfig</command>.</para></listitem>
|
---|
| 159 |
|
---|
| 160 | <listitem><para>The <emphasis>search</emphasis> lines are generally not
|
---|
| 161 | useful for LFS systems as that command only sets an internal GRUB
|
---|
| 162 | variable used to find the kernel image. The <emphasis>set root</emphasis>
|
---|
| 163 | command provides the same capability without the overhead of
|
---|
| 164 | searching.</para></listitem>
|
---|
| 165 |
|
---|
| 166 | <listitem><para>The <emphasis>set root</emphasis> and
|
---|
| 167 | <emphasis>insmod ext2</emphasis> commands can be moved out of the
|
---|
| 168 | <emphasis>menuentry</emphasis> sections to apply to all sections of the file.
|
---|
| 169 | This leads to a simple section like:</para></listitem>
|
---|
| 170 |
|
---|
| 171 | </itemizedlist>
|
---|
| 172 | <screen><computeroutput>menuentry "Linux &linux-version;-lfs-&version;" {
|
---|
| 173 | linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
---|
| 174 | }
|
---|
| 175 | </computeroutput></screen>
|
---|
| 176 |
|
---|
| 177 | <itemizedlist>
|
---|
| 178 |
|
---|
| 179 | <listitem><para>Passing a UUID to the kernel requires an initial ram disk
|
---|
| 180 | (initrd) not built by LFS.</para></listitem>
|
---|
| 181 |
|
---|
| 182 | <listitem><para>If the <filename>/boot</filename> partition is installed
|
---|
| 183 | on a separate partition, the linux and initrd lines should not have the
|
---|
| 184 | string <emphasis>/boot</emphasis> prefixed to the file
|
---|
| 185 | names.</para></listitem>
|
---|
| 186 |
|
---|
| 187 | <listitem><para>In this example the kernel files for a Ubuntu
|
---|
| 188 | installation are also found in <filename
|
---|
| 189 | class="directory">/boot</filename>.</para></listitem>
|
---|
| 190 |
|
---|
| 191 | </itemizedlist>
|
---|
| 192 | </note>
|
---|
[4e82d47] | 193 |
|
---|
[f9bcaec] | 194 | </sect2>
|
---|
| 195 |
|
---|
| 196 | <sect2>
|
---|
| 197 | <title>Testing the Configuration</title>
|
---|
| 198 |
|
---|
| 199 | <para>The core image of GRUB is also a Multiboot kernel, so if you already
|
---|
[52318649] | 200 | have <emphasis>GRUB Legacy</emphasis> loaded you can load
|
---|
| 201 | GRUB-&grub-version; through your old boot loader. To accomplish this, you
|
---|
| 202 | will need to exit the <command>chroot</command> environment now and
|
---|
| 203 | re-enter it in the next section to finish the few remaining portions of
|
---|
| 204 | the book.</para>
|
---|
[f9bcaec] | 205 |
|
---|
| 206 | <screen role="nodump"><userinput>/sbin/reboot
|
---|
| 207 | ...
|
---|
| 208 | grub> root (hd0,1)
|
---|
| 209 | grub> kernel /boot/grub/core.img
|
---|
| 210 | grub> boot</userinput></screen>
|
---|
| 211 |
|
---|
| 212 | <para>Note that the GRUB commands above are assumed to be GRUB Legacy.
|
---|
| 213 | At this point the GRUB prompt will appear (very similar to GRUB Legacy) and
|
---|
| 214 | you can explore the interface or boot to one of the systems in the grub.cfg
|
---|
| 215 | file.</para>
|
---|
| 216 |
|
---|
| 217 | </sect2>
|
---|
| 218 |
|
---|
| 219 | <sect2>
|
---|
| 220 | <title>Updating the Master Boot Record</title>
|
---|
| 221 |
|
---|
| 222 | <para>If you tested the GRUB configuration as specified above, re-enter
|
---|
[a26951e] | 223 | the <command>chroot</command> environment.</para>
|
---|
[1561534] | 224 |
|
---|
[4e82d47] | 225 | <warning>
|
---|
| 226 | <para>The following command will overwrite the current boot loader. Do not
|
---|
| 227 | run the command if this is not desired, for example, if using a third party
|
---|
[f9bcaec] | 228 | boot manager to manage the Master Boot Record (MBR).</para>
|
---|
[4e82d47] | 229 | </warning>
|
---|
[81fd230] | 230 |
|
---|
[f9bcaec] | 231 | <para>Update the MBR with:</para>
|
---|
[54ff0b9] | 232 |
|
---|
[312e7dd] | 233 | <screen role="nodump"><userinput>grub-setup '<DEVICE>'</userinput></screen>
|
---|
| 234 |
|
---|
| 235 | <para>Change the DEVICE above to your boot disk, normally '(hd0)' or /dev/sda.
|
---|
| 236 | If using (hd0) be sure to escape the parentheses with backslashes or single
|
---|
| 237 | quotes to prevent the shell from interpreting them as a sub-shell.</para>
|
---|
[1561534] | 238 |
|
---|
[f9bcaec] | 239 | <para>This program uses the following defaults and are correct if you did not
|
---|
| 240 | deviate from the instructions above:</para>
|
---|
[1561534] | 241 |
|
---|
[f9bcaec] | 242 | <itemizedlist>
|
---|
| 243 | <listitem><para>boot image - boot.img </para></listitem>
|
---|
| 244 | <listitem><para>core image - core.img </para></listitem>
|
---|
| 245 | <listitem><para>directory - /boot/grub</para></listitem>
|
---|
| 246 | <listitem><para>device map - device.map</para></listitem>
|
---|
[312e7dd] | 247 | <listitem><para>default root setting - guessed</para></listitem>
|
---|
[f9bcaec] | 248 | </itemizedlist>
|
---|
[1561534] | 249 |
|
---|
[312e7dd] | 250 | <note><para>The root setting is the default value if a 'set root'
|
---|
| 251 | instruction is not found in grub.cfg. This is the partition that is
|
---|
| 252 | searched for the kernel and other supporting files. It is different from
|
---|
| 253 | the 'root=' parameter on the 'linux' line in the configuration line. The
|
---|
[21bbf5f] | 254 | latter is the partition the kernel mounts as '/'. In the example grub.cfg
|
---|
[312e7dd] | 255 | above, both values point to /dev/sda2, but if there is a separate boot
|
---|
| 256 | partition, they will be different.</para></note>
|
---|
| 257 |
|
---|
[f9bcaec] | 258 | </sect2>
|
---|
[4e82d47] | 259 |
|
---|
[955533b] | 260 | </sect1>
|
---|