grub.xml 11 KB

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