aboutlfs.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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-partitioning-aboutlfs">
  8. <?dbhtml filename="aboutlfs.html"?>
  9. <title>设置 $LFS 环境变量</title>
  10. <!--para>Throughout this book, the environment variable <envar>LFS</envar> will
  11. be used several times. You should ensure that this variable is always defined
  12. throughout the LFS build process. It should be set to the name of the
  13. directory where you will be building your LFS system - we will use
  14. <filename class="directory">/mnt/lfs</filename> as an example, but the
  15. directory choice is up to you. If you are building LFS on a separate
  16. partition, this directory will be the mount point for the partition.
  17. Choose a directory location and set the variable with the
  18. following command:</para-->
  19. <para>在本书中,我们经常使用环境变量 <envar>LFS</envar> 。您应该保证,
  20. 在构建 LFS 的全过程中,该变量都被定义且设置为您构建 LFS 使用的目录
  21. —— 我们使用 <filename class="directory">/mnt/lfs</filename> 作为例子,
  22. 但您可以选择其他目录。如果您在一个独立的分区上构建 LFS ,
  23. 那么这个目录将成为该分区的挂载点。选择一个目录,
  24. 然后用以下命令设置环境变量:</para>
  25. <screen role="nodump"><userinput>export LFS=<replaceable>/mnt/lfs</replaceable></userinput></screen>
  26. <!--para>Having this variable set is beneficial in that commands such as
  27. <command>mkdir -v $LFS/tools</command> can be typed literally. The shell
  28. will automatically replace <quote>$LFS</quote> with
  29. <quote>/mnt/lfs</quote> (or whatever the variable was set to) when it
  30. processes the command line.</para-->
  31. <para>设置该环境变量的好处是,我们可以直接输入书中的命令,例如
  32. <command>mkdir -v $LFS/tools</command> 。
  33. Shell 在解析命令时会自动将 <quote>$LFS</quote> 替换成
  34. <quote>/mnt/lfs</quote>(或是您设置的其他值)。</para>
  35. <caution>
  36. <!--para>Do not forget to check that <envar>LFS</envar> is set whenever
  37. you leave and reenter the current working environment (such as when doing a
  38. <command>su</command> to <systemitem class="username">root</systemitem> or
  39. another user). Check that the <envar>LFS</envar> variable is set up
  40. properly with:</para-->
  41. <para> 如果您离开并重新进入了工作环境 (例如使用 <command>su</command>
  42. 切换到 <systemitem class="username">root</systemitem> 或者其他用户),
  43. 请执行以下命令,检查 <envar>LFS</envar> 的设置是否正确:</para>
  44. <screen role="nodump"><userinput>echo $LFS</userinput></screen>
  45. <!--para>Make sure the output shows the path to your LFS system's build
  46. location, which is <filename class="directory">/mnt/lfs</filename> if the
  47. provided example was followed. If the output is incorrect, use the command
  48. given earlier on this page to set <envar>$LFS</envar> to the correct
  49. directory name.</para-->
  50. <para>确认该命令的输出是您构建 LFS 的位置,如果您使用本书提供的例子,
  51. 那么输出应该是 <filename class="directory">/mnt/lfs</filename>。
  52. 如果输出不正确,使用前文给出的命令,将 <envar>$LFS</envar>
  53. 设置成正确的目录名。</para>
  54. </caution>
  55. <note><!--para>One way to ensure that the <envar>LFS</envar> variable is always
  56. set is to edit the <filename>.bash_profile</filename> file in both your
  57. personal home directory and in <filename>/root/.bash_profile</filename> and
  58. enter the export command above. In addition, the shell specified in the
  59. <filename>/etc/passwd</filename> file for all users that need the
  60. <envar>LFS</envar> variable needs to be bash to ensure that the
  61. <filename>/root/.bash_profile</filename> file is incorporated as a part of
  62. the login process.</para-->
  63. <para>确保 <envar>LFS</envar> 始终正确的一种方法是:编辑您的主目录中的
  64. <filename>.bash_profile</filename> 以及
  65. <systemitem class="username">root</systemitem> 用户的
  66. <filename>/root/.bash_profile</filename>,为它们加入上述设置并导出
  67. <envar>LFS</envar> 变量的 <command>export</command> 命令。还要确认
  68. <filename>/etc/passwd</filename> 中为每个需要使用 <envar>LFS</envar>
  69. 变量的用户指定的 shell 都是 bash,以保证每次登录时都执行
  70. <filename>.bash_profile</filename> 中的命令。</para>
  71. <!--para>Another consideration is the method that is used to log into the
  72. host system. If logging in through a graphical display manager, the
  73. user's <filename>.bash_profile</filename> is not normally used when
  74. a virtual terminal is started. In this case, add the export command to
  75. the <filename>.bashrc</filename> file for the user and root. In addition,
  76. some distributions have instructions to not run the <filename>.bashrc</filename>
  77. instructions in a non-interactive bash invocation. Be sure to add the
  78. export command before the test for non-interactive use.</para-->
  79. <para>另外还要考虑登录宿主系统的方式,如果您使用图形显示管理器登录,
  80. 再启动虚拟终端,那么 <filename>.bash_profile</filename>
  81. 一般不会被虚拟终端执行。此时,应该将 <command>export</command>
  82. 命令加入到您使用的用户和
  83. <systemitem class="username">root</systemitem> 的
  84. <filename>.bashrc</filename> 文件中。另外,如果以非交互模式启动 bash,
  85. 有的发行版不会执行 <filename>.bashrc</filename> 中的指令。
  86. 此时一定要在使用环境变量前添加 <command>export</command> 命令。</para>
  87. </note>
  88. </sect1>