grub.xml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <sect1 id="ch08-grub">
  2. <title>Making the LFS system bootable</title>
  3. <?dbhtml filename="grub.html" dir="chapter08"?>
  4. <para>Your shiny new LFS system is almost complete. One of the last things to
  5. do is ensure you can boot it. The instructions below apply only to computers
  6. of IA-32 architecture, i.e. mainstream PC's. Information on "boot loading" for
  7. other architectures should be available in the usual resource specific
  8. locations for those architectures.</para>
  9. <para>Boot loading can be a complex area. First, a few cautionary words. You
  10. really should be familiar with your current boot loader and any other
  11. operating systems present on your hard drive(s) that you might wish to keep
  12. bootable. Please make sure that you have an emergency boot disk ready, so that
  13. you can rescue your computer if, by any chance, your computer becomes unusable
  14. (unbootable).</para>
  15. <para>Earlier, we compiled and installed the Grub boot loader software in
  16. preparation for this step. The procedure involves writing some special Grub
  17. files to specific locations on the hard drive. Before we get to that, we
  18. highly recommend that you create a Grub boot floppy diskette just in case.
  19. Insert a blank floppy diskette and run the following commands:</para>
  20. <screen><userinput>dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1
  21. dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1</userinput></screen>
  22. <para>Remove the diskette and store it somewhere safe. Now we'll run the
  23. <userinput>grub</userinput> shell.</para>
  24. <screen><userinput>grub</userinput></screen>
  25. <para>Grub uses its own naming structure for drives and partitions, in the form
  26. of (hdn,m), where <emphasis>n</emphasis> is the hard drive number, and
  27. <emphasis>m</emphasis> the partition number, both starting from zero. This
  28. means, for instance, that partition <filename>hda1</filename> is (hd0,0) to
  29. Grub, and <filename>hdb2</filename> is (hd1,1). In contrast to Linux, Grub
  30. doesn't consider CD-ROM drives to be hard drives, so if you have a CD on
  31. <filename>hdb</filename>, for example, and a second hard drive on
  32. <filename>hdc</filename>, that second hard drive would still be (hd1).</para>
  33. <para>Using the above information, determine the appropriate designator for
  34. your root partition. For the following example, we'll assume your root
  35. partition is <filename>hda4</filename>.</para>
  36. <para>First, tell Grub where to search for its <filename>stage{1,2}</filename>
  37. files -- you can use Tab everywhere to make Grub show the alternatives:</para>
  38. <screen><userinput>root (hd0,3)</userinput></screen>
  39. <!-- HACK - Force some whitespace to appease tidy -->
  40. <literallayout></literallayout>
  41. <warning><para>The following command will overwrite your current boot loader.
  42. Don't run the command if this is not what you want. For example, you may be
  43. using a third party boot manager to manage your MBR (Master Boot Record). In
  44. this scenario, it would probably make more sense to install Grub into the
  45. "boot sector" of the LFS partition, in which case the command would become
  46. <userinput>setup (hd0,3)</userinput>:</para></warning>
  47. <!-- HACK - Force some whitespace to appease tidy -->
  48. <literallayout></literallayout>
  49. <para>Then tell it to install itself into the MBR (Master Boot Record) of
  50. <filename>hda</filename>:</para>
  51. <screen><userinput>setup (hd0)</userinput></screen>
  52. <para>If all is well, Grub will have reported finding its files in
  53. <filename>/boot/grub</filename>. That's all there is to it:</para>
  54. <screen><userinput>quit</userinput></screen>
  55. <para>Now we need to create the <filename>menu.lst</filename> file, which
  56. defines Grub's boot menu:</para>
  57. <screen><userinput>cat &gt; /boot/grub/menu.lst &lt;&lt; "EOF"</userinput>
  58. # Begin /boot/grub/menu.lst
  59. # By default boot the first menu entry.
  60. default 0
  61. # Allow 30 seconds before booting the default.
  62. timeout 30
  63. # Use prettier colors.
  64. color green/black light-green/black
  65. # The first entry is for LFS.
  66. title LFS &milestone;
  67. root (hd0,3)
  68. kernel /boot/lfskernel root=/dev/hda4 ro
  69. <userinput>EOF</userinput></screen>
  70. <para>You may want to add an entry for your host distribution. It might look
  71. like this:</para>
  72. <screen><userinput>cat &gt;&gt; /boot/grub/menu.lst &lt;&lt; "EOF"</userinput>
  73. title Red Hat
  74. root (hd0,2)
  75. kernel /boot/kernel-2.4.20 root=/dev/hda3 ro
  76. initrd /boot/initrd-2.4.20
  77. <userinput>EOF</userinput></screen>
  78. <para>Also, if you happen to dual-boot Windows, the following entry should
  79. allow booting it:</para>
  80. <screen><userinput>cat &gt;&gt; /boot/grub/menu.lst &lt;&lt; "EOF"</userinput>
  81. title Windows
  82. rootnoverify (hd0,0)
  83. chainloader +1
  84. <userinput>EOF</userinput></screen>
  85. <para>If <userinput>info grub</userinput> doesn't tell you all you want to
  86. know, you can find more information regarding Grub on its website, located at:
  87. <ulink url="http://www.gnu.org/software/grub"/>.</para>
  88. </sect1>