- In this chapter, we enter the building site and start constructing
- the LFS system in earnest. That is, we chroot into the temporary mini
- Linux system, make a few final preparations, and then begin
- installing the packages.
+ 在本章中,我们进入构建页面,开始认真构建 LFS 系统。也就是说,我们需要 chroot 到临时的迷你 Linux 系统,做一些最后的准备,然后开始安装软件包。
- The installation of this software is straightforward. Although in
- many cases the installation instructions could be made shorter and
- more generic, we have opted to provide the full instructions for
- every package to minimize the possibilities for mistakes. The key to
- learning what makes a Linux system work is to know what each package
- is used for and why you (or the system) may need it.
+ 安装这些软件很简单。虽然在很多情况下安装说明可以做得更短,更通用,但是我们选择提供每个包的完整说明给大家,以尽量减少产生错误的可能性。学习 Linux 系统如何工作的关键是知道每个软件包是用来干什么以及你(或者系统)为什么需要它。
- We do not recommend using optimizations. They can make a program run
- slightly faster, but they may also cause compilation difficulties and
- problems when running the program. If a package refuses to compile
- when using optimization, try to compile it without optimization and
- see if that fixes the problem. Even if the package does compile when
- using optimization, there is the risk it may have been compiled
- incorrectly because of the complex interactions between the code and
- build tools. Also note that the -march
- and -mtune options using values not
- specified in the book have not been tested. This may cause problems
- with the toolchain packages (Binutils, GCC and Glibc). The small
- potential gains achieved in using compiler optimizations are often
- outweighed by the risks. First-time builders of LFS are encouraged to
- build without custom optimizations. The subsequent system will still
- run very fast and be stable at the same time.
+ 我们不建议使用最优化配置。它们可以使程序运行速度略快,但可能导致编译更困难或者程序运行时出现问题。如果某个包在使用优化时编译出错,请尝试在没有优化的情况下编译它,看看是否能解决问题。即使软件包在使用优化时进行编译,由于代码和构建工具之间复杂的交互,也有编译不正确的风险。另请注意,-march 和 -mtune 选项尚未测试,他们使用了未作详细说明的值。这可能会导致工具链包(Binutils,GCC 和 Glibc)出现问题。在使用编译器优化时实现的一点潜在增益通常会被其风险所抵消。建议首次构建 LFS 的人无需自定义优化。后续系统仍将运行非常快,同时也很稳定。
- The order that packages are installed in this chapter needs to be
- strictly followed to ensure that no program accidentally acquires a
- path referring to /tools hard-wired
- into it. For the same reason, do not compile separate packages in
- parallel. Compiling in parallel may save time (especially on dual-CPU
- machines), but it could result in a program containing a hard-wired
- path to /tools, which will cause the
- program to stop working when that directory is removed.
+ 本章中安装软件包的顺序需要严格遵守,因为安装某些程序需要引用硬链接到 /tools 的路径,这样做可以确保这些程序不会产生这种意外的问题。同样,也不要并行编译单独的包。虽然并行编译可以节省时间(特别是在双CPU机器上),但它可能会影响到包含在 /tools 的硬连线路径中的程序,这将导致程序在该目录被删除时停止工作。
- Before the installation instructions, each installation page provides
- information about the package, including a concise description of
- what it contains, approximately how long it will take to build, and
- how much disk space is required during this building process.
- Following the installation instructions, there is a list of programs
- and libraries (along with brief descriptions of these) that the
- package installs.
+ 在进行安装说明之前,每个安装页面都会提供相关软件包的信息,包括其中包含内容的简述,大约需要的构建时长,以及在构建过程中需要多少磁盘空间。安装说明中会有一个安装软件包所需程序和库的列表(以及它们的简要说明)。
- Note
+ 注意
- The SBU values and required disk space includes test suite data for
- all applicable packages in Chapter 6.
+ SBU 值和所需硬盘空间包含第6章所有适用软件包的测试套件数据。
- 6.1.1. About libraries
+ 6.1.1. 关于函数库
- In general, the LFS editors discourage building and installing
- static libraries. The original purpose for most static libraries
- has been made obsolete in a modern Linux system. In addition
- linking a static library into a program can be detrimental. If an
- update to the library is needed to remove a security problem, all
- programs that use the static library will need to be relinked to
- the new library. Since the use of static libraries is not always
- obvious, the relevant programs (and the procedures needed to do the
- linking) may not even be known.
+ 一般来说,LFS 编辑器不鼓励构建和安装静态库。大多数静态库的最初目的在现代 Linux 系统中已经过时了。另外,将静态库链接到程序中可能是有害的。如果为了消除一个安全问题而需要更新一个静态库,那么使用这个静态库的所有程序都需要重新链接到新库。因为静态库的作用并不总是很明显,相关程序(以及执行链接所需的过程)甚至可能是未知的。
- In the procedures in Chapter 6, we remove or disable installation
- of most static libraries. In a few cases, especially glibc and gcc,
- the use of static libraries remains essential to the general
- package building process. Usually this is done by passing a
- --disable-static option to configure. In other cases,
- alternate means are needed.
+ 在介绍第6章的过程中,我们去除或禁用了大多数静态库的安装。在少数情况下,特别是 glibc 和 gcc,静态库的使用对于一般的包构建过程仍然是至关重要的。通常这要通过传递一个 --disable-static 选项给 configure 来完成。在其他情况下,需要其它替代方法。
- For a more complete discussion of libraries, see the discussion
+ 有关函数库的更详细的讨论,见 BLFS 中的论述
- Libraries: Static or shared? in the BLFS book.
+ Libraries: Static or shared?
From 194ca1c59832ad6cd155e07cd68b8c06738d8fbb Mon Sep 17 00:00:00 2001
From: Jay Liu
Date: Fri, 10 Mar 2017 13:51:05 +0800
Subject: [PATCH 02/20] modified 6.1 introduction.html
---
lfs-8.0/chapter06/introduction.html | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lfs-8.0/chapter06/introduction.html b/lfs-8.0/chapter06/introduction.html
index 7a01b70..f874b72 100644
--- a/lfs-8.0/chapter06/introduction.html
+++ b/lfs-8.0/chapter06/introduction.html
@@ -19,26 +19,26 @@
一般来说,LFS 编辑器不鼓励构建和安装静态库。大多数静态库的最初目的在现代 Linux 系统中已经过时了。另外,将静态库链接到程序中可能是有害的。如果为了消除一个安全问题而需要更新一个静态库,那么使用这个静态库的所有程序都需要重新链接到新库。因为静态库的作用并不总是很明显,相关程序(以及执行链接所需的过程)甚至可能是未知的。
- Various file systems exported by the kernel are used to communicate
- to and from the kernel itself. These file systems are virtual in that
- no disk space is used for them. The content of the file systems
- resides in memory.
+ 由内核导出的各种文件系统用于与内核本身进行通信。这些文件系统是虚拟的,因为它们不使用磁盘空间。这些文件系统的内容驻留在内存中。
- Begin by creating directories onto which the file systems will be
- mounted:
+ 首先创建将要挂载文件系统的目录:
- When the kernel boots the system, it requires the presence of a few
- device nodes, in particular the console and null
- devices. The device nodes must be created on the hard disk so that
- they are available before udevd has been started, and
- additionally when Linux is started with init=/bin/bash. Create the devices by
- running the following commands:
+ 当内核引导系统时,它需要存在几个设备节点,特别是 console 和 null 设备。设备节点必须在硬盘上创建,以便在启动 udevd 之前可用,此外,当使用 init=/bin/bash 启动 Linux 时。通过运行以下命令创建设备:
6.2.2.
- Mounting and Populating /dev
+ 安装和填充 /dev
- The recommended method of populating the /dev directory with devices is to mount a virtual
- filesystem (such as tmpfs) on the
- /dev directory, and allow the devices
- to be created dynamically on that virtual filesystem as they are
- detected or accessed. Device creation is generally done during the
- boot process by Udev. Since this new system does not yet have Udev
- and has not yet been booted, it is necessary to mount and populate
- /dev manually. This is accomplished
- by bind mounting the host system's /dev directory. A bind mount is a special type of
- mount that allows you to create a mirror of a directory or mount
- point to some other location. Use the following command to achieve
- this:
+ 推荐的用设备填充 /dev 目录的方法是在 /dev 目录上挂载虚拟文件系统(如 tmpfs),并允许在检测或访问设备时动态创建该虚拟文件系统。设备创建通常由 Udev 在引导过程中完成。由于这个新系统还没有 Udev 并且尚未启动,因此需要手动安装和填充 /dev。这是通过绑定挂载主机系统的 /dev 目录来实现的。绑定挂载是特殊类型的挂载,它允许你创建目录的镜像或指向其他位置的挂载点。使用以下命令实现此目的:
mount -v --bind /dev $LFS/dev
@@ -112,11 +87,10 @@
6.2.3. Mounting Virtual Kernel File
- Systems
+ "ch-system-kernfsmount">6.2.3. 挂载虚拟内核文件系统
- Now mount the remaining virtual kernel filesystems:
+ 现在挂载剩下的虚拟内核文件系统:
- The meaning of the mount options for devpts:
+ 挂载选项 devpts 的含义:
@@ -135,12 +109,7 @@
- This ensures that all devpts-created device nodes are owned
- by group ID 5. This is the ID we will use later on for the
- tty group. We use the group
- ID instead of a name, since the host system might use a
- different ID for its tty
- group.
+ 该选项确保所有 devpts 创建的设备节点都属于 ID 为 5 的组。这个 ID 我们之后将用于 tty 组。我们使用组 ID 而不是名称,因为主机系统可能为其 tty 组使用不同的 ID。
@@ -149,13 +118,7 @@
- This ensures that all devpts-created device nodes have mode
- 0620 (user readable and writable, group writable). Together
- with the option above, this ensures that devpts will create
- device nodes that meet the requirements of grantpt(), meaning
- the Glibc pt_chown helper binary
- (which is not installed by default) is not necessary.
+ 该选项确保所有 devpts 创建的设备节点处于 0620 模式(用户可读写,组可写)。与上面的选项一起,这确保 devpts 将创建满足 grantpt() 的要求的设备节点,这意味着 Glibc pt_chown 辅助程序二进制文件(默认情况下不安装)是不必要的。
@@ -165,6 +128,7 @@
symbolic link to /run/shm. The /run
tmpfs was mounted above so in this case only a directory needs to
be created.
+ 在某些主机系统中,/dev/shm 是指向 /run/shm 的符号链接。/run 目录的 tmpfs 已经挂载了,所以现在只需要创建一个目录。
if [ -h $LFS/dev/shm ]; then
@@ -177,25 +141,25 @@
- Package Management is an often requested addition to the LFS Book. A
- Package Manager allows tracking the installation of files making it
- easy to remove and upgrade packages. As well as the binary and
- library files, a package manager will handle the installation of
- configuration files. Before you begin to wonder, NO—this
- section will not talk about nor recommend any particular package
- manager. What it provides is a roundup of the more popular techniques
- and how they work. The perfect package manager for you may be among
- these techniques or may be a combination of two or more of these
- techniques. This section briefly mentions issues that may arise when
- upgrading packages.
+ 软件包管理是 LFS 手册中经常需要添加的。软件包管理器可以跟踪文件的安装,以便删除和升级软件包。除了二进制和库文件,包管理器还会处理配置文件的安装。然而需要告诉你的是,这一节不会谈论和推荐任何特定的包管理器。它提供了一个更流行的技术并且说明了它们如何工作。最适合你的包管理器可能是这些技术之中的一个,或者是这些技术中的两个或多个的组合。本节简要介绍升级软件包时可能出现的问题。
- Some reasons why no package manager is mentioned in LFS or BLFS
- include:
+ 在 LFS 或 BLFS 中未提及软件包管理器的一些原因包括:
- Dealing with package management takes the focus away from the
- goals of these books—teaching how a Linux system is
- built.
+ 处理包管理使得关注焦点远离这些书的目标 — 教授如何构建Linux系统。
- There are multiple solutions for package management, each
- having its strengths and drawbacks. Including one that
- satisfies all audiences is difficult.
+ 有很多用于包管理的解决方案,每个都各有优缺点。其中一条就是满足所有用户是困难的。
- There are some hints written on the topic of package management.
- Visit the Hints Project
- and see if one of them fits your need.
+ 有一些关于包管理的提示。访问 Hints Project,看看是否有一个适合你的需求。
- 6.3.1. Upgrade Issues
+ 6.3.1. 升级问题
- A Package Manager makes it easy to upgrade to newer versions when
- they are released. Generally the instructions in the LFS and BLFS
- Book can be used to upgrade to the newer versions. Here are some
- points that you should be aware of when upgrading packages,
- especially on a running system.
+ 软件包管理器可以在软件发布时轻松升级到较新的版本。通常,LFS 和 BLFS 手册中的指令可用来升级到较新版本。以下是升级软件包时应注意的一些问题,尤其是在正在运行的系统上。
- If Glibc needs to be upgraded to a newer version, (e.g. from
- glibc-2.19 to glibc-2.20, it is safer to rebuild LFS. Though
- you may be able to
- rebuild all the packages in their dependency order, we do not
- recommend it.
+ 如果 Glibc 需要升级到更新的版本(例如,从 glibc-2.19 升级到 glibc-2.20,重建 LFS 会更安全)。虽然你可以重建所有顺序依赖的包,但我们不推荐这样做。
- If a package containing a shared library is updated, and if
- the name of the library changes, then all the packages
- dynamically linked to the library need to be recompiled to
- link against the newer library. (Note that there is no
- correlation between the package version and the name of the
- library.) For example, consider a package foo-1.2.3 that
- installs a shared library with name libfoo.so.1. Say you upgrade the package to
- a newer version foo-1.2.4 that installs a shared library with
- name libfoo.so.2. In this case,
- all packages that are dynamically linked to libfoo.so.1 need to be recompiled to link
- against libfoo.so.2. Note that
- you should not remove the previous libraries until the
- dependent packages are recompiled.
+ 如果一个包含共享库的包更新,并且库的名称有更改,则动态链接到库的所有包都需要重新编译以链接到较新的库(注意,软件包版本和软件包名称之间没有关系)。例如,考虑一个软件包 foo-1.2.3,它安装一个名为 libfoo.so.1 的共享库。假如你要将包升级到更新的版本 foo-1.2.4,而它会安装一个名为 libfoo.so.2 的共享库。在这种情况下,动态链接到 libfoo.so.1 的所有软件包都需要重新编译以链接到 libfoo.so.2。请注意,在重新编译依赖包之前,不应删除原来的库。
- The following are some common package management techniques. Before
- making a decision on a package manager, do some research on the
- various techniques, particularly the drawbacks of the particular
- scheme.
+ 以下是一些常见的软件包管理技技术。在决定用什么包管理器之前,最好研究一下各种技术,尤其是了解特定方案的缺点。
- 6.3.2.1. It is All in My Head!
+ 6.3.2.1. 所有东西都在我脑袋里!
- Yes, this is a package management technique. Some folks do not
- find the need for a package manager because they know the
- packages intimately and know what files are installed by each
- package. Some users also do not need any package management
- because they plan on rebuilding the entire system when a package
- is changed.
+ 是的,这也是一种包管理技术。有些人可能没有对包管理器的需求,因为他们很熟悉软件包,而且知道每个软件包会安装哪些文件。也有些不需要包管理器的人是因为他们打算在更改某个软件包的时候重建整个系统。
- 6.3.2.2. Install in Separate Directories
+ 6.3.2.2. 安装在单独的目录里
- This is a simplistic package management that does not need any
- extra package to manage the installations. Each package is
- installed in a separate directory. For example, package foo-1.1
- is installed in /usr/pkg/foo-1.1
- and a symlink is made from /usr/pkg/foo to /usr/pkg/foo-1.1. When installing a new version
- foo-1.2, it is installed in /usr/pkg/foo-1.2 and the previous symlink is
- replaced by a symlink to the new version.
+ 这是一个简单的包管理方式,不需要任何额外的软件包来管理安装。每个包都安装在单独的目录中。例如,包 foo-1.1 安装在 /usr/pkg/foo-1.1 中,并创建由 /usr/pkg/foo 到 /usr/pkg/foo-1.1 的符号链接。当安装新版本 foo-1.2 时,将它安装在 /usr/pkg/foo-1.2 中,之前的符号链接替换为新版本的符号链接。
- Environment variables such as PATH,
- LD_LIBRARY_PATH, MANPATH, INFOPATH and
- CPPFLAGS need to be expanded to
- include /usr/pkg/foo. For more than
- a few packages, this scheme becomes unmanageable.
+ PATH, LD_LIBRARY_PATH, MANPATH, INFOPATH 和 CPPFLAGS 等环境变量都需要包含/ usr / pkg / foo。如果有很多软件包,这个方案就很难管理了。
- This is a variation of the previous package management technique.
- Each package is installed similar to the previous scheme. But
- instead of making the symlink, each file is symlinked into the
- /usr hierarchy. This removes the
- need to expand the environment variables. Though the symlinks can
- be created by the user to automate the creation, many package
- managers have been written using this approach. A few of the
- popular ones include Stow, Epkg, Graft, and Depot.
+ 这是上一种包管理技术的一个变体。每个软件包都用相同的方式安装。但是,这种方式不是创建目录的符号链接,而是将每个文件在 /usr 目录结构中创建符号链接。这样就不再需要扩展环境变量了。虽然用户可以创建符号链接来实现自动化,但是许多软件包管理器都已经使用了这种方法来编写。几个比较流行的有 Stow,Epkg,Graft 和 Depot。
- The installation needs to be faked, so that the package thinks
- that it is installed in /usr though
- in reality it is installed in the /usr/pkg hierarchy. Installing in this manner
- is not usually a trivial task. For example, consider that you are
- installing a package libfoo-1.1. The following instructions may
- not install the package properly:
+ 这种安装方式安装伪装,以使软件包认为它被安装在 /usr 中,但实际上它安装在 /usr/pkg 层次结构中。用这种方式安装通常都不是一件简单的工作。例如,假设你正在安装 libfoo-1.1 软件包。以下指令可能无法正确安装包:
- The installation will work, but the dependent packages may not
- link to libfoo as you would expect. If you compile a package that
- links against libfoo, you may notice that it is linked to
- /usr/pkg/libfoo/1.1/lib/libfoo.so.1
- instead of /usr/lib/libfoo.so.1 as
- you would expect. The correct approach is to use the DESTDIR strategy to fake installation of the
- package. This approach works as follows:
+ 这样安装后可以工作,但依赖软件包可能不会像你所期望的那样链接到libfoo。如果你编译一个链接到libfoo的包,你可能会注意到它被链接到 /usr/pkg/libfoo/1.1/lib/libfoo.so.1 而不是你期望的 /usr/lib/libfoo.so.1。正确的方法是使用 DESTDIR 策略来伪装软件包的安装。此方法的工作原理如下:
./configure --prefix=/usr
@@ -228,125 +150,65 @@
make DESTDIR=/usr/pkg/libfoo/1.1 install
- Most packages support this approach, but there are some which do
- not. For the non-compliant packages, you may either need to
- manually install the package, or you may find that it is easier
- to install some problematic packages into /opt.
+ 大多数软件包都支持这种方法,但是也有一些不支持。对于非兼容包,你可能需要手动安装这些包,或许你会发现这样更容易将一些有问题的软件包安装到 /opt。
- 6.3.2.4. Timestamp Based
+ 6.3.2.4. 基于时间戳
- In this technique, a file is timestamped before the installation
- of the package. After the installation, a simple use of the
- find command with
- the appropriate options can generate a log of all the files
- installed after the timestamp file was created. A package manager
- written with this approach is install-log.
+ 这种技术里,在安装软件包之前会创建文件的时间戳。安装后,一个简单的带有合适参数的 find 命令可以产生在时间戳被创建后安装的所有文件的日志。有一种使用这种方法的包管理器是 install-log。
- Though this scheme has the advantage of being simple, it has two
- drawbacks. If, during installation, the files are installed with
- any timestamp other than the current time, those files will not
- be tracked by the package manager. Also, this scheme can only be
- used when one package is installed at a time. The logs are not
- reliable if two packages are being installed on two different
- consoles.
+ 虽然这个方案的优点是简单,但它也有两个缺点。在安装期间,如果被安装的文件的时间戳与当前的时间不同,这些文件就不会被包管理器追踪。同时,这种方案只适用于同一时间只有一个包被安装的情况。如果在两个不同终端下同时安装两个软件包,那产生的日志是不可靠的。
- In this approach, the commands that the installation scripts
- perform are recorded. There are two techniques that one can use:
+ 在这种方法中,安装脚本执行的命令都会被记录下来。对此,有两种技术,其中一种可以这样用:
- The LD_PRELOAD environment variable
- can be set to point to a library to be preloaded before
- installation. During installation, this library tracks the
- packages that are being installed by attaching itself to various
- executables such as cp, install, mv and tracking the system
- calls that modify the filesystem. For this approach to work, all
- the executables need to be dynamically linked without the suid or
- sgid bit. Preloading the library may cause some unwanted
- side-effects during installation. Therefore, it is advised that
- one performs some tests to ensure that the package manager does
- not break anything and logs all the appropriate files.
+ 可以设置环境变量 LD_PRELOAD 指向一个在安装前预加载的库。安装过程中,此库通过将自身附加到各种可执行文件(如 cp, install, mv)并跟踪修改文件系统的系统调用来跟踪要安装的软件包。对于这种工作方式,所有可执行文件都需要动态链接,无需使用 suid 或 sgid 位。预加载库可能导致安装过程中不必要的副作用。因此,建议您执行一些测试以确保软件包管理器不会破坏任何内容并记录所有相应的文件。
- The second technique is to use strace, which logs all system
- calls made during the execution of the installation scripts.
+ 第二种技术是使用 strace 来记录执行安装脚本期间所有的系统调用
- In this scheme, the package installation is faked into a separate
- tree as described in the Symlink style package management. After
- the installation, a package archive is created using the
- installed files. This archive is then used to install the package
- either on the local machine or can even be used to install the
- package on other machines.
+ 在这种方案中,软件包被伪装安装到一个单独的目录树,就如符号链接软件包管理中描述的。安装后,使用已安装的文件创建包存档。然后,此存档用于在本地机器上安装软件包,甚至可以用于在其他计算机上安装软件包。
- 6.3.2.7. User Based Management
+ 6.3.2.7. 基于用户的包管理
- This scheme, unique to LFS, was devised by Matthias Benkmann, and
- is available from the Hints
- Project. In this scheme, each package is installed as a
- separate user into the standard locations. Files belonging to a
- package are easily identified by checking the user ID. The
- features and shortcomings of this approach are too complex to
- describe in this section. For the details please see the hint at
- Hints Project 获得。在此方案中,每个包都作为单独的用户安装到标准位置。通过检查用户 ID 可以容易地识别属于包的文件。这种方法的特点和缺点太复杂,无法在本节中进行描述。有关详细信息,请参阅
- http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt.
+ http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt 上的提示。
- 6.3.3. Deploying LFS on Multiple Systems
+ 6.3.3. 在多系统上部署 LFS
One of the advantages of an LFS system is that there are no files
@@ -367,30 +229,24 @@
- A custom kernel may need to be built for the new system depending
- on differences in system hardware and the original kernel
- configuration.
+ 可能需要为新系统构建定制内核,具体取决于系统硬件和原始内核配置的不同。
- Note
+ 注意
- There have been some reports of issues when copying between
- similar but not identical architectures. For instance, the
- instruction set for an Intel system is not identical with an AMD
- processor and later versions of some processors may have
- instructions that are unavailable in earlier versions.
+ 在类似但不相同的体系结构之间进行复制时,有一些问题会报错。例如,英特尔系统的指令集与 AMD 处理器不相同,新版本的某些处理器可能具有早期版本中不可用的指令。
- It is time to enter the chroot environment to begin building and
- installing the final LFS system. As user root, run the following command to enter the
- realm that is, at the moment, populated with only the temporary
- tools:
+ 现在是时候进入 chroot 环境开始构建和安装最终的 LFS 系统了。以 root 用户运行以下命令进入现在只含有一些临时工具的“空间”:
- The -i option given to the
- env command will clear
- all variables of the chroot environment. After that, only the
- HOME, TERM,
- PS1, and PATH
- variables are set again. The TERM=$TERM construct will set the
- TERM variable inside chroot to the same
- value as outside chroot. This variable is needed for programs like
- vim and less to operate properly. If other
- variables are needed, such as CFLAGS or
- CXXFLAGS, this is a good place to set them
- again.
+ env 命令的 -i 选项将清除 chroot 环境的所有变量。随后,只有 HOME,TERM,PS1 和 PATH 变量会被重新设置。TERM=$TERM 语句将会把 chroot 内的 TERM 变量的值设置为与外部 chroot 相同。对于像 vim 和 less 这样的程序,需要这个变量以保证其正常运行。如果需要其他变量,如 CFLAGS 或
+ CXXFLAGS,就在这个地方设置会比较好。
- From this point on, there is no need to use the LFS variable anymore, because all work will be
- restricted to the LFS file system. This is because the Bash shell is
- told that $LFS is now the root
- (/) directory.
+ 从这里以后,就不再需要 LFS 变量了,因为所有的工作都将被限制在 LFS 文件系统中。这是因为我们已经告诉 Bash shell $LFS 现在是根(/)目录。
- Notice that /tools/bin comes last in
- the PATH. This means that a temporary tool
- will no longer be used once its final version is installed. This
- occurs when the shell does not “remember” the
- locations of executed binaries—for this reason, hashing is
- switched off by passing the +h option to bash.
+ 注意 /tools/bin 放在了 PATH 中的最后。这意味着一旦安装了最终版本,就不再使用临时工具。当 shell 没有“记住”执行的二进制文件的位置时,就会发生这种情况。因此,需要给 bash 加上 +h 参数,以关闭哈希功能。
- Note that the bash
- prompt will say I have no name!
- This is normal because the /etc/passwd
- file has not been created yet.
+ 还需注意 bash 会提示 I have no name! 这通常是因为没有创建 /etc/passwd 文件。
- Note
+ 注意
- It is important that all the commands throughout the remainder of
- this chapter and the following chapters are run from within the
- chroot environment. If you leave this environment for any reason
- (rebooting for example), ensure that the virtual kernel filesystems
- are mounted as explained in Section 6.2.2,
- “Mounting and Populating /dev” and Section 6.2.3,
- “Mounting Virtual Kernel File Systems” and enter
- chroot again before continuing with the installation.
+ 需要重视,本章从这以后的命令,以及后续章节里的命令都要在 chroot 环境下运行。如果因为某种原因(比如说重启)离开了这个环境,请保证要按照 6.2.2,“挂载和激活 /dev” 和 6.2.3,“挂载虚拟内核文件系统” 里所说的那样挂载虚拟内核文件系统,然后在继续构建之前重新运行 chroot 进入环境。
- It is time to create some structure in the LFS file system. Create a
- standard directory tree by issuing the following commands:
+ 现在准备创建 LFS 文件系统里的一些目录结构。使用下面的命令创建一个标准的目录树:
- Directories are, by default, created with permission mode 755, but
- this is not desirable for all directories. In the commands above, two
- changes are made—one to the home directory of user root, and another to the directories for
- temporary files.
+ 一般目录默认会按 755 的权限创建,但是这并不适用于所有的目录。在上面的命令里,有两个改动 —— 一个是 root 用户的主目录,另一个是存放临时文件的目录。
- The first mode change ensures that not just anybody can enter the
- /root directory—the same as a
- normal user would do with his or her home directory. The second mode
- change makes sure that any user can write to the /tmp and /var/tmp
- directories, but cannot remove another user's files from them. The
- latter is prohibited by the so-called “sticky bit,”
- the highest bit (1) in the 1777 bit mask.
+ 第一个模式改动能保证不是所有人都能进入 /root 目录 —— 同样,一般用户也需要为他/她的家目录设置这样的模式。第二个模式改动能保证所有用户都可以写目录 /tmp 和 /var/tmp。还增加了一个所谓的“粘滞位”的限制,即位掩码 0x1777 中的最高位(1)。
- 6.5.1. FHS Compliance Note
+ 6.5.1. 关于 FHS 兼容性
- The directory tree is based on the Filesystem Hierarchy Standard
- (FHS) (available at https://wiki.linuxfoundation.org/en/FHS).
- The FHS also stipulates the optional existence some directories
- such as /usr/local/games and
- /usr/share/games. We create only the
- directories that are needed. However, feel free to create these
- directories.
+ 这个目录树是基于文件系统目录结构标准(FHS)(参见 https://wiki.linuxfoundation.org/en/FHS)。FHS 标准还规定了要有 /usr/local/games 和 /usr/share/games 目录。我们只需要创建我们需要的文件。当然,你也可以自由地创建这些目录。
6.6.
- Creating Essential Files and Symlinks
+ 创建必需文件和符号链接
- Some programs use hard-wired paths to programs which do not exist
- yet. In order to satisfy these programs, create a number of symbolic
- links which will be replaced by real files throughout the course of
- this chapter after the software has been installed:
+ 有些程序里会使用写死的路径调用其它暂时还未安装的程序。为了满足这些程序的需要,这些软件会安装好后,我们将创建一些符号链接,并替代贯穿本章教程的实际文件:
- This pathname is hard-coded into Glibc's configure script.
+ 这个路径名在 Glibc 配置脚本中是被写死的。
@@ -95,8 +91,7 @@
- This is to satisfy one of the tests in Glibc's test suite,
- which expects /bin/echo.
+ 这个是为了满足 Glibc 测试套件里的一个测试用例,它会检测 /bin/echo.
@@ -105,8 +100,7 @@
- Some configure
- scripts, particularly Glibc's, have this pathname hard-coded.
+ 一些 configure 脚本, 特别是 Glibc 的,写死了这个路径.
@@ -115,8 +109,7 @@
- This pathname is hard-coded into Expect, therefore it is needed
- for Binutils and GCC test suites to pass.
+ 这个路径名在 Expect 中也是固定的,因此在 Binutils 和 GCC 测试套件中需要它。
@@ -125,8 +118,7 @@
- Many Perl scripts hard-code this path to the perl program.
+ 许多 Perl 脚本写死了这个调用 perl 执行程序的路径。
@@ -135,7 +127,7 @@
- Glibc needs this for the pthreads library to work.
+ Glibc 需要这个让 pthreads 库正常工作。
@@ -144,8 +136,7 @@
- This is needed by several tests in Glibc's test suite, as well
- as for C++ support in GMP.
+ 在 Glibc 的一些测试套件中需要这个,而且在 GMP 的 C++ 支持中也会需要。
@@ -154,9 +145,7 @@
- This prevents a /tools reference
- that would otherwise be in /usr/lib/libstdc++.la after GCC is installed.
+ 这可以防止在安装 GCC 之后 /usr/lib/libstdc++.la 中对 /tools 的引用。
@@ -165,33 +154,24 @@
- Many shell scripts hard-code /bin/sh.
- Historically, Linux maintains a list of the mounted file systems in
- the file /etc/mtab. Modern kernels
- maintain this list internally and exposes it to the user via the
- /proc filesystem. To satisfy utilities
- that expect the presence of /etc/mtab,
- create the following symbolic link:
+ 历史上,Linux 在 /etc/mtab 文件中保存挂载文件系统的列表。而现代内核在内部维护此列表,并通过 /proc 文件系统将其公开给用户。为了满足一些依赖 /etc/mtab 的应用程序,需要创建以下符号链接:
ln -sv /proc/self/mounts /etc/mtab
- In order for user root to be able to
- login and for the name “root” to be recognized, there must be
- relevant entries in the /etc/passwd and
- /etc/group files.
+ 为了使用户 root 能够登录,并且名称“root”能被识别,必需在 /etc/passwd 和 /etc/group 文件中写入相关条目。
- Create the /etc/passwd file by running
- the following command:
+ 运行下面的命令创建 /etc/passwd 文件:
cat > /etc/passwd << "EOF"
@@ -203,13 +183,10 @@
EOF
- The actual password for root (the
- “x”
- used here is just a placeholder) will be set later.
+ root 用户的实际密码(这里的 “x” 只是占位符)将在后面创建。
- Create the /etc/group file by running
- the following command:
+ 运行下面的命令创建 /etc/group 文件:
cat > /etc/group << "EOF"
@@ -239,52 +216,19 @@
EOF
- The created groups are not part of any standard—they are groups
- decided on in part by the requirements of the Udev configuration in
- this chapter, and in part by common convention employed by a number
- of existing Linux distributions. In addition, some test suites rely
- on specific users or groups. The Linux Standard Base (LSB, available
- at http://www.linuxbase.org) recommends
- only that, besides the group root
- with a Group ID (GID) of 0, a group bin with a GID of 1 be present. All other group
- names and GIDs can be chosen freely by the system administrator since
- well-written programs do not depend on GID numbers, but rather use
- the group's name.
+ 这里创建的组用户没有参照任何标准 —— 它们部分是由本章中Udev配置的要求部分决定的,部分由多个现有Linux发行版使用的常规约定组成。 另外,一些测试套件依赖于特定的用户或组。Linux 标准库(LSB,参见 http://www.linuxbase.org)建议,除组ID(GID)为 0 的组 root 外,还提供 GID 为 1 的组 bin。所有其他组名和 GID 可由系统管理员自由选择,因为好的程序不依赖于 GID,而是使用组的名称。
- To remove the “I have
- no name!” prompt, start a new shell. Since a full
- Glibc was installed in Chapter 5
- and the /etc/passwd and /etc/group files have been created, user name and
- group name resolution will now work:
+ 为了移除 “I have no name!” 的提示符,可以打开一个新 shell。由于在第五章已经安装了完整的 Glibc,而且已经创建好了 /etc/passwd 和 /etc/group 文件,用户名和组名就可以正常解析了:
exec /tools/bin/bash --login +h
- Note the use of the +h
- directive. This tells bash not to use its internal path
- hashing. Without this directive, bash would remember the paths to
- binaries it has executed. To ensure the use of the newly compiled
- binaries as soon as they are installed, the +h directive will be used for the
- duration of this chapter.
+ 注意这里使用了 +h 参数。这样会告诉 bash 不要使用它内建的路径哈希功能。如果不加这个参数的话, bash 将会记住曾经执行过程序的路径。为了在新编译安装好程序后就能马上使用,参数 +h 将在本章中一直使用。
- The login, agetty, and init programs (and others) use a
- number of log files to record information such as who was logged into
- the system and when. However, these programs will not write to the
- log files if they do not already exist. Initialize the log files and
- give them proper permissions:
+ login,agetty,init 等程序会使用一些日志文件来记录信息,比如谁在什么时候登录了系统。不过,在日志文件不存在的时候这些程序一般不会写入。下面初始化一下日志文件并加上合适的权限:
- The /var/log/wtmp file records all
- logins and logouts. The /var/log/lastlog file records when each user last
- logged in. The /var/log/faillog file
- records failed login attempts. The /var/log/btmp file records the bad login attempts.
+ /var/log/wtmp 文件会记录所有登录和注销信息。/var/log/lastlog 文件记录每个用户上次登录的时间。/var/log/faillog 文件记录失败的登录尝试。/var/log/wtmp 文件记录错误登录尝试。
@@ -306,9 +245,7 @@
Note
- The /run/utmp file records the users
- that are currently logged in. This file is created dynamically in
- the boot scripts.
+ /run/utmp 文件会记录当当前已登录的用户信息。这个文件在启动脚本中动态创建。
6.7. Linux-4.9.9 API Headers
+ "ch-system-linux-headers">6.7. Linux-4.9.9 API 头文件
- The Linux API Headers (in linux-4.9.9.tar.xz) expose the kernel's
- API for use by Glibc.
+ Linux API 头文件(在 linux-4.9.9.tar.xz 中)会把内核 API 导出给 Glibc 使用。
- Approximate build time:
- less than 0.1 SBU
+ 预计构建时间:
+ 少于 0.1 SBU
- Required disk space:
+ 所需磁盘空间:767 MB
@@ -71,28 +70,19 @@
- 6.7.1. Installation of Linux API Headers
+ 6.7.1. 安装 Linux API 头文件
- The Linux kernel needs to expose an Application Programming
- Interface (API) for the system's C library (Glibc in LFS) to use.
- This is done by way of sanitizing various C header files that are
- shipped in the Linux kernel source tarball.
+ Linux 内核需要提供一个应用编程接口(API)供系统的 C 库(LFS 中的 Glibc)调用。这通过整理 Linux 内核源码包中的多个 C 头文件来完成。
- Make sure there are no stale files and dependencies lying around
- from previous activity:
+ 确保在之前的动作里没有留下旧文件和依赖关系:
make mrproper
- Now extract the user-visible kernel headers from the source. They
- are placed in an intermediate local directory and copied to the
- needed location because the extraction process removes any existing
- files in the target directory. There are also some hidden files
- used by the kernel developers and not needed by LFS that are
- removed from the intermediate directory.
+ 现在要从源代码里解压出用户需要的内核头文件。因为解压过程会删除目标目录下所有文件,所以我们会先输出到一个本地中间目录后再拷贝到需要的地方。而且里面还有一些隐藏文件是给内核开发人员用的,而 LFS 不需要,所以会将它们从中间目录里删除。
make INSTALL_HDR_PATH=dest headers_install
@@ -103,32 +93,32 @@
6.7.2. Contents of Linux API Headers
+ "contents-linux-headers">6.7.2. Linux API 头文件内容
Home
+ "Linux From Scratch - Version 8.0-systemd">主页
6.1.
- Introduction
+ 简介
- In this chapter, we enter the building site and start constructing
- the LFS system in earnest. That is, we chroot into the temporary mini
- Linux system, make a few final preparations, and then begin
- installing the packages.
+ 在本章中,我们进入构建页面,开始认真构建 LFS 系统。也就是说,我们需要 chroot 到临时的迷你 Linux 系统,做一些最后的准备,然后开始安装软件包。
- The installation of this software is straightforward. Although in
- many cases the installation instructions could be made shorter and
- more generic, we have opted to provide the full instructions for
- every package to minimize the possibilities for mistakes. The key to
- learning what makes a Linux system work is to know what each package
- is used for and why you (or the system) may need it.
+ 安装这些软件很简单。虽然在很多情况下安装说明可以做得更短,更通用,但是我们选择提供每个包的完整说明给大家,以尽量减少产生错误的可能性。学习 Linux 系统如何工作的关键是知道每个软件包是用来干什么以及你(或者系统)为什么需要它。
- We do not recommend using optimizations. They can make a program run
- slightly faster, but they may also cause compilation difficulties and
- problems when running the program. If a package refuses to compile
- when using optimization, try to compile it without optimization and
- see if that fixes the problem. Even if the package does compile when
- using optimization, there is the risk it may have been compiled
- incorrectly because of the complex interactions between the code and
- build tools. Also note that the -march
- and -mtune options using values not
- specified in the book have not been tested. This may cause problems
- with the toolchain packages (Binutils, GCC and Glibc). The small
- potential gains achieved in using compiler optimizations are often
- outweighed by the risks. First-time builders of LFS are encouraged to
- build without custom optimizations. The subsequent system will still
- run very fast and be stable at the same time.
+ 我们不建议使用最优化配置。它们可以使程序运行速度略快,但可能导致编译更困难或者程序运行时出现问题。如果某个包在使用优化时编译出错,请尝试在没有优化的情况下编译它,看看是否能解决问题。即使软件包在使用优化时进行编译,由于代码和构建工具之间复杂的交互,也有编译不正确的风险。另请注意,-march 和 -mtune 选项尚未测试,他们使用了未作详细说明的值。这可能会导致工具链包(Binutils,GCC 和 Glibc)出现问题。在使用编译器优化时实现的一点潜在增益通常会被其风险所抵消。建议首次构建 LFS 的人无需自定义优化。后续系统仍将运行非常快,同时也会很稳定。
- The order that packages are installed in this chapter needs to be
- strictly followed to ensure that no program accidentally acquires a
- path referring to /tools hard-wired
- into it. For the same reason, do not compile separate packages in
- parallel. Compiling in parallel may save time (especially on dual-CPU
- machines), but it could result in a program containing a hard-wired
- path to /tools, which will cause the
- program to stop working when that directory is removed.
+ 本章中安装软件包的顺序需要严格遵守,因为安装某些程序需要引用硬连接到 /tools 的路径,这样做可以确保这些程序不会产生这种意外的问题。同样,也不要并行编译单独的包。虽然并行编译可以节省时间(特别是在双 CPU 机器上),但它可能会影响到包含在 /tools 的硬连线路径中的程序,这将导致程序在该目录被删除时停止工作。
- Before the installation instructions, each installation page provides
- information about the package, including a concise description of
- what it contains, approximately how long it will take to build, and
- how much disk space is required during this building process.
- Following the installation instructions, there is a list of programs
- and libraries (along with brief descriptions of these) that the
- package installs.
+ 在进行安装说明之前,每个安装页面都会提供相关软件包的信息,包括其中包含内容的简述,大约需要的构建时长,以及在构建过程中需要多少磁盘空间。安装说明中会有一个安装软件包所需程序和库的列表(以及它们的简要说明)。
- Note
+ 注意
- The SBU values and required disk space includes test suite data for
- all applicable packages in Chapter 6.
+ 第六章中 SBU 值和所需硬盘空间包含所有适用软件包的测试套件数据。
- 6.1.1. About libraries
+ 6.1.1. 关于函数库
- In general, the LFS editors discourage building and installing
- static libraries. The original purpose for most static libraries
- has been made obsolete in a modern Linux system. In addition
- linking a static library into a program can be detrimental. If an
- update to the library is needed to remove a security problem, all
- programs that use the static library will need to be relinked to
- the new library. Since the use of static libraries is not always
- obvious, the relevant programs (and the procedures needed to do the
- linking) may not even be known.
+ 一般来说,LFS 编辑器不鼓励构建和安装静态库。大多数静态库的最初目的在现代 Linux 系统中已经过时了。另外,将静态库链接到程序中可能是有害的。如果为了消除一个安全问题而需要更新一个静态库,那么使用这个静态库的所有程序都需要重新链接到新库。因为静态库的作用并不总是很明显,相关程序(以及执行链接所需的过程)甚至可能是未知的。
- In the procedures in Chapter 6, we remove or disable installation
- of most static libraries. In a few cases, especially glibc and gcc,
- the use of static libraries remains essential to the general
- package building process. Usually this is done by passing a
- --disable-static option to configure. In other cases,
- alternate means are needed.
+ 在介绍第六章的过程中,我们去除或禁用了大多数静态库的安装。在少数情况下,特别是 glibc 和 gcc,静态库的使用对于一般的包构建过程仍然是至关重要的。通常这要通过传递一个 --disable-static 选项给 configure 来完成。在其他情况下,需要其它替代方法。
- Various file systems exported by the kernel are used to communicate
- to and from the kernel itself. These file systems are virtual in that
- no disk space is used for them. The content of the file systems
- resides in memory.
+ 由内核导出的各种文件系统用于与内核本身进行通信。这些文件系统是虚拟的,因为它们不使用磁盘空间。这些文件系统的内容驻留在内存中。
- Begin by creating directories onto which the file systems will be
- mounted:
+ 首先创建将要挂载文件系统的目录:
- When the kernel boots the system, it requires the presence of a few
- device nodes, in particular the console and null
- devices. The device nodes must be created on the hard disk so that
- they are available before udevd has been started, and
- additionally when Linux is started with init=/bin/bash. Create the devices by
- running the following commands:
+ 当内核引导系统时,它需要存在几个设备节点,特别是 console 和 null 设备。设备节点必须在硬盘上创建,以便在启动 udevd 之前可用,此外,当使用 init=/bin/bash 启动 Linux 时。通过运行以下命令创建设备:
6.2.2.
- Mounting and Populating /dev
+ 安装和填充 /dev
- The recommended method of populating the /dev directory with devices is to mount a virtual
- filesystem (such as tmpfs) on the
- /dev directory, and allow the devices
- to be created dynamically on that virtual filesystem as they are
- detected or accessed. Device creation is generally done during the
- boot process by Udev. Since this new system does not yet have Udev
- and has not yet been booted, it is necessary to mount and populate
- /dev manually. This is accomplished
- by bind mounting the host system's /dev directory. A bind mount is a special type of
- mount that allows you to create a mirror of a directory or mount
- point to some other location. Use the following command to achieve
- this:
+ 推荐的用设备填充 /dev 目录的方法是在 /dev 目录上挂载虚拟文件系统(如 tmpfs),并允许在检测或访问设备时动态创建该虚拟文件系统。设备创建通常由 Udev 在引导过程中完成。由于这个新系统还没有 Udev 并且尚未启动,因此需要手动安装和填充 /dev。这是通过绑定挂载主机系统的 /dev 目录来实现的。绑定挂载是特殊类型的挂载,它允许你创建目录的镜像或指向其他位置的挂载点。使用以下命令实现此目的:
mount -v --bind /dev $LFS/dev
@@ -112,11 +87,10 @@
6.2.3. Mounting Virtual Kernel File
- Systems
+ "ch-system-kernfsmount">6.2.3. 挂载虚拟内核文件系统
- Now mount the remaining virtual kernel filesystems:
+ 现在挂载剩下的虚拟内核文件系统:
- The meaning of the mount options for devpts:
+ 挂载选项 devpts 的含义:
@@ -135,12 +109,7 @@
- This ensures that all devpts-created device nodes are owned
- by group ID 5. This is the ID we will use later on for the
- tty group. We use the group
- ID instead of a name, since the host system might use a
- different ID for its tty
- group.
+ 该选项确保所有 devpts 创建的设备节点都属于 ID 为 5 的组。这个 ID 我们之后将用于 tty 组。我们使用组 ID 而不是名称,因为主机系统可能为其 tty 组使用不同的 ID。
@@ -149,13 +118,7 @@
- This ensures that all devpts-created device nodes have mode
- 0620 (user readable and writable, group writable). Together
- with the option above, this ensures that devpts will create
- device nodes that meet the requirements of grantpt(), meaning
- the Glibc pt_chown helper binary
- (which is not installed by default) is not necessary.
+ 该选项确保所有 devpts 创建的设备节点处于 0620 模式(用户可读写,组可写)。与上面的选项一起,这确保 devpts 将创建满足 grantpt() 的要求的设备节点,这意味着 Glibc pt_chown 辅助程序二进制文件(默认情况下不安装)是不必要的。
@@ -165,6 +128,7 @@
symbolic link to /run/shm. The /run
tmpfs was mounted above so in this case only a directory needs to
be created.
+ 在某些主机系统中,/dev/shm 是指向 /run/shm 的符号链接。/run 目录的 tmpfs 已经挂载了,所以现在只需要创建一个目录。
if [ -h $LFS/dev/shm ]; then
@@ -177,25 +141,25 @@
Up
+ "Chapter 6. Installing Basic System Software">返回
Home
+ "Linux From Scratch - Version 8.0-systemd ">主页
From 9301053a5c1ff923cb74b921ada41f90856563f5 Mon Sep 17 00:00:00 2001
From: Jay Liu
Date: Tue, 9 May 2017 19:24:35 +0800
Subject: [PATCH 17/20] lfs-8.0/chapter06/pkgmgt.html: remove redundancy
English
---
lfs-8.0/chapter06/pkgmgt.html | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/lfs-8.0/chapter06/pkgmgt.html b/lfs-8.0/chapter06/pkgmgt.html
index ad3bc82..a54fd11 100644
--- a/lfs-8.0/chapter06/pkgmgt.html
+++ b/lfs-8.0/chapter06/pkgmgt.html
@@ -211,24 +211,6 @@
6.3.3. 在多系统上部署 LFS
- One of the advantages of an LFS system is that there are no files
- that depend on the position of files on a disk system. Cloning an
- LFS build to another computer with the same architecture as the
- base system is as simple as using tar on the LFS partition that
- contains the root directory (about 250MB uncompressed for a base
- LFS build), copying that file via network transfer or CD-ROM to the
- new system and expanding it. From that point, a few configuration
- files will have to be changed. Configuration files that may need to
- be updated include: /etc/hosts,
- /etc/fstab, /etc/passwd, /etc/group, /etc/shadow, /etc/ld.so.conf, /etc/sysconfig/rc.site, /etc/sysconfig/network, and /etc/sysconfig/ifconfig.eth0.
LFS 系统的优点之一是没有文件依赖于磁盘系统上文件的位置。将 LFS 克隆到与基础系统架构相同的另一台计算机上,简单到只需在包含根目录的 LFS 分区(大约 250MB 未压缩的基本 LFS 构建)上使用 tar 命令打包,然后通过网络传输或 CD-ROM 拷贝到新系统并解包。此后,还必须更改一些配置文件。可能需要更新的配置文件包括:/etc/hosts,/etc/fstab,/etc/passwd,/etc/group,/etc/shadow,/etc/ld.so.conf,/etc/sysconfig/rc.site,/etc/sysconfig/network 和 /etc/sysconfig/ifconfig.eth0。
Home
+ "Linux From Scratch - Version 8.0-systemd ">目录
- 6.3. Package
- Management
+ 6.3.
+ 软件包管理
- Package Management is an often requested addition to the LFS Book. A
- Package Manager allows tracking the installation of files making it
- easy to remove and upgrade packages. As well as the binary and
- library files, a package manager will handle the installation of
- configuration files. Before you begin to wonder, NO—this
- section will not talk about nor recommend any particular package
- manager. What it provides is a roundup of the more popular techniques
- and how they work. The perfect package manager for you may be among
- these techniques or may be a combination of two or more of these
- techniques. This section briefly mentions issues that may arise when
- upgrading packages.
+ 软件包管理是 LFS 手册中经常需要添加的。软件包管理器可以跟踪文件的安装,以便删除和升级软件包。除了二进制和库文件,包管理器还会处理配置文件的安装。然而需要告诉你的是,这一节不会谈论和推荐任何特定的包管理器。它提供了一个更流行的技术并且说明了它们如何工作。最适合你的包管理器可能是这些技术之中的一个,或者是这些技术中的两个或多个的组合。本节简要介绍升级软件包时可能出现的问题。
- Some reasons why no package manager is mentioned in LFS or BLFS
- include:
+ 在 LFS 或 BLFS 中未提及软件包管理器的一些原因包括:
- Dealing with package management takes the focus away from the
- goals of these books—teaching how a Linux system is
- built.
+ 处理包管理使得关注焦点远离这些书的目标 — 教授如何构建Linux系统。
- There are multiple solutions for package management, each
- having its strengths and drawbacks. Including one that
- satisfies all audiences is difficult.
+ 有很多用于包管理的解决方案,每个都各有优缺点。其中一条就是满足所有用户是困难的。
- There are some hints written on the topic of package management.
- Visit the Hints Project
- and see if one of them fits your need.
+ 有一些关于包管理的提示。访问 Hints Project,看看是否有一个适合你的需求。
- 6.3.1. Upgrade Issues
+ 6.3.1. 升级问题
- A Package Manager makes it easy to upgrade to newer versions when
- they are released. Generally the instructions in the LFS and BLFS
- Book can be used to upgrade to the newer versions. Here are some
- points that you should be aware of when upgrading packages,
- especially on a running system.
+ 软件包管理器可以在软件发布时轻松升级到较新的版本。通常,LFS 和 BLFS 手册中的指令可用来升级到较新版本。以下是升级软件包时应注意的一些问题,尤其是在正在运行的系统上。
- If Glibc needs to be upgraded to a newer version, (e.g. from
- glibc-2.19 to glibc-2.20, it is safer to rebuild LFS. Though
- you may be able to
- rebuild all the packages in their dependency order, we do not
- recommend it.
+ 如果 Glibc 需要升级到更新的版本(例如,从 glibc-2.19 升级到 glibc-2.20,重建 LFS 会更安全)。虽然你可以重建所有顺序依赖的包,但我们不推荐这样做。
- If a package containing a shared library is updated, and if
- the name of the library changes, then all the packages
- dynamically linked to the library need to be recompiled to
- link against the newer library. (Note that there is no
- correlation between the package version and the name of the
- library.) For example, consider a package foo-1.2.3 that
- installs a shared library with name libfoo.so.1. Say you upgrade the package to
- a newer version foo-1.2.4 that installs a shared library with
- name libfoo.so.2. In this case,
- all packages that are dynamically linked to libfoo.so.1 need to be recompiled to link
- against libfoo.so.2. Note that
- you should not remove the previous libraries until the
- dependent packages are recompiled.
+ 如果一个包含共享库的包更新,并且库的名称有更改,则动态链接到库的所有包都需要重新编译以链接到较新的库(注意,软件包版本和软件包名称之间没有关系)。例如,考虑一个软件包 foo-1.2.3,它安装一个名为 libfoo.so.1 的共享库。假如你要将包升级到更新的版本 foo-1.2.4,而它会安装一个名为 libfoo.so.2 的共享库。在这种情况下,动态链接到 libfoo.so.1 的所有软件包都需要重新编译以链接到 libfoo.so.2。请注意,在重新编译依赖包之前,不应删除原来的库。
- The following are some common package management techniques. Before
- making a decision on a package manager, do some research on the
- various techniques, particularly the drawbacks of the particular
- scheme.
+ 以下是一些常见的软件包管理技技术。在决定用什么包管理器之前,最好研究一下各种技术,尤其是了解特定方案的缺点。
- 6.3.2.1. It is All in My Head!
+ 6.3.2.1. 所有东西都在我脑袋里!
- Yes, this is a package management technique. Some folks do not
- find the need for a package manager because they know the
- packages intimately and know what files are installed by each
- package. Some users also do not need any package management
- because they plan on rebuilding the entire system when a package
- is changed.
+ 是的,这也是一种包管理技术。有些人可能没有对包管理器的需求,因为他们很熟悉软件包,而且知道每个软件包会安装哪些文件。也有些不需要包管理器的人是因为他们打算在更改某个软件包的时候重建整个系统。
- 6.3.2.2. Install in Separate Directories
+ 6.3.2.2. 安装在单独的目录里
- This is a simplistic package management that does not need any
- extra package to manage the installations. Each package is
- installed in a separate directory. For example, package foo-1.1
- is installed in /usr/pkg/foo-1.1
- and a symlink is made from /usr/pkg/foo to /usr/pkg/foo-1.1. When installing a new version
- foo-1.2, it is installed in /usr/pkg/foo-1.2 and the previous symlink is
- replaced by a symlink to the new version.
+ 这是一个简单的包管理方式,不需要任何额外的软件包来管理安装。每个包都安装在单独的目录中。例如,包 foo-1.1 安装在 /usr/pkg/foo-1.1 中,并创建由 /usr/pkg/foo 到 /usr/pkg/foo-1.1 的符号链接。当安装新版本 foo-1.2 时,将它安装在 /usr/pkg/foo-1.2 中,之前的符号链接替换为新版本的符号链接。
- Environment variables such as PATH,
- LD_LIBRARY_PATH, MANPATH, INFOPATH and
- CPPFLAGS need to be expanded to
- include /usr/pkg/foo. For more than
- a few packages, this scheme becomes unmanageable.
+ PATH, LD_LIBRARY_PATH, MANPATH, INFOPATH 和 CPPFLAGS 等环境变量都需要包含/ usr / pkg / foo。如果有很多软件包,这个方案就很难管理了。
- This is a variation of the previous package management technique.
- Each package is installed similar to the previous scheme. But
- instead of making the symlink, each file is symlinked into the
- /usr hierarchy. This removes the
- need to expand the environment variables. Though the symlinks can
- be created by the user to automate the creation, many package
- managers have been written using this approach. A few of the
- popular ones include Stow, Epkg, Graft, and Depot.
+ 这是上一种包管理技术的一个变体。每个软件包都用相同的方式安装。但是,这种方式不是创建目录的符号链接,而是将每个文件在 /usr 目录结构中创建符号链接。这样就不再需要扩展环境变量了。虽然用户可以创建符号链接来实现自动化,但是许多软件包管理器都已经使用了这种方法来编写。几个比较流行的有 Stow,Epkg,Graft 和 Depot。
- The installation needs to be faked, so that the package thinks
- that it is installed in /usr though
- in reality it is installed in the /usr/pkg hierarchy. Installing in this manner
- is not usually a trivial task. For example, consider that you are
- installing a package libfoo-1.1. The following instructions may
- not install the package properly:
+ 这种安装方式安装伪装,以使软件包认为它被安装在 /usr 中,但实际上它安装在 /usr/pkg 层次结构中。用这种方式安装通常都不是一件简单的工作。例如,假设你正在安装 libfoo-1.1 软件包。以下指令可能无法正确安装包:
- The installation will work, but the dependent packages may not
- link to libfoo as you would expect. If you compile a package that
- links against libfoo, you may notice that it is linked to
- /usr/pkg/libfoo/1.1/lib/libfoo.so.1
- instead of /usr/lib/libfoo.so.1 as
- you would expect. The correct approach is to use the DESTDIR strategy to fake installation of the
- package. This approach works as follows:
+ 这样安装后可以工作,但依赖软件包可能不会像你所期望的那样链接到libfoo。如果你编译一个链接到libfoo的包,你可能会注意到它被链接到 /usr/pkg/libfoo/1.1/lib/libfoo.so.1 而不是你期望的 /usr/lib/libfoo.so.1。正确的方法是使用 DESTDIR 策略来伪装软件包的安装。此方法的工作原理如下:
./configure --prefix=/usr
@@ -228,166 +150,85 @@
make DESTDIR=/usr/pkg/libfoo/1.1 install
- Most packages support this approach, but there are some which do
- not. For the non-compliant packages, you may either need to
- manually install the package, or you may find that it is easier
- to install some problematic packages into /opt.
+ 大多数软件包都支持这种方法,但是也有一些不支持。对于非兼容包,你可能需要手动安装这些包,或许你会发现这样更容易将一些有问题的软件包安装到 /opt。
- 6.3.2.4. Timestamp Based
+ 6.3.2.4. 基于时间戳
- In this technique, a file is timestamped before the installation
- of the package. After the installation, a simple use of the
- find command with
- the appropriate options can generate a log of all the files
- installed after the timestamp file was created. A package manager
- written with this approach is install-log.
+ 这种技术里,在安装软件包之前会创建文件的时间戳。安装后,一个简单的带有合适参数的 find 命令可以产生在时间戳被创建后安装的所有文件的日志。有一种使用这种方法的包管理器是 install-log。
- Though this scheme has the advantage of being simple, it has two
- drawbacks. If, during installation, the files are installed with
- any timestamp other than the current time, those files will not
- be tracked by the package manager. Also, this scheme can only be
- used when one package is installed at a time. The logs are not
- reliable if two packages are being installed on two different
- consoles.
+ 虽然这个方案的优点是简单,但它也有两个缺点。在安装期间,如果被安装的文件的时间戳与当前的时间不同,这些文件就不会被包管理器追踪。同时,这种方案只适用于同一时间只有一个包被安装的情况。如果在两个不同终端下同时安装两个软件包,那产生的日志是不可靠的。
- In this approach, the commands that the installation scripts
- perform are recorded. There are two techniques that one can use:
+ 在这种方法中,安装脚本执行的命令都会被记录下来。对此,有两种技术,其中一种可以这样用:
- The LD_PRELOAD environment variable
- can be set to point to a library to be preloaded before
- installation. During installation, this library tracks the
- packages that are being installed by attaching itself to various
- executables such as cp, install, mv and tracking the system
- calls that modify the filesystem. For this approach to work, all
- the executables need to be dynamically linked without the suid or
- sgid bit. Preloading the library may cause some unwanted
- side-effects during installation. Therefore, it is advised that
- one performs some tests to ensure that the package manager does
- not break anything and logs all the appropriate files.
+ 可以设置环境变量 LD_PRELOAD 指向一个在安装前预加载的库。安装过程中,此库通过将自身附加到各种可执行文件(如 cp, install, mv)并跟踪修改文件系统的系统调用来跟踪要安装的软件包。对于这种工作方式,所有可执行文件都需要动态链接,无需使用 suid 或 sgid 位。预加载库可能导致安装过程中不必要的副作用。因此,建议您执行一些测试以确保软件包管理器不会破坏任何内容并记录所有相应的文件。
- The second technique is to use strace, which logs all system
- calls made during the execution of the installation scripts.
+ 第二种技术是使用 strace 来记录执行安装脚本期间所有的系统调用
- In this scheme, the package installation is faked into a separate
- tree as described in the Symlink style package management. After
- the installation, a package archive is created using the
- installed files. This archive is then used to install the package
- either on the local machine or can even be used to install the
- package on other machines.
+ 在这种方案中,软件包被伪装安装到一个单独的目录树,就如符号链接软件包管理中描述的。安装后,使用已安装的文件创建包存档。然后,此存档用于在本地机器上安装软件包,甚至可以用于在其他计算机上安装软件包。
- 6.3.2.7. User Based Management
+ 6.3.2.7. 基于用户的包管理
- This scheme, unique to LFS, was devised by Matthias Benkmann, and
- is available from the Hints
- Project. In this scheme, each package is installed as a
- separate user into the standard locations. Files belonging to a
- package are easily identified by checking the user ID. The
- features and shortcomings of this approach are too complex to
- describe in this section. For the details please see the hint at
- Hints Project 获得。在此方案中,每个包都作为单独的用户安装到标准位置。通过检查用户 ID 可以容易地识别属于包的文件。这种方法的特点和缺点太复杂,无法在本节中进行描述。有关详细信息,请参阅
- http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt.
+ http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt 上的提示。
- 6.3.3. Deploying LFS on Multiple Systems
+ 6.3.3. 在多系统上部署 LFS
- One of the advantages of an LFS system is that there are no files
- that depend on the position of files on a disk system. Cloning an
- LFS build to another computer with the same architecture as the
- base system is as simple as using tar on the LFS partition that
- contains the root directory (about 250MB uncompressed for a base
- LFS build), copying that file via network transfer or CD-ROM to the
- new system and expanding it. From that point, a few configuration
- files will have to be changed. Configuration files that may need to
- be updated include: /etc/hosts,
- /etc/fstab, /etc/passwd, /etc/group, /etc/shadow, and /etc/ld.so.conf.
+ LFS 系统的优点之一是没有文件依赖于磁盘系统上文件的位置。将 LFS 克隆到与基础系统架构相同的另一台计算机上,简单到只需在包含根目录的 LFS 分区(大约 250MB 未压缩的基本 LFS 构建)上使用 tar 命令打包,然后通过网络传输或 CD-ROM 拷贝到新系统并解包。此后,还必须更改一些配置文件。可能需要更新的配置文件包括:/etc/hosts,/etc/fstab,/etc/passwd,/etc/group,/etc/shadow 和 /etc/ld.so.conf。
- A custom kernel may need to be built for the new system depending
- on differences in system hardware and the original kernel
- configuration.
+ 可能需要为新系统构建定制内核,具体取决于系统硬件和原始内核配置的不同。
- Note
+ 注意
- There have been some reports of issues when copying between
- similar but not identical architectures. For instance, the
- instruction set for an Intel system is not identical with an AMD
- processor and later versions of some processors may have
- instructions that are unavailable in earlier versions.
+ 在类似但不相同的体系结构之间进行复制时,有一些问题会报错。例如,英特尔系统的指令集与 AMD 处理器不相同,新版本的某些处理器可能具有早期版本中不可用的指令。
- It is time to enter the chroot environment to begin building and
- installing the final LFS system. As user root, run the following command to enter the
- realm that is, at the moment, populated with only the temporary
- tools:
+ 现在是时候进入 chroot 环境开始构建和安装最终的 LFS 系统了。以 root 用户运行以下命令进入现在只含有一些临时工具的“空间”:
- The -i option given to the
- env command will clear
- all variables of the chroot environment. After that, only the
- HOME, TERM,
- PS1, and PATH
- variables are set again. The TERM=$TERM construct will set the
- TERM variable inside chroot to the same
- value as outside chroot. This variable is needed for programs like
- vim and less to operate properly. If other
- variables are needed, such as CFLAGS or
- CXXFLAGS, this is a good place to set them
- again.
+ env 命令的 -i 选项将清除 chroot 环境的所有变量。随后,只有 HOME,TERM,PS1 和 PATH 变量会被重新设置。TERM=$TERM 语句将会把 chroot 内的 TERM 变量的值设置为与外部 chroot 相同。对于像 vim 和 less 这样的程序,需要这个变量以保证其正常运行。如果需要其他变量,如 CFLAGS 或
+ CXXFLAGS,就在这个地方设置会比较好。
- From this point on, there is no need to use the LFS variable anymore, because all work will be
- restricted to the LFS file system. This is because the Bash shell is
- told that $LFS is now the root
- (/) directory.
+ 从这里以后,就不再需要 LFS 变量了,因为所有的工作都将被限制在 LFS 文件系统中。这是因为我们已经告诉 Bash shell $LFS 现在是根(/)目录。
- Notice that /tools/bin comes last in
- the PATH. This means that a temporary tool
- will no longer be used once its final version is installed. This
- occurs when the shell does not “remember” the
- locations of executed binaries—for this reason, hashing is
- switched off by passing the +h option to bash.
+ 注意 /tools/bin 放在了 PATH 中的最后。这意味着一旦安装了最终版本,就不再使用临时工具。当 shell 没有“记住”执行的二进制文件的位置时,就会发生这种情况。因此,需要给 bash 加上 +h 参数,以关闭哈希功能。
- Note that the bash
- prompt will say I have no name!
- This is normal because the /etc/passwd
- file has not been created yet.
+ 还需注意 bash 会提示 I have no name! 这通常是因为没有创建 /etc/passwd 文件。
- Note
+ 注意
- It is important that all the commands throughout the remainder of
- this chapter and the following chapters are run from within the
- chroot environment. If you leave this environment for any reason
- (rebooting for example), ensure that the virtual kernel filesystems
- are mounted as explained in Section 6.2.2,
- “Mounting and Populating /dev” and Section 6.2.3,
- “Mounting Virtual Kernel File Systems” and enter
- chroot again before continuing with the installation.
+ 需要重视,本章从这以后的命令,以及后续章节里的命令都要在 chroot 环境下运行。如果因为某种原因(比如说重启)离开了这个环境,请保证要按照 6.2.2,“挂载和激活 /dev” 和 6.2.3,“挂载虚拟内核文件系统” 里所说的那样挂载虚拟内核文件系统,然后在继续构建之前重新运行 chroot 进入环境。
Home
+ "Linux From Scratch - Version 8.0-systemd ">主页
6.5.
- Creating Directories
+ 创建目录
- It is time to create some structure in the LFS file system. Create a
- standard directory tree by issuing the following commands:
+ 现在准备创建 LFS 文件系统里的一些目录结构。使用下面的命令创建一个标准的目录树:
- Directories are, by default, created with permission mode 755, but
- this is not desirable for all directories. In the commands above, two
- changes are made—one to the home directory of user root, and another to the directories for
- temporary files.
+ 一般目录默认会按 755 的权限创建,但是这并不适用于所有的目录。在上面的命令里,有两个改动 —— 一个是 root 用户的主目录,另一个是存放临时文件的目录。
- The first mode change ensures that not just anybody can enter the
- /root directory—the same as a
- normal user would do with his or her home directory. The second mode
- change makes sure that any user can write to the /tmp and /var/tmp
- directories, but cannot remove another user's files from them. The
- latter is prohibited by the so-called “sticky bit,”
- the highest bit (1) in the 1777 bit mask.
+ 第一个模式改动能保证不是所有人都能进入 /root 目录 —— 同样,一般用户也需要为他/她的家目录设置这样的模式。第二个模式改动能保证所有用户都可以写目录 /tmp 和 /var/tmp。还增加了一个所谓的“粘滞位”的限制,即位掩码 0x1777 中的最高位(1)。
- 6.5.1. FHS Compliance Note
+ 6.5.1. 关于 FHS 兼容性
- The directory tree is based on the Filesystem Hierarchy Standard
- (FHS) (available at https://wiki.linuxfoundation.org/en/FHS).
- The FHS also stipulates the optional existence some directories
- such as /usr/local/games and
- /usr/share/games. We create only the
- directories that are needed. However, feel free to create these
- directories.
+ 这个目录树是基于文件系统目录结构标准(FHS)(参见 https://wiki.linuxfoundation.org/en/FHS)。FHS 标准还规定了要有 /usr/local/games 和 /usr/share/games 目录。我们只需要创建我们需要的文件。当然,你也可以自由地创建这些目录。