grub.xml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <warning><para>Configuring GRUB incorrectly can render your system
  18. inoperable without an alternate boot device such as a CD-ROM. This
  19. section is not required to boot your LFS system. You may just
  20. want to modify your current boot loader, e.g. Grub-Legacy, GRUB2, or
  21. LILO.</para></warning>
  22. <para> Ensure that an emergency boot disk is ready to <quote>rescue</quote>
  23. the computer if the computer becomes unusable (un-bootable). If you do not
  24. already have a boot device, you can create one. In order for the procedure
  25. below to work, you need to jump ahead to BLFS and install
  26. <userinput>xorriso</userinput> from the <ulink
  27. url="&blfs-book;multimedia/libisoburn.html">
  28. libisoburn</ulink> package.</para>
  29. <screen role="nodump"><userinput>cd /tmp
  30. grub-mkrescue --output=grub-img.iso
  31. xorriso -as cdrecord -v dev=/dev/cdrw blank=as_needed grub-img.iso</userinput></screen>
  32. <note>
  33. <para>
  34. To boot LFS on host systems that have UEFI enabled, the kernel needs to
  35. have been built with the CONFIG_EFI_STUB capabality described in the
  36. previous section. However, LFS can be booted using GRUB2 without such
  37. an addition. To do this, the UEFI Mode and Secure Boot capabilities in
  38. the host system's BIOS need to be turned off. For details, see <ulink
  39. url="http://www.linuxfromscratch.org/hints/downloads/files/lfs-uefi.txt">
  40. the lfs-uefi.txt hint</ulink> at
  41. http://www.linuxfromscratch.org/hints/downloads/files/lfs-uefi.txt.
  42. </para>
  43. </note>
  44. </sect2>
  45. <sect2>
  46. <title>GRUB Naming Conventions</title>
  47. <para>GRUB uses its own naming structure for drives and partitions in
  48. the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
  49. is the hard drive number and <emphasis>m</emphasis> is the partition
  50. number. The hard drive number starts from zero, but the partition number
  51. starts from one for normal partitions and five for extended partitions.
  52. Note that this is different from earlier versions where
  53. both numbers started from zero. For example, partition <filename
  54. class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
  55. GRUB and <filename class="partition">sdb3</filename> is
  56. <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
  57. consider CD-ROM drives to be hard drives. For example, if using a CD
  58. on <filename class="partition">hdb</filename> and a second hard drive
  59. on <filename class="partition">hdc</filename>, that second hard drive
  60. would still be <emphasis>(hd1)</emphasis>.</para>
  61. </sect2>
  62. <sect2>
  63. <title>Setting Up the Configuration</title>
  64. <para>GRUB works by writing data to the first physical track of the
  65. hard disk. This area is not part of any file system. The programs
  66. there access GRUB modules in the boot partition. The default location
  67. is /boot/grub/.</para>
  68. <para>The location of the boot partition is a choice of the user that
  69. affects the configuration. One recommendation is to have a separate small
  70. (suggested size is 100 MB) partition just for boot information. That way
  71. each build, whether LFS or some commercial distro, can access the same boot
  72. files and access can be made from any booted system. If you choose to do
  73. this, you will need to mount the separate partition, move all files in the
  74. current <filename class="directory">/boot</filename> directory (e.g. the
  75. linux kernel you just built in the previous section) to the new partition.
  76. You will then need to unmount the partition and remount it as <filename
  77. class="directory">/boot</filename>. If you do this, be sure to update
  78. <filename>/etc/fstab</filename>.</para>
  79. <para>Using the current lfs partition will also work, but configuration
  80. for multiple systems is more difficult.</para>
  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
  85. class="partition">sda2</filename>.</para>
  86. <para>Install the GRUB files into <filename
  87. class="directory">/boot/grub</filename> and set up the boot track:</para>
  88. <warning>
  89. <para>The following command will overwrite the current boot loader. Do not
  90. run the command if this is not desired, for example, if using a third party
  91. boot manager to manage the Master Boot Record (MBR).</para>
  92. </warning>
  93. <screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
  94. <note>
  95. <para>If the system has been booted using UEFI,
  96. <command>grub-install</command> will try to install files for the
  97. <emphasis>x86_64-efi</emphasis> target, but those files
  98. have not been installed in chapter 6. If this is the case, add
  99. <option>--target i386-pc</option> to the command above.</para>
  100. </note>
  101. <!-- This does not seem to be true any more
  102. <note><para><application>grub-install</application> is a script and calls another
  103. program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
  104. If so, create a temporary symbolic link from your root partition to /dev/root:</para>
  105. <screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
  106. <para>The symbolic link will only be present until the system is rebooted.
  107. The link is only needed for the installation procedure.
  108. </para></note>
  109. -->
  110. </sect2>
  111. <sect2 id="grub-cfg">
  112. <title>Creating the GRUB Configuration File</title>
  113. <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
  114. <screen revision="sysv"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
  115. <literal># Begin /boot/grub/grub.cfg
  116. set default=0
  117. set timeout=5
  118. insmod ext2
  119. set root=(hd0,2)
  120. menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
  121. linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
  122. }</literal>
  123. EOF</userinput></screen>
  124. <screen revision="systemd"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
  125. <literal># Begin /boot/grub/grub.cfg
  126. set default=0
  127. set timeout=5
  128. insmod ext2
  129. set root=(hd0,2)
  130. menuentry "GNU/Linux, Linux &linux-version;-lfs-&versiond;" {
  131. linux /boot/vmlinuz-&linux-version;-lfs-&versiond; root=/dev/sda2 ro
  132. }</literal>
  133. EOF</userinput></screen>
  134. <note><para>From <application>GRUB</application>'s perspective, the
  135. kernel files are relative to the partition used. If you
  136. used a separate /boot partition, remove /boot from the above
  137. <emphasis>linux</emphasis> line. You will also need to change the
  138. <emphasis>set root</emphasis> line to point to the boot partition.
  139. </para></note>
  140. <para>GRUB is an extremely powerful program and it provides a tremendous
  141. number of options for booting from a wide variety of devices, operating
  142. systems, and partition types. There are also many options for customization
  143. such as graphical splash screens, playing sounds, mouse input, etc. The
  144. details of these options are beyond the scope of this introduction.</para>
  145. <caution><para>There is a command, <application>grub-mkconfig</application>, that
  146. can write a configuration file automatically. It uses a set of scripts in
  147. /etc/grub.d/ and will destroy any customizations that you make. These scripts
  148. are designed primarily for non-source distributions and are not recommended for
  149. LFS. If you install a commercial Linux distribution, there is a good chance
  150. that this program will be run. Be sure to back up your grub.cfg file.</para></caution>
  151. </sect2>
  152. </sect1>