1
0

grub.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. <note><title>译注</title>
  65. <para>以上 hint 版本较老,译者维护了它的更新版本,参阅
  66. <ulink url="http://svn.linuxfromscratch.org/hints/trunk/lfs-uefi-20180409.txt"/>。
  67. </para>
  68. </note>
  69. </sect2>
  70. <sect2>
  71. <title>GRUB 命名惯例</title>
  72. <!--para>GRUB uses its own naming structure for drives and partitions in
  73. the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
  74. is the hard drive number and <emphasis>m</emphasis> is the partition
  75. number. The hard drive number starts from zero, but the partition number
  76. starts from one for normal partitions and five for extended partitions.
  77. Note that this is different from earlier versions where
  78. both numbers started from zero. For example, partition <filename
  79. class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
  80. GRUB and <filename class="partition">sdb3</filename> is
  81. <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
  82. consider CD-ROM drives to be hard drives. For example, if using a CD
  83. on <filename class="partition">hdb</filename> and a second hard drive
  84. on <filename class="partition">hdc</filename>, that second hard drive
  85. would still be <emphasis>(hd1)</emphasis>.</para-->
  86. <para>GRUB 使用一种独特的命名结构,为驱动器和分区命名。
  87. 分区名的形式为 <emphasis>(hdn,m)</emphasis>,这里
  88. <emphasis>n</emphasis> 是硬盘驱动器编号,<emphasis>m</emphasis>
  89. 是分区编号。硬盘驱动器编号从 0 开始,但分区号对于主分区来说从
  90. 1 开始,而对于扩展分区来说从 5 开始。例如,分区
  91. <filename class="partition">sda1</filename> 在 GRUB 中的名字是
  92. <emphasis>(hd0, 1)</emphasis>,而
  93. <filename class="partition">sda3</filename> 的名字是
  94. <emphasis>(hd1, 3)</emphasis>。和 Linux 不同,
  95. GRUB 不认为 CD-ROM 驱动器属于硬盘驱动器。例如,如果在
  96. <filename class="partition">hdb</filename> 上有一个 CD-ROM 驱动器,
  97. 而 <filename class="partition">hdc</filename>
  98. 上有一个次要硬盘驱动器,则第二个驱动器仍然名为
  99. <emphasis>hd1</emphasis>。</para>
  100. </sect2>
  101. <sect2>
  102. <title>设定 GRUB 配置</title>
  103. <!--para>GRUB works by writing data to the first physical track of the
  104. hard disk. This area is not part of any file system. The programs
  105. there access GRUB modules in the boot partition. The default location
  106. is /boot/grub/.</para-->
  107. <para>GRUB 的工作方式是,将数据写入硬盘的第一个物理磁道。
  108. 这里不属于任何文件系统,在启动时,
  109. 第一个物理磁道中的程序从引导分区加载 GRUB 模块,
  110. 默认在 /boot/grub 中查找模块。</para>
  111. <!--para>The location of the boot partition is a choice of the user that
  112. affects the configuration. One recommendation is to have a separate small
  113. (suggested size is 100 MB) partition just for boot information. That way
  114. each build, whether LFS or some commercial distro, can access the same boot
  115. files and access can be made from any booted system. If you choose to do
  116. this, you will need to mount the separate partition, move all files in the
  117. current <filename class="directory">/boot</filename> directory (e.g. the
  118. linux kernel you just built in the previous section) to the new partition.
  119. You will then need to unmount the partition and remount it as <filename
  120. class="directory">/boot</filename>. If you do this, be sure to update
  121. <filename>/etc/fstab</filename>.</para-->
  122. <para>引导分区的位置由负责进行配置的用户自己决定,
  123. 作者推荐创建一个小的(建议大小为 100 MB)分区,
  124. 专门存放引导信息。这样,不同的 Linux 系统(无论是 LFS
  125. 还是商业发行版)在启动时和启动后都能访问相同的引导文件。
  126. 如果您选择这样做,您需要挂载这个单独的分区,将 /boot
  127. 中已有的文件(例如上一节中构建的内核)移动到新的分区中。
  128. 之后,解除该分区的挂载,并将它挂载为
  129. <filename class="directory">/boot</filename>,
  130. 而且还要注意更新 <filename>/etc/fstab</filename>。</para>
  131. <!--para>Using the current lfs partition will also work, but configuration
  132. for multiple systems is more difficult.</para-->
  133. <para>直接使用 LFS 分区也是可以的,但这样在配置多系统启动时比较麻烦。
  134. </para>
  135. <!--para>Using the above information, determine the appropriate
  136. designator for the root partition (or boot partition, if a separate
  137. one is used). For the following example, it is assumed that the root
  138. (or separate boot) partition is <filename
  139. class="partition">sda2</filename>.</para-->
  140. <para>根据以上信息,确定 LFS 根分区(或 boot 分区)的名称。
  141. 下面假设 LFS 根分区(或 boot 分区)是
  142. <filename class="partition">sda2</filename>。</para>
  143. <para>将 GRUB 文件安装到<filename
  144. class="directory">/boot/grub</filename> 并设定引导磁道:</para>
  145. <warning>
  146. <!--para>The following command will overwrite the current boot loader. Do not
  147. run the command if this is not desired, for example, if using a third party
  148. boot manager to manage the Master Boot Record (MBR).</para-->
  149. <para>以下命令会覆盖当前启动引导器,如果这不是您希望的,
  150. 不要运行该命令。例如,如果您使用第三方启动引导器管理主引导记录
  151. (MBR)。</para>
  152. </warning>
  153. <screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
  154. <!-- This does not seem to be true any more
  155. <note><para><application>grub-install</application> is a script and calls another
  156. program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
  157. If so, create a temporary symbolic link from your root partition to /dev/root:</para>
  158. <screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
  159. <para>The symbolic link will only be present until the system is rebooted.
  160. The link is only needed for the installation procedure.
  161. </para></note>
  162. -->
  163. </sect2>
  164. <sect2 id="grub-cfg">
  165. <title>创建 GRUB 配置文件</title>
  166. <para>生成 <filename>/boot/grub/grub.cfg</filename>:</para>
  167. <screen revision="sysv"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
  168. <literal># Begin /boot/grub/grub.cfg
  169. set default=0
  170. set timeout=5
  171. insmod ext2
  172. set root=(hd0,2)
  173. menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
  174. linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
  175. }</literal>
  176. EOF</userinput></screen>
  177. <screen revision="systemd"><userinput>cat &gt; /boot/grub/grub.cfg &lt;&lt; "EOF"
  178. <literal># Begin /boot/grub/grub.cfg
  179. set default=0
  180. set timeout=5
  181. insmod ext2
  182. set root=(hd0,2)
  183. menuentry "GNU/Linux, Linux &linux-version;-lfs-&versiond;" {
  184. linux /boot/vmlinuz-&linux-version;-lfs-&versiond; root=/dev/sda2 ro
  185. }</literal>
  186. EOF</userinput></screen>
  187. <note><para>从 <application>GRUB</application>的视角来看,
  188. 内核文件的位置相对于它使用的分区。如果您使用了单独的 /boot
  189. 分区,需要从上面的 <emphasis>linux</emphasis> 行删除 /boot,
  190. 然后修改 <emphasis>set root</emphasis> 行,
  191. 指向 /boot 分区。</para></note>
  192. <!--para>GRUB is an extremely powerful program and it provides a tremendous
  193. number of options for booting from a wide variety of devices, operating
  194. systems, and partition types. There are also many options for customization
  195. such as graphical splash screens, playing sounds, mouse input, etc. The
  196. details of these options are beyond the scope of this introduction.</para-->
  197. <para>GRUB 是一个很强大的程序,它提供了非常多的选项,
  198. 可以支持多种设备、操作系统和分区类型,还有很多用于定制启动屏幕、
  199. 声音、鼠标输入等的选项。这些选项的细节超过了本书的范围,
  200. 不予讨论。</para>
  201. <!--caution><para>There is a command, <application>grub-mkconfig</application>, that
  202. can write a configuration file automatically. It uses a set of scripts in
  203. /etc/grub.d/ and will destroy any customizations that you make. These scripts
  204. are designed primarily for non-source distributions and are not recommended for
  205. LFS. If you install a commercial Linux distribution, there is a good chance
  206. that this program will be run. Be sure to back up your grub.cfg file.</para></caution-->
  207. <caution><para>有一个命令 <application>grub-mkconfig</application>
  208. 被用于自动创建配置文件。它使用 /etc/grub.d
  209. 中的脚本创建新配置文件,这会覆盖您手动编写的 grub.cfg。
  210. 这些脚本主要是为非源代码发行版设计的,
  211. 在 LFS 中不推荐使用。但是,如果您安装了商业发行版,
  212. 它很可能在发行版中被运行,记得备份 grub.cfg 以防它被覆盖。
  213. </para></caution>
  214. </sect2>
  215. </sect1>