grub.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?xml version="1.0" encoding="UTF-8"?>
  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>使用 GRUB 设定引导过程</title>
  15. <sect2>
  16. <title>概述</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. <warning>
  23. <para>如果您不小心错误地配置了 GRUB,而且没有 CD-ROM
  24. 之类的备用引导设备,可能会导致您的系统完全无法使用。
  25. 本节不是引导您的 LFS 系统的唯一方案,
  26. 您可能只要修改现有的启动加载器(如 Grub-Legacy、GRUB2 或 LILO)
  27. 配置即可引导 LFS。</para>
  28. </warning>
  29. <!--para> Ensure that an emergency boot disk is ready to <quote>rescue</quote>
  30. the computer if the computer becomes unusable (un-bootable). If you do not
  31. already have a boot device, you can create one. In order for the procedure
  32. below to work, you need to jump ahead to BLFS and install
  33. <userinput>xorriso</userinput> from the <ulink
  34. url="&blfs-book;multimedia/libisoburn.html">
  35. libisoburn</ulink> package.</para-->
  36. <para>您务必保证自己拥有一个紧急引导磁盘,它在计算机不可用(无法引导)
  37. 时能够 <quote>救援</quote> 计算机。如果您现在还没有引导设备,
  38. 您可以执行以下命令创建一个。在运行下列命令前,您需要跳到 BLFS,
  39. 安装包含 <command>xorriso</command> 的
  40. <ulink url="&blfs-book;multimedia/libisoburn.html">libisoburn
  41. </ulink> 软件包:</para>
  42. <screen role="nodump"><userinput>cd /tmp
  43. grub-mkrescue --output=grub-img.iso
  44. xorriso -as cdrecord -v dev=/dev/cdrw blank=as_needed grub-img.iso</userinput></screen>
  45. <note>
  46. <!--para>
  47. To boot LFS on host systems that have UEFI enabled, the kernel needs to
  48. have been built with the CONFIG_EFI_STUB capabality described in the
  49. previous section. However, LFS can be booted using GRUB2 without such
  50. an addition. To do this, the UEFI Mode and Secure Boot capabilities in
  51. the host system's BIOS need to be turned off. For details, see <ulink
  52. url="http://www.linuxfromscratch.org/hints/downloads/files/lfs-uefi.txt">
  53. the lfs-uefi.txt hint</ulink> at
  54. http://www.linuxfromscratch.org/hints/downloads/files/lfs-uefi.txt.
  55. </para-->
  56. <para>为了在使用 UEFI 的宿主系统上引导 LFS ,在构建内核时,
  57. 需要启用 CONFIG_EFI_STUB 功能,正如上一节所述。
  58. 不过,可以使用 GRUB2 在没有该功能的情况下引导 LFS,
  59. 前提是在系统 BIOS 设定中关闭 UEFI 模式和安全引导
  60. (Secure Boot)功能。关于在 UEFI 环境下引导 LFS 的的详细信息,
  61. 可以参阅 <ulink url="&hints-root;lfs-uefi.txt"/>。
  62. </para>
  63. </note>
  64. </sect2>
  65. <sect2>
  66. <title>GRUB 命名惯例</title>
  67. <!--para>GRUB uses its own naming structure for drives and partitions in
  68. the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
  69. is the hard drive number and <emphasis>m</emphasis> is the partition
  70. number. The hard drive number starts from zero, but the partition number
  71. starts from one for normal partitions and five for extended partitions.
  72. Note that this is different from earlier versions where
  73. both numbers started from zero. For example, partition <filename
  74. class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
  75. GRUB and <filename class="partition">sdb3</filename> is
  76. <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
  77. consider CD-ROM drives to be hard drives. For example, if using a CD
  78. on <filename class="partition">hdb</filename> and a second hard drive
  79. on <filename class="partition">hdc</filename>, that second hard drive
  80. would still be <emphasis>(hd1)</emphasis>.</para-->
  81. <para>GRUB 使用一种独特的命名结构,为驱动器和分区命名。
  82. 分区名的形式为 <emphasis>(hdn,m)</emphasis>,这里
  83. <emphasis>n</emphasis> 是硬盘驱动器编号,<emphasis>m</emphasis>
  84. 是分区编号。硬盘驱动器编号从 0 开始,但分区号对于主分区来说从
  85. 1 开始,而对于扩展分区来说从 5 开始。例如,分区
  86. <filename class="partition">sda1</filename> 在 GRUB 中的名字是
  87. <emphasis>(hd0, 1)</emphasis>,而
  88. <filename class="partition">sda3</filename> 的名字是
  89. <emphasis>(hd1, 3)</emphasis>。和 Linux 不同,
  90. GRUB 不认为 CD-ROM 驱动器属于硬盘驱动器。例如,如果在
  91. <filename class="partition">hdb</filename> 上有一个 CD-ROM 驱动器,
  92. 而 <filename class="partition">hdc</filename>
  93. 上有一个次要硬盘驱动器,则第二个驱动器仍然名为
  94. <emphasis>hd1</emphasis>。</para>
  95. </sect2>
  96. <sect2>
  97. <title>设定 GRUB 配置</title>
  98. <!--para>GRUB works by writing data to the first physical track of the
  99. hard disk. This area is not part of any file system. The programs
  100. there access GRUB modules in the boot partition. The default location
  101. is /boot/grub/.</para-->
  102. <para>GRUB 的工作方式是,将数据写入硬盘的第一个物理磁道。
  103. 这里不属于任何文件系统,在启动时,
  104. 第一个物理磁道中的程序从引导分区加载 GRUB 模块,
  105. 默认在 /boot/grub 中查找模块。</para>
  106. <!--para>The location of the boot partition is a choice of the user that
  107. affects the configuration. One recommendation is to have a separate small
  108. (suggested size is 100 MB) partition just for boot information. That way
  109. each build, whether LFS or some commercial distro, can access the same boot
  110. files and access can be made from any booted system. If you choose to do
  111. this, you will need to mount the separate partition, move all files in the
  112. current <filename class="directory">/boot</filename> directory (e.g. the
  113. linux kernel you just built in the previous section) to the new partition.
  114. You will then need to unmount the partition and remount it as <filename
  115. class="directory">/boot</filename>. If you do this, be sure to update
  116. <filename>/etc/fstab</filename>.</para-->
  117. <para>引导分区的位置由负责进行配置的用户自己决定,
  118. 作者推荐创建一个小的(建议大小为 100 MB)分区,
  119. 专门存放引导信息。这样,不同的 Linux 系统(无论是 LFS
  120. 还是商业发行版)在启动时和启动后都能访问相同的引导文件。
  121. 如果您选择这样做,您需要挂载这个单独的分区,将 /boot
  122. 中已有的文件(例如上一节中构建的内核)移动到新的分区中。
  123. 之后,解除该分区的挂载,并将它挂载为
  124. <filename class="directory">/boot</filename>,
  125. 而且还要注意更新 <filename>/etc/fstab</filename>。</para>
  126. <!--para>Using the current lfs partition will also work, but configuration
  127. for multiple systems is more difficult.</para-->
  128. <para>直接使用 LFS 分区也是可以的,但这样在配置多系统启动时比较麻烦。
  129. </para>
  130. <!--para>Using the above information, determine the appropriate
  131. designator for the root partition (or boot partition, if a separate
  132. one is used). For the following example, it is assumed that the root
  133. (or separate boot) partition is <filename
  134. class="partition">sda2</filename>.</para-->
  135. <para>根据以上信息,确定 LFS 根分区(或 boot 分区)的名称。
  136. 下面假设 LFS 根分区(或 boot 分区)是
  137. <filename class="partition">sda2</filename>。</para>
  138. <para>将 GRUB 文件安装到<filename
  139. class="directory">/boot/grub</filename> 并设定引导磁道:</para>
  140. <warning>
  141. <!--para>The following command will overwrite the current boot loader. Do not
  142. run the command if this is not desired, for example, if using a third party
  143. boot manager to manage the Master Boot Record (MBR).</para-->
  144. <para>以下命令会覆盖当前启动引导器,如果这不是您希望的,
  145. 不要运行该命令。例如,如果您使用第三方启动引导器管理主引导记录
  146. (MBR)。</para>
  147. </warning>
  148. <screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
  149. <note>
  150. <para>如果系统是使用 UEFI 引导的,
  151. <command>grub-install</command> 会试图为
  152. <emphasis>x86_64-efi</emphasis> 目标安装文件,
  153. 但它们并未在第 6 章中安装。如果出现了这类问题,请在以上命令中添加
  154. <option>--target i386-pc</option> 选项。</para>
  155. </note>
  156. <!-- This does not seem to be true any more
  157. <note><para><application>grub-install</application> is a script and calls another
  158. program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
  159. If so, create a temporary symbolic link from your root partition to /dev/root:</para>
  160. <screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
  161. <para>The symbolic link will only be present until the system is rebooted.
  162. The link is only needed for the installation procedure.
  163. </para></note>
  164. -->
  165. </sect2>
  166. <sect2 id="grub-cfg">
  167. <title>创建 GRUB 配置文件</title>
  168. <para>生成 <filename>/boot/grub/grub.cfg</filename>:</para>
  169. <screen revision="sysv"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
  170. <literal># Begin /boot/grub/grub.cfg
  171. set default=0
  172. set timeout=5
  173. insmod ext2
  174. set root=(hd0,2)
  175. menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
  176. linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
  177. }</literal>
  178. EOF</userinput></screen>
  179. <screen revision="systemd"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
  180. <literal># Begin /boot/grub/grub.cfg
  181. set default=0
  182. set timeout=5
  183. insmod ext2
  184. set root=(hd0,2)
  185. menuentry "GNU/Linux, Linux &linux-version;-lfs-&versiond;" {
  186. linux /boot/vmlinuz-&linux-version;-lfs-&versiond; root=/dev/sda2 ro
  187. }</literal>
  188. EOF</userinput></screen>
  189. <note><para>从 <application>GRUB</application>的视角来看,
  190. 内核文件的位置相对于它使用的分区。如果您使用了单独的 /boot
  191. 分区,需要从上面的 <emphasis>linux</emphasis> 行删除 /boot,
  192. 然后修改 <emphasis>set root</emphasis> 行,
  193. 指向 /boot 分区。</para></note>
  194. <!--para>GRUB is an extremely powerful program and it provides a tremendous
  195. number of options for booting from a wide variety of devices, operating
  196. systems, and partition types. There are also many options for customization
  197. such as graphical splash screens, playing sounds, mouse input, etc. The
  198. details of these options are beyond the scope of this introduction.</para-->
  199. <para>GRUB 是一个很强大的程序,它提供了非常多的选项,
  200. 可以支持多种设备、操作系统和分区类型,还有很多用于定制启动屏幕、
  201. 声音、鼠标输入等的选项。这些选项的细节超过了本书的范围,
  202. 不予讨论。</para>
  203. <!--caution><para>There is a command, <application>grub-mkconfig</application>, that
  204. can write a configuration file automatically. It uses a set of scripts in
  205. /etc/grub.d/ and will destroy any customizations that you make. These scripts
  206. are designed primarily for non-source distributions and are not recommended for
  207. LFS. If you install a commercial Linux distribution, there is a good chance
  208. that this program will be run. Be sure to back up your grub.cfg file.</para></caution-->
  209. <caution><para>有一个命令 <application>grub-mkconfig</application>
  210. 被用于自动创建配置文件。它使用 /etc/grub.d
  211. 中的脚本创建新配置文件,这会覆盖您手动编写的 grub.cfg。
  212. 这些脚本主要是为非源代码发行版设计的,
  213. 在 LFS 中不推荐使用。但是,如果您安装了商业发行版,
  214. 它很可能在发行版中被运行,记得备份 grub.cfg 以防它被覆盖。
  215. </para></caution>
  216. </sect2>
  217. </sect1>