升级Gentoo

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Upgrading Gentoo and the translation is 76% complete.
Outdated translations are marked like this.

Gentoo 有着独到的更新方式。本文将介绍如何 升级(更新) Gentoo,以及如何更好地维护系统。

保持 Gentoo 更新到最新版本十分重要。不止是为了获取最新版本的安全补丁,若长时间为更新,Gentoo 的安装流程可能会与现行版本脱节并且有时会使其更新过程更加繁复。

提示
尝试更新时,每日或每周更新 Gentoo Linux 可以更加丝滑地安装并获取最新的安全更新;而等待数周以上才更新可能会使事情变得更加复杂。为避免服务器压力,一天内请不要 同步 次数过多。
附注
本文不会涉及十年或以上的旧版本更新方法。 参见页面历史以了解旧版本说明。

关于 Gentoo 的架构和升级

Gentoo 的更新与其他 Linux 发行版不同。大多数发行版会每隔几个月或几年定期发布更新,是可预测的事件。

与之相反, Gentoo 是一个 滚动的 发行版。 你无需为获得最新版本的软件包而等待—— 一旦软件稳定即可被安装。 Gentoo 从一开始就是围绕着 快,增量更新的概念而设计的,因此 Gentoo 会有频繁的软件更新,为你带来最新最热的软件包。详情请参阅 FAQ,关于Gentoo的发行以及是什么使 Gentoo 脱颖而出

一旦安装好软件, 一次常规的更新 就会使所有的软件包更新最新状态。

在极少数情况下, 更新会对改动核心系统,对于这样的软件包, profile 的改动,亦或是Portage的更新,可能会需要在更新途中(或者更新后)作出手动的干预。 在此重要的情况下,以及Gentoo 仓库同步之后,news 模块会作出提示。请认真阅读 news 和 Portage 出现的信息。

Profile 就是Gentoo 系统的中心,正在于其可以行之有效地定义核心系统,一个新的profile 出现时,意味着Gentoo 的基本运作方式有所调整。Profile 是在安装时,根据使用目的而选定的,一般非必要不改动,或是仅在更新时改动。

升级软件包

手册为您提供了 更新Gentoo 仓库更新系统的一些细节。详情请见man emerge。 参见 同步仓库了解如何使用 emaint 同步的完整内容。

重要
请阅读在同步仓库后可能会出现的新闻条目

为使所有已安装软件更新到最新版本, 首要任务就是用emaint 更新Gentoo 仓库:

root #emaint --auto sync

或使用简写:

root #emaint -a sync

指令可能会输出上文提到的新闻条目。 如果配置文件更新在前一更新中被挂起,这可能提示你需要更新配置文件

运行 emerge 连带依赖一起升级整个系统:

root #emerge --ask --verbose --update --deep --newuse @world

或者,使用短选项:

root #emerge -avuDN @world

--newuse 可用--changed-use 来代替。但如果你不构建二进制包的话,使用--changed-use ,当添加或删减软件包中被禁用的USE 变量不会导致安装包的重新安装。参阅Binary package guide.

--with-bdeps=y 也可以被用于更新构建时间性依赖。

重要
注意Portage 在更新最后提示的信息。部分内容可见Portage log

如遇到Portage 报出依赖方面的错误,--backtrack=30 (或改为更高的数字)选项兴许会有用。原则上来讲,(出于性能缘故,)Portage 对如何解决依赖问题有着相对低的限制,有时甚至没有。

需要解决出现的任何配置文件的改动,可使用dispatch-conf:

root #dispatch-conf

升级之后的清理

更新之后,建议为Portage 运行emerge --depclean指令。 使用emerge --depclean必须要小心谨慎,它很可能会移除十分重要的软件包(e.g. kernel sources 或者 virtual package 中部分可选依赖)。

另请参阅
参阅 移除孤包 了解如何用 emerge --depclean 安全地移除长期未使用过的软件包。另参阅 Portage FAQ

配置文件更新说明

重要
在执行任何配置文件的更改之前需要阅读相关文档
警告
切换 systemd profile

前请仔细阅读systemd文档。

重要
请确保在执行任何配置文件的更改之前已同步 Gentoo 主存储库(Portage 树)。

当一个新的profile 可用时,Portage 会以新闻条目的形式告知用户。 (最近的消息会在官网列出)。

如果你的系统太过于老旧,是系统更新到最新状态可能会非常难,此时重新构建可能更佳。

一般来说,即使一个新的profile 问世,系统也并不强求你切换到新的profile 。系统在老版本的profile 中依然可以稳定运行。但是,Gentoo 还是强烈建议在配置文件被弃用时更新该配置文件,因为这意味着 Gentoo 开发人员不再计划支持它。

Profile 需要手动升级。这种升级的形式可能会因profile 而异;这取决于新的profile 的改动有多大。 在最简单的情况下,用户仅需用eselect 来修改/etc/portage/make.profile 的符号链接,在最坏的情况下可能会产生重要的重新配置,并从头重新编译整个系统,(虽然一般情况下变化不会太大,并且是可以被理解解释的——关键要点就是遵循说明)。

相关新闻条目中详细说明了迁移到新配置文件所需的具体内容。

通用信息

This is a generic outline of what is done to update a profile. As stated previously, specific instructions will be provided in a news item, for each new profile. A profile update often requires manual intervention, beyond just switching the profile version.

附注
There are desktop subprofiles for most architectures. Examine these profiles carefully, as they may serve the requirements better than the extremely minimal default profiles.
重要
The developer subprofile is specifically for Gentoo Linux development tasks. It is not meant to help set up general development environments.

使用 eselect 切换配置文件

Make sure warnings in parent section have been read.

为使用自动化工具切换profile ,请保证app-admin/eselect已被安装。eselect 程序便于查看和选择配置文件,无需手动创建或删除符号链接。

root #eselect profile list
root #eselect profile set <number>

手动切换配置文件

确保已经阅读上面章节的警告信息

Gentoo 也支持通过以下命令手动更改配置文件:

root #rm /etc/portage/make.profile
root #cd /etc/portage
root #ln -s ../../var/db/repos/gentoo/profiles/<selected profile> make.profile

更新到 17.1 配置文件

参阅17.1版本发布的新闻条目在此所有安装都应该用上17.1的profile ,迁移可能会有所困难。

更新到 17.0 配置文件

参阅17版本发布的新闻条目在此所有安装都应该用上17.1的profile ,迁移可能会有所困难。

升级旧系统

Sometimes, systems are too old to easily upgrade. It may be possible to manually update a very old system, but it may be better to start from scratch and copy system configuration an files from the old system to the new one.

Here is a rough guide to updating an old system. Another method can be found here.

概述

The idea with this upgrade approach is that we create an intermediate build chroot in which a recent stage3 is extracted. Then, using the tools available in the stage3 chroot we upgrade the packages on the live system.

警告
The commands below might be incomplete and serve more as a guidance rather than work instructions. Unless the approach is clear, it might be faster to just backup the important files and re-install Gentoo.

Preparing the intermediate build chroot

Let's first create the intermediate build chroot location, say /mnt/build, and extract a recent stage3 archive into it.

root #mkdir -p /mnt/build
root #tar -xf /path/to/stage3-somearch-somedate.tar.bz2 -C /mnt/build
root #mount --rbind /dev /mnt/build/dev
root #mount --rbind /proc /mnt/build/proc
root #mount --rbind /sys /mnt/build/sys

Next, we create a mount point inside this chroot environment, on which we then bind-mount the live (old) environment.

root #mkdir -p /mnt/build/mnt/host
root #mount --rbind / /mnt/build/mnt/host

So now the live (old) system is also reachable within /mnt/build/mnt/host. This will allow us to reach the live (old) system and update the packages even when chrooted inside the intermediate build chroot.

网络、chroot 和更新

新安装需要访问网络,因此复制网络相关的信息:

root #cp -L /etc/resolv.conf /mnt/build/etc/

Now chroot into the intermediate build location, and start updating vital packages on the live system, until the live system can be updated from within the live system (rather than through the intermediate build chroot):

root #chroot /mnt/build
root #source /etc/profile
root #export PS1="(chroot) ${PS1}"
(chroot) root #emerge --sync

It may be a good idea to check that the profile and Portage configuration are compatible between the (old) live system and the chroot.

Now start building packages into the (old) live system. If Portage is old or missing, it is a good idea to start with that:

(chroot) root #emerge --root=/mnt/host --config-root=/mnt/host --verbose --oneshot sys-apps/portage

Keep this chrooted session open and try to update the (old) live system. When failures occur, use this chrooted session to update packages using the build tools available in the intermediate build chroot (which includes recent sys-libs/glibc, sys-devel/gcc, etc.). Tools can be added as needed to the build chroot.

重要
在 chroot 中执行的所有 emerge 命令别忘了添加 --root=/mnt/host --config-root=/mnt/host !否则,将更新 chroot 本身,而不是(旧的)live 系统。

For some installations it may be necessary to update configuration files in order to install new software. Make the changes in the chroot environment.

To get the system fully up-to-date before exiting the root, build the @world set (all packages) into the (old) live system:

(chroot) root #emerge --root=/mnt/host --config-root=/mnt/host --update --newuse --deep --ask @world

这些都完成后,现在使用的应该就是最新的系统!

另请参阅

External resources


This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: Gregorio Guidi, Chris Gianelloni, Joshua Saddler
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.