This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Gentoo Linux alpha 手册:使用Portage

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:Alpha/Full/Portage and the translation is 100% complete.
Alpha Handbook
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装stage3
安装基本系统
配置Linux内核
配置系统
安装系统工具
配置系统引导程序Bootloader
收尾安装工作
使用Gentoo
Portage介绍
USE标记
Portage功能特性
初始化脚本(Initscript)系统
环境变量
使用Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
定制Portage树
高级特性
网络配置
入门
高级配置
模块化网络
无线
添加功能
动态管理


Portage文件

配置指南

Portage附带了一个默认的配置文件/usr/share/portage/config/make.globals。当你打开它时,你就会发现所有的Portage配置选项都是通过变量来控制的。Portage读取的是什么变量,这些变量分别又是什么意思,下面将详细解释。

Since many configuration directives differ between architectures, Portage also has default configuration files which are part of the system profile. This profile is pointed to by the /etc/portage/make.profile symlink; Portage's configurations are set in the make.defaults files of the profile and all parent profiles. We'll explain more about profiles and the /etc/portage/make.profile directory later on.

如果打算改变配置变量,不要变更/usr/share/portage/config/make.globals 或者make.defaults。而应该修改/etc/portage/make.conf,它比前面的几个文件有更高的优先级。你会发现还有一个/usr/share/portage/config/make.conf.example文件。顾名思义,它仅仅是一个例子而已——Portage并不读取这个文件。

你也可以将一个Portage的配置变量定义为环境变量,但我们并不推荐这样做。

Profile特定的信息

我们已经见到过 /etc/portage/make.profile 目录了。不过,这并不是一个真正的目录,而是一个指向/usr/portage/profiles/ 的符号链接,默认情况下是一个位于/usr/portage/profiles里的目录,虽然你也可以在其他地方创建自己的profile并指向他们。这个符号链接指向的profile就是你的系统所使用的。

一个profile包含了Portage需要的与架构相关的信息,比如该profile对应的system包含的软件包的列表,以及对这个profile来说不能运行的(或者被屏蔽掉)的软件列表,等等。

用户特定的配置

当你需要变更Portage安装软件的行为时,你需要做的就是编辑 /etc/portage/ 中的文件。我们强烈建议你使用/etc/portage/ 中的文件而不是通过修改环境变量来变更这些行为!

/etc/portage/目录中,你可以创建下列文档:

  • package.mask它列出了你永远不希望Portage安装的软件包。
  • package.unmask 它列出了本来Gentoo的开发者不建议安装的,但是你希望能安装的软件包。
  • package.accept_keywords 它列出了还未被确认适合你的系统或架构,但是你希望能安装的软件包。
  • package.use它列出了你希望某些特定软件包使用的而不是整个系统使用的USE标记。

这些并不需要一定是文件;它们也可以是有包含单个软件包信息文件的目录。更多关于 /etc/portage/目录的信息及你能创建的文件的完整列表可以在Portage的手册页中找到:

user $man portage

改变Portage文件和目录的位置

先前提到的配置文件不能保存在其他地方——Portage总是会在这些特定的位置搜索配置文件。不过Portage还用了许多其他的位置来满足不同的目的:编译、保存源代码、保存portage数据库。

所有的这些目的都有众所周知的默认位置,不过你可以根据你自己的喜好通过/etc/portage/make.conf来改变它们。本章中的其他部分将解释Portage使用哪些特定的位置存放它们以及怎样改变它们在你的文件系统中的存放地点。

这篇文档并不是一份全面的参考。如果你需要100%范围的说明,请参看Portage和make.conf的手册页:

user $man portage
user $man make.conf

储存文件

Gentoo ebuild 软件仓库

Gentoo ebuild repository 的默认位置是/usr/portage。这由缺省的 repos.conf 文件定义,位于 /usr/share/portage/config/repos.conf。 要修改默认值,请将此文件复制到 /etc/portage/repos.conf/gentoo.conf 并更改 location 设置。 当将Gentoo ebuild 存储库存储在别处(通过更改此变量)时,不要忘记相应地更改/etc/portage/make.profile 符号链接。

如果你改变了/etc/portage/repos.conf/gentoo.conf里面的location变量,你可能也需要改变下面几个变量,因为它们不会知道location变量的改变。这是Portage处理这些变量的方式导致的:PKGDIR, DISTDIR, and RPMDIR

预编译二进制包

虽然Portage并不默认使用预编译的二进制包,但却对其有多方面的支持。当你要求Portage使用预编译的二进制包时,它就会在/usr/portage/packages.中寻找它们。这个位置是通过 PKGDIR 变量定义的。

源代码

程序的源代码默认保存于/usr/portage/distfiles。这个位置是通过DISTDIR 变量定义的。

Portage 数据库

Portage将你系统的状态(装了哪些软件包,什么文件属于哪个软件包……)保存在/var/db/pkg

警告
不要手动改变这些文件!它可能破坏Portage对你系统的了解。

Portage缓存

Portage缓存(包括修改时间、虚拟包、依赖关系树信息……)储存在/var/cache/edb。这个位置就是一个缓存:如果你没有正在运行portage相关的程序,你就可以清空它。

编译软件

Portage的临时文件

Portage的临时文件默认保存在/var/tmp/。这是通过 PORTAGE_TMPDIR变量定义的。

编译目录

Portage为每一个它所安装的软件包在/var/tmp/portage/里创建特定的编译目录。这一位置是在 portage/ 中已添加的 PORTAGE_TMPDIR 变量定义。

Live文件系统位置

默认情况下,Portage将所有的文件安装到当前文件系统(/)里。但是你可以通过改变环境变量ROOT来改变它。这在你想要创建一个新的编译镜像时是很有用的。

日志特性

Ebuild日志

Portage能为每一个ebuild建立日志文件,但只有当 PORT_LOGDIR变量设定的位置是portage可写的才行。默认情况下,这个变量没有设定。如果你没有设定 PORT_LOGDIR,你就不会收到当前日志系统报告的任何编译日志,然而你可能收到一些来自新的elog机制的日志。

如果你定义了PORT_LOGDIR并且你也使用 elog,你就将收到编译日志以及elog保存的任何日志,就像下文解释的一样。

Portage通过elog对日志记录提供精确的控制:

  • PORTAGE_ELOG_CLASSES: 这是你设置什么信息被记入日志的地方。你可以使用任何用空格分隔的info、warn、error、log和qa的组合。
    • info: 记录下ebuild打印的 "einfo" 信息
    • warn: 记录下ebuild打印的"ewarn" 信息
    • error: 记录下ebuild打印的 "eerror"信息
    • log: 记录下ebuild打印的 "elog"信息
    • qa: 记录下ebuild打印的 "QA Notice"信息
  • PORTAGE_ELOG_SYSTEM: PORTAGE_ELOG_SYSTEM:这是用来选择处理日志信息的模块的。如果留空,则日志记录就被取消。你可以使用任何用空格分隔开的save、custom、syslog、mail、save_summary和mail_summary的组合。你必须至少选择一个模块以使用elog。
    • save: 表示将每一个软件包的日志保存在$PORT_LOGDIR/elog中,或者是在$PORT_LOGDIR/没有配置的情况下保存在/var/log/portage/elog 目录下面。
    • custom: 将所有的信息传递给用户在$PORTAGE_ELOG_COMMAND中定义的命令,这将在随后讨论。
    • syslog: 把所有的信息发送给已安装的系统日志软件。
    • mail:把所有的信息传递给用户在$PORTAGE_ELOG_MAILURI中定义的邮件服务器;这将在随后讨论。这一elog的邮件特性需要>=portage-2.1.1。
    • save_summary: 和save类似,不过它把所有的信息保存在$PORT_LOGDIR/elog/summary.log里,或者/var/log/portage/elog/summary.log里,如果$PORT_LOGDIR没有定义的话。
    • mail_summary: 和mail类似,不过它会在emerge结束时把所有的信息在一个邮件里发送出去。.
  • PORTAGE_ELOG_COMMAND: 这个仅仅在custom模块被激活时使用。在这里你指定一个命令来处理日志信息。注意,你可以利用两个变量:${PACKAGE}是软件包的名字和版本,而${LOGFILE}是日志文件的绝对路径。这里是一个可能的用法:
CODE PORTAGE_ELOG_COMMAND 默认样本
PORTAGE_ELOG_COMMAND="/path/to/logger -p '\${PACKAGE}' -f '\${LOGFILE}'"
  • PORTAGE_ELOG_MAILURI:这包含了mail模块的设定,如地址、用户、密码、邮件服务器、端口。默认配置是 “root@localhost localhost” 这里是一个使用smtp服务器的例子,基于用户名和密码认证并使用特定端口(默认端口是25):
CODE PORTAGE_ELOG_MAILURI默认样本
PORTAGE_ELOG_MAILURI="user@some.domain username:password@smtp.some.domain:995"
  • PORTAGE_ELOG_MAILFROM: 允许你配置日志邮件的"from" 地址;如果没有配置的话,默认是"Portage" 。
  • PORTAGE_ELOG_MAILSUBJECT: 允许你为日志邮件生成一个主题行。注意你可以使用两个变量:${PACKAGE}将会显示软件包的名子和版本,而${HOST}则是运行Portage的主机的FQDN。
CODE PORTAGE_ELOG_MAILSUBJECT默认样本
PORTAGE_ELOG_MAILSUBJECT="package \${PACKAGE} was merged on \${HOST} with some messages"
重要
如果你使用Portage-2.0.*中的enotice,你必须完全移除enotice,因为它和elog不兼容。




Alpha Handbook
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装stage3
安装基本系统
配置Linux内核
配置系统
安装系统工具
配置系统引导程序Bootloader
收尾安装工作
使用Gentoo
Portage介绍
USE标记
Portage功能特性
初始化脚本(Initscript)系统
环境变量
使用Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
定制Portage树
高级特性
网络配置
入门
高级配置
模块化网络
无线
添加功能
动态管理


Portage configuration

As noted previously, Portage is configurable through many variables which should be defined in /etc/portage/make.conf or one of the subdirectories of /etc/portage/. Please refer to the make.conf and portage man pages for more and complete information:

user $man make.conf
user $man portage

Build-specific options

Configure and compiler options

When Portage builds applications, it passes the contents of the following variables to the compiler and configure script:

CFLAGS and CXXFLAGS
Define the desired compiler flags for C and C++ compiling.
CHOST
Defines the build host information for the application's configure script
MAKEOPTS
Passed to the make command and is usually set to define the amount of parallelism used during the compilation. More information about the make options can be found in the make man page.

The USE variable is also used during configure and compilations but has been explained in great detail in previous chapters.

Merge options

When Portage has merged a newer version of a certain software title, it will remove the obsoleted files of the older version from the system. Portage gives the user a 5 second delay before unmerging the older version. These 5 seconds are defined by the CLEAN_DELAY variable.

It is possible to tell emerge to use certain options every time it is run by setting EMERGE_DEFAULT_OPTS. Some useful options would be --ask, --verbose, --tree, and so on.

Configuration file protection

Portage protected locations

Portage overwrites files provided by newer versions of a software title if the files aren't stored in a protected location. These protected locations are defined by the CONFIG_PROTECT variable and are generally configuration file locations. The directory listing is space-delimited.

A file that would be written in such a protected location is renamed and the user is warned about the presence of a newer version of the (presumable) configuration file.

To find out about the current CONFIG_PROTECT setting, use the emerge --info output:

user $emerge --info | grep 'CONFIG_PROTECT='

More information about Portage's configuration file protection is available in the CONFIGURATION FILES section of the emerge manpage:

user $man emerge

Excluding directories

To 'unprotect' certain subdirectories of protected locations users can use the CONFIG_PROTECT_MASK variable.

Download options

Server locations

When the requested information or data is not available on the system, Portage will retrieve it from the Internet. The server locations for the various information and data channels are defined by the following variables:

GENTOO_MIRRORS
Defines a list of server locations which contain source code (distfiles).
PORTAGE_BINHOST
Defines a particular server location containing prebuilt packages for the system.

A third setting involves the location of the rsync server which users use to update their local Gentoo repository. This is defined in the /etc/portage/repos.conf file (or a file inside that directory if it is defined as a directory):

sync-type
Defines the type of server and defaults to rsync.
sync-uri
Defines a particular server which Portage uses to fetch the Gentoo repository.

The GENTOO_MIRRORS, sync-type, and sync-uri variables can be set automatically through the mirrorselect application. Of course, app-portage/mirrorselect needs to be installed first before it can be used. For more information, see mirrorselect's online help:

root #mirrorselect --help

If the environment requires the use of a proxy server, then the http_proxy, ftp_proxy, and RSYNC_PROXY variables can be declared.

Fetch commands

When Portage needs to fetch source code, it uses wget by default. This can be changed through the FETCHCOMMAND variable.

Portage is able to resume partially downloaded source code. It uses wget by default, but this can be altered through the RESUMECOMMAND variable.

Make sure that the FETCHCOMMAND and RESUMECOMMAND store the source code in the correct location. Inside the variables the \${URI} and \${DISTDIR} variables can be used to point to the source code location and distfiles location respectively.

It is also possible to define protocol-specific handlers with FETCHCOMMAND_HTTP, FETCHCOMMAND_FTP, RESUMECOMMAND_HTTP, RESUMECOMMAND_FTP, and so on.

Rsync settings

It is not possible to alter the rsync command used by Portage to update the Gentoo repository, but it is possible to set some variables related to the rsync command:

PORTAGE_RSYNC_OPTS
Sets a number of default variables used during sync, each space-separated. These shouldn't be changed unless you know exactly what you're doing. Note that certain absolutely required options will always be used even if PORTAGE_RSYNC_OPTS is empty.
PORTAGE_RSYNC_EXTRA_OPTS
Used to set additional options when syncing. Each option should be space separated:
--timeout=<number>
This defines the number of seconds an rsync connection can idle before rsync sees the connection as timed-out. This variable defaults to 180 but dialup users or individuals with slow computers might want to set this to 300 or higher.
--exclude-from=/etc/portage/rsync_excludes
This points to a file listing the packages and/or categories rsync should ignore during the update process. In this case, it points to /etc/portage/rsync_excludes.
--quiet
Reduces output to the screen.
--verbose
Prints a complete filelist.
--progress
Displays a progress meter for each file.
PORTAGE_RSYNC_RETRIES
Defines how many times rsync should try connecting to the mirror pointed to by the SYNC variable before bailing out. This variable defaults to 3.

For more information on these options and others, please read man rsync.

Gentoo configuration

Branch selection

It is possible to change the default branch with the ACCEPT_KEYWORDS variable. It defaults to the architecture's stable branch. More information on Gentoo's branches can be found in the next chapter.

Portage features

It is possible to activate certain portage features through the FEATURES variable. The Portage features have been discussed in previous chapters.

Portage behavior

Resource management

With the PORTAGE_NICENESS variable users can augment or reduce the nice value portage runs with. The PORTAGE_NICENESS value is added to the current nice value.

For more information about nice values, see the nice man page:

user $man nice

Output behavior

The NOCOLOR variable, which defaults to false, defines if Portage should disable the use of colored output.




Alpha Handbook
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装stage3
安装基本系统
配置Linux内核
配置系统
安装系统工具
配置系统引导程序Bootloader
收尾安装工作
使用Gentoo
Portage介绍
USE标记
Portage功能特性
初始化脚本(Initscript)系统
环境变量
使用Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
定制Portage树
高级特性
网络配置
入门
高级配置
模块化网络
无线
添加功能
动态管理


使用一个分支

稳定版

Gentoo提供了一个 ACCEPT_KEYWORDS变量来定义您系统所使用的软件分支。默认情况下,系统会选择您的体系结构的稳定软件分支alpha。

我们推荐您只使用默认的稳定软件分支。不过,如果您不是那么注重稳定性,并且愿意向http://bugs.gentoo.org提交一些bug报告来帮助和完善Gentoo,请继续阅读下面的内容。

测试

如果您想用最新版本的软件,您可以考虑转向使用测试分支。要让Portage转而使用测试分支的软件,您只需在您的体系结构名称前加上一个 ~符号。

顾名思义,“测试分支”就是带有测试性质的。如果一个包正处于测试中,这代表软件的开发人员认为它虽然已经具有了相当的功能但还没有经过完全的测试。使用这样的软件,您当然可能会第一个发现它的bug,并可以提交一个bug报告来通知相关的开发者。

要小心的是,您可能会遇到不稳定性、不完美的软件包处理(例如错误或者缺失的依赖关系)、过于频繁的更新(导致大量的编译)和损坏的包等问题。如果您还不是很清楚Gentoo的工作方式以及如何去解决这些问题,我们推荐您还是使用稳定且测试过分支。

例如,要选择针对 alpha 体系结构的测试分支,请修改 /etc/portage/make.conf 文件并设定如下内容:

FILE /etc/portage/make.conf使用测试分支
ACCEPT_KEYWORDS="~alpha"

之后如果您更新系统,您将会发现有大量的包需要更新。要提醒您注意的是:您使用测试分支更新系统后,再想转回使用官方的稳定分支将不是一件容易的事情。

混合使用稳定和测试分支

package.accept_keywords

您可以让Portage使用某些软件的测试分支中的版本,对于系统的其他软件则使用稳定分支。要实现这样的目的,您需要在/etc/portage/package.accept_keywords文件里加入那些软件包的名字及其所属分类的名称。您也可以建立一个同名文件夹,并在里面建立的文件里加入上述内容。

例如,要使用gnumeric属于测试分支中的版本:

FILE /etc/portage/package.accept_keywords混合使用稳定和测试分支gnumeric application例子
app-office/gnumeric

测试特定版本

如果您希望Portage使用测试分支中某软件的特定版本,但后续版本不再这么做,你可以在package.accept_keywords 里加入相应的版本号来实现这个目的。在此情况下您必须使用 = 运算符。您也可以通过使用<=,<,>或>=运算符来指定一个要使用的版本范围。

任何情况下,如果您添加了版本号,您必须使用一个运算符;如果您忽略了版本号,您就不能使用运算符。

在如下的例子中,我们要求Portage接受版本号为1.2.13的gnumeric:

FILE /etc/portage/package.accept_keywords允许gnumeric的测试版本
=app-office/gnumeric-1.2.13

使用被屏蔽的包

package.unmask

Important
The Gentoo developers do not support the use of unmasking packages. Please exercise due caution when doing so. Support requests related to package.unmask and/or package.mask might not be answered.

When a package has been masked by the Gentoo developers, yet despite the reason mentioned in the package.mask file (situated in /usr/portage/profiles/ by default) a user still wants to use this package, then add the desired version (usually this will be the exact same line from the package.mask file in the profile) to the /etc/portage/package.unmask file (or in a file in that directory if it is a directory).

For instance, if =net-mail/hotwayd-0.8 is masked, then it can be unmasked by adding the exact same line in the package.unmask location:

FILE /etc/portage/package.unmask使用特定版本
=net-mail/hotwayd-0.8
附注
如果 /usr/portage/profiles/package.mask 中的条目包含一系列软件包版本,则只需要取消屏蔽实际需要的版本即可。 请阅读上一节以了解如何指定版本。

package.mask

当您希望Portage忽略一个特定的软件包或者一个软件包的特定版本,您可以在/etc/portage/package.mask文件(或者此目录下的一个文件)中加入一行适当的内容来屏蔽它。

For instance, to prevent Portage from installing kernel sources newer than gentoo-sources-4.9.16, add the following line at the package.mask location:

FILE /etc/portage/package.maskMask gentoo-sources 高于 2.6.8.1 的版本
>sys-kernel/gentoo-sources-2.6.8.1




Alpha Handbook
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装stage3
安装基本系统
配置Linux内核
配置系统
安装系统工具
配置系统引导程序Bootloader
收尾安装工作
使用Gentoo
Portage介绍
USE标记
Portage功能特性
初始化脚本(Initscript)系统
环境变量
使用Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
定制Portage树
高级特性
网络配置
入门
高级配置
模块化网络
无线
添加功能
动态管理



dispatch-conf

dispatch-conf是一个帮助合并 ._cfg0000_<name>的工具。 ._cfg0000_<name>是由Portage在它要覆盖被CONFIG_PROTECT变量所保护的某个目录里的文件时建立的。

使用 dispatch-conf,能够在合并配置文件并升级更新的同时保持所有更新记录。 dispatch-conf以RCS版本管理系统或是补丁的方式来保存配置文件间的差别。这意味着如果你在升级配置文件犯下错误时,你可以随时退回到你的配置文件的之前版本。

使用 dispatch-conf,,你可以保持配置文件原来的样子,或者使用新的配置文件,你还可以编辑当前文件或交互式地合并更新。除此之外, dispatch-conf,还有一些很棒的特性:

  • 可以自动合并仅有注释变更的文件;
  • 可自动合并仅有空白符数量的不同的文件;

确定你先编辑了/etc/dispatch-conf.conf并创建了dispatch-conf变量设定的目录。

root #dispatch-conf

当运行 dispatch-conf的时候,程序会带你把每个改变了的配置文件挨个过一边。按 u来用新配置文件更新(替换)现在的配置文件,然后继续处理下一个。按w来删除新配置文件,然后继续处理下一个。当处理完所有的配置文件之后, dispatch-conf就会退出。你也可以随时按q 来退出。

更多信息,请查阅dispatch-conf手册页。它会告诉你交互式的合并新旧配置文件,编辑新配置文件,检查两个文件间的差异等等。

user $man dispatch-conf

etc-update

你也可以使用 etc-update来合并配置文件。它不像dispatch-conf那样简单易用,功能也少,但是它也能提供交互式合并功能并且能自动合并一些简单的改变。

不过,和dispatch-conf不同的是, etc-update不保留你的配置文件的旧版本。一旦你更新了文件,旧版本就永远丢失了。所以要非常小心,因为使用etc-update 与使用 dispatch-conf 相比明显的不安全。

root #etc-update

在整合简单直观的更动后,系统会提示你一个需要更新的受保护的文件列表。在最底下会提示你可选的操作选项:

CODE etc-update 输出选项
Please select a file to edit by entering the corresponding number.
              (-1 to exit) (-3 to auto merge all remaining files)
                           (-5 to auto-merge AND not use 'mv -i'):

如果你输入-1, etc-update将直接退出且不执行任何变更。如果你输入-3 或者 -5,所有列出的配置文件将被更新的版本覆盖。因此先选出无需自动升级的配置文件非常重要,而具体步骤也很简单,只需要输入在该配置文件左边显示的数字就可以了。

我们选择配置文件/etc/pear.conf作为范例:

CODE 更新指定的配置文件
Beginning of differences between /etc/pear.conf and /etc/._cfg0000_pear.conf
[...]
End of differences between /etc/pear.conf and /etc/._cfg0000_pear.conf
(1) Replace original with update
(2) Delete update, keeping original as is
(3) Interactively merge original with update
(4) Show differences again

现在你可以看到这两个文件之间的差别。如果你认为升级的配置文件可以正确无误的投入使用,输入1.。如果你认为升级的配置文件是不必要的,或者它也没有提供任何新的或有用的信息,输入2.。如果你想交互地升级你当前的配置文件,输入3.。

这里我们就不再赘述交互性整合的详细过程。出于完整性的考虑,我们将列出在整合两个文件时可以用到的所有的命令。你将看到来自新旧文件的两行内容和一个提示符,在提示符这里你可以输入以下命令:

CODE 用交互方式配置时可以使用的命令
ed:     Edit then use both versions, each decorated with a header.
eb:     Edit then use both versions.
el:     Edit then use the left version.
er:     Edit then use the right version.
e:      Edit a new version.
l:      Use the left version.
r:      Use the right version.
s:      Silently include common lines.
v:      Verbosely include common lines.
q:      Quit.

当你完成重要的配置文件的更新后,余下的其它配置文件你就可以采用自动更新的方法了。当无法再找到任何可更新的配置文件时etc-update将退出。

quickpkg

利用quickpkg可以对系统中已安装的包进行打包归档。这些归档文件可以作为预编译包使用。运行quickpkg非常简单:只要加上你想要制作的软件包的名字就可以了。

例如,要打包curl,arts,procps;

root #quickpkg curl orage procps

预编译包会保存在$PKGDIR/All(默认为(/usr/portage/packages/)。指向这些包的符号链接保存在$PKGDIR/CATEGORY.中。




Alpha Handbook
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装stage3
安装基本系统
配置Linux内核
配置系统
安装系统工具
配置系统引导程序Bootloader
收尾安装工作
使用Gentoo
Portage介绍
USE标记
Portage功能特性
初始化脚本(Initscript)系统
环境变量
使用Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
定制Portage树
高级特性
网络配置
入门
高级配置
模块化网络
无线
添加功能
动态管理


Using a subset of the Gentoo repository

Excluding packages and categories

It is possible to selectively update certain categories/packages and ignore the other categories/packages. This can be achieved by having rsync exclude categories/packages during the emerge --sync step.

Define the name of the file that contains the exclude patterns in the PORTAGE_RSYNC_EXTRA_OPTS variable in /etc/portage/make.conf:

FILE /etc/portage/make.confDefining the exclude file
PORTAGE_RSYNC_EXTRA_OPTS="--exclude-from=/etc/portage/rsync_excludes"
FILE /etc/portage/rsync_excludesExcluding all games
games-*/*

Note however that this may lead to dependency issues since new, allowed packages might depend on new but excluded packages.

Adding unofficial ebuilds

Defining a custom repository

It is possible to ask Portage to use ebuilds that are not officially available through the Gentoo repository. Create a new directory (for instance /usr/local/portage) in which to store the 3rd-party ebuilds. Use the same directory structure as the official Gentoo repository!

root #mkdir -p /usr/local/portage/{metadata,profiles}
root #chown -R portage:portage /usr/local/portage

Next, pick a sensible name for the repository. The next example uses "localrepo" as the name:

root #echo 'localrepo' > /usr/local/portage/profiles/repo_name

Tell Portage that the repository master is the main Gentoo repository, and that the repository should not be automatically synchronized (as it is not backed by an rsync server, git mirror or other repository source):

FILE /usr/local/portage/metadata/layout.conf
masters = gentoo
auto-sync = false

Finally, enable the repository on the local system by creating a repository configuration file inside /etc/portage/repos.conf, informing Portage where the local repository can be found:

FILE /etc/portage/repos.conf/localrepo.conf
[localrepo]
location = /usr/local/portage

Working with several overlays

For the power users who develop on several overlays, test packages before they hit the Gentoo repository or just want to use unofficial ebuilds from various sources, the app-portage/layman package brings layman, a tool to help users keep the overlay repositories up to date.

Alternatively, install app-eselect/eselect-repository to utilize the native synchronization in Portage. See also Eselect/Repository

eselect-repository

Adding repositories is simple with this tool.

For instance, to enable the hardened-development overlay:

root #eselect repository enable hardened-development

Updating of overlays added with this methods happens naturally with:

root #emerge --sync

Layman

First install and configure layman as shown in the Overlays User Guide, and add the desired repositories with layman -a.

For instance, to enable the hardened-development overlay:

root #layman -a hardened-development

Regardless of how many repositories are used through layman, all the repositories can be updated with the following command:

root #layman -S

For more information on working with overlays, please read man layman and the previously linked layman/overlay users' guide.

Non-Portage maintained software

Using Portage with self-maintained software

Sometimes users want to configure, install and maintain software individually without having Portage automate the process, even though Portage can provide the software titles. Known cases are kernel sources and Nvidia drivers. It is possible to configure Portage so it knows that a certain package is manually installed on the system (and thus take this information into account when calculating dependencies). This process is called injecting and is supported by Portage through the /etc/portage/profile/package.provided file.

For instance, to inform Portage about gentoo-sources-4.9.16 which has been installed manually, add the following line to /etc/portage/profile/package.provided:

FILE /etc/portage/profile/package.providedMarking gentoo-sources-4.9.16 as manually installed
sys-kernel/gentoo-sources-4.9.16
Note
This is a file that uses versions without an = operator.




Alpha Handbook
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装stage3
安装基本系统
配置Linux内核
配置系统
安装系统工具
配置系统引导程序Bootloader
收尾安装工作
使用Gentoo
Portage介绍
USE标记
Portage功能特性
初始化脚本(Initscript)系统
环境变量
使用Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
定制Portage树
高级特性
网络配置
入门
高级配置
模块化网络
无线
添加功能
动态管理


介绍

For most users, the information received thus far is sufficient for all their Linux operations. But Portage is capable of much more; many of its features are for advanced users or only applicable in specific corner cases. Still, that would not be an excuse not to document them.

Of course, with lots of flexibility comes a huge list of potential cases. It will not be possible to document them all here. Instead, we hope to focus on some generic issues which can then be bended to fit personal needs. More tweaks and tips can be found all over the Gentoo Wiki.

Most, if not all of these additional features can be easily found by digging through the manual pages that Portage provides:

user $man portage
user $man make.conf

Finally, know that these are advanced features which, if not worked with correctly, can make debugging and troubleshooting very difficult. Make sure to mention these when hitting a bug and opening a bug report.

Per-package environment variables

使用 /etc/portage/env

By default, package builds will use the environment variables defined in /etc/portage/make.conf, such as CFLAGS, MAKEOPTS and more. In some cases though, it might be beneficial to provide different variables for specific packages. To do so, Portage supports the use of /etc/portage/env and /etc/portage/package.env.

The /etc/portage/package.env file contains the list of packages for which deviating environment variables are needed as well as a specific identifier that tells Portage which changes to make. The identifier name is free format, and Portage will look for the variables in the /etc/portage/env/IDENTIFIER file.

Example: Using debugging for specific packages

As an example, we enable debugging for the media-video/mplayer package.

First of all, set the debugging variables in a file called /etc/portage/env/debug-cflags. The name is arbitrarily chosen, but of course reflects the reason of the deviation to make it more obvious later why a deviation was put in.

FILE /etc/portage/env/debug-cflagsSpecific variables for debugging
CFLAGS="-O2 -ggdb -pipe"
FEATURES="${FEATURES} nostrip"

Next, we tag the media-video/mplayer package to use this content:

FILE /etc/portage/package.envUsing debug-cflags for the mplayer package
media-video/mplayer debug-cflags

Hooking in the emerge process

Using /etc/portage/bashrc and affiliated files

When Portage works with ebuilds, it uses a bash environment in which it calls the various build functions (like src_prepare, src_configure, pkg_postinst, etc.). But Portage also allows users to set up a specific bash environment.

The advantage of using a specific bash environment is that it allows users to hook in the emerge process during each step it performs. This can be done for every emerge (through /etc/portage/bashrc) or by using per-package environments (through /etc/portage/env as discussed earlier).

To hook in the process, the bash environment can listen to the variables EBUILD_PHASE, CATEGORY as well as the variables that are always available during ebuild development (such as P, PF, ...). Based on the values of these variables, additional steps/functions can then be executed.

Example: Updating the file database

In this example, we'll use /etc/portage/bashrc to call some file database applications to ensure their databases are up to date with the system. The applications used in the example are aide (an intrusion detection tool) and updatedb (to use with mlocate), but these are meant as examples. Do not consider this as a guide for AIDE ;-)

To use /etc/portage/bashrc for this case, we need to "hook" in the postrm (after removal of files) and postinst (after installation of files) functions, because that is when the files on the file system have been changed.

FILE /etc/portage/bashrcHooking into the postinst and postrm phases
if [ "${EBUILD_PHASE}" == "postinst" ] || [ "${EBUILD_PHASE}" == "postrm" ];
then
  echo ":: Calling aide --update to update its database"
  aide --update
  echo ":: Calling updatedb to update its database"
  updatedb
fi

Executing tasks after --sync

Using /etc/portage/postsync.d location

Until now we've talked about hooking into the ebuild processes. However, Portage also has another important function: updating the Gentoo repository. In order to run tasks after updating the Gentoo repository, put a script inside /etc/portage/postsync.d and make sure it is marked as executable.

Example: Running eix-update

If eix-sync was not used to update the tree, then it is still possible to update the eix database after running emerge --sync (or emerge-webrsync) by putting a symlink to /usr/bin/eix called eix-update in /etc/portage/postsync.d.

root #ln -s /usr/bin/eix /etc/portage/postsync.d/eix-update
Note
If a different name would be chosen, then it needs to be a script that calls /usr/bin/eix-update instead. The eix binary looks at how it has been called to find out which function it has to execute. If a symlink would be created that points to eix yet isn't called eix-update, it will not run correctly.

Overriding profile settings

Using /etc/portage/profile

By default, Gentoo uses the settings contained in the profile pointed to by /etc/portage/make.profile (a symbolic link to the right profile directory). These profiles define both specific settings as well as inherit settings from other profiles (through their parent file).

By using /etc/portage/profile, users can override profile settings such as packages (what packages are considered to be part of the system set), forced use flags and more.

Example: Adding nfs-utils to the system set

When using an NFS-based file systems for rather critical file systems, it might be necessary to mark net-fs/nfs-utils as a system package, causing Portage to heavily warn administrators if they would attempt to unmerge it.

To accomplish that, we add the package to /etc/portage/profile/packages, prepended with a *:

FILE /etc/portage/profile/packagesMarking nfs-utils as a system package
*net-fs/nfs-utils

Applying non-standard patches

Using epatch_user

Note
The epatch_user function is applicable to EAPIs less than or equal to 5, see the eapply_user function for EAPIs greater than or equal to 6.

To manage several ebuilds in a similar manner, ebuild developers use eclasses (which are shell libraries) that define commonly used functions. One of these eclasses is epatch.eclass which offers a helpful function called epatch_user.

The epatch_user function applies source code patches that are found in /etc/portage/patches/<category>/<package>[-<version>[-<revision>]], whatever directory is found first. Sadly, not all ebuilds automatically call this function so just putting a patch in this location might not always work.

Luckily, with the information provided earlier in this chapter, users can call this function by hooking into, for instance, the prepare phase. The function can be called as many times as necessary - it will only apply the patches once.

Example: Applying patches to Firefox

The www-client/firefox package is one of the many that already call epatch_user from within the ebuild, so there is no need to override anything specific.

If for some reason (for instance because a developer provided a patch and asked to check if it fixes the bug reported) patching Firefox is wanted, all that is needed is to put the patch in /etc/portage/patches/www-client/firefox (probably best to use the full name and version so that the patch does not interfere with later versions) and rebuild Firefox.



Warning: Display title "Gentoo Linux alpha 手册:使用Portage" overrides earlier display title "手册:Alpha/全部/使用Portage".