Gentoo Linux 手册:安装Gentoo

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:PPC/Full/Installation and the translation is 100% complete.



介绍

欢迎

欢迎使用 Gentoo!Gentoo 是一个基于 Linux 的自由操作系统,他可以针对任何应用或需求进行自动优化和定制。 它基于自由软件生态系统,不会向用户隐瞒背后运行的内容。

开放

Gentoo 的主要工具是用简单的编程语言构建的。Portage/zh-cn 是 Gentoo 的软件包维护系统,他是 由 Python 编写的。Ebuilds 为 Portage 定义软件包,他是由 bash 编写的。我们鼓励用户审查、修改和完善 Gentoo 所有源代码。

默认情况下,软件包只在必要时才会打补丁,比如修复漏洞或者提供与 Gentoo 互操作。软件包通过上游项目提供的源代码编译成二进制格式,然后安装到系统中(尽管也支持预编译二进制包)。也可以通过文本文件配置 Gentoo。

出于上述和其他原因:开放是 Gentoo 设计原则之一。

选择

Gentoo 的另一个设计原则选择

安装 Gentoo 时,选择贯穿于整个手册中。系统管理员可以选择两种完全支持的 init 系统(Gentoo 自己的 OpenRC 和 Freedesktop.org 的 systemd),存储磁盘的分区结构,磁盘使用什么文件系统,目标 系统配置文件,通过 USE 标记对全局(系统级)或特定软件包移除、添加特性,启动引导,网络管理工具,还有很多很多。

作为一种开发哲学, Gentoo 的作者尽量避免强迫用户使用特定的系统配置文件或桌面环境。如果一些东西在 GNU/Linux 生态系统中有,那很有可能在 Gentoo 中也能使用。即使 GNU/Linux 没有,我们也很乐意看到他。如果要添加新的软件包,请提交 bug 报告或者创建你自己的 ebuild 仓库。

强力

作为一个基于源代码的操作系统,Gentoo 可以移植到新计算机指令集架构上,还可以对所有安装的软件包进行调整。这一优势体现了 Gentoo 的另一个设计原则强力

A system administrator who has successfully installed and customized Gentoo has compiled a tailored operating system from source code. The entire operating system can be tuned at a binary level via the mechanisms included in Portage's make.conf file. If so desired, adjustments can be made on a per-package basis, or a package group basis. In fact, entire sets of functionality can be added or removed using USE flags.

手册的读者必须明白,这些设计原则正是 Gentoo 的独特之处。由于 Gentoo 着重强调了强大的功能、多种选择和极度开放的原则,因此在使用 Gentoo 时应多努力、多思考、多用心。

安装步骤

Gentoo的安装可以被分成10个步骤,分别对应后续的章节。执行完每个步骤,都会让系统进入某种确定的状态:

步骤 结果
1 用户处于一个准备好安装 Gentoo 的工作环境中。
2 用于安装 Gentoo 的互联网连接已经准备完毕。
3 硬盘已经为 Gentoo 的安装初始化完毕。
4 安装环境已经准备好,用户准备 chroot 到新环境中去。
5 那些在所有Gentoo安装中都相同的核心软件包已经安装完毕。
6 Linux内核已经安装完毕。
7 用户已经创建好大部分的 Gentoo 系统配置文件。
8 必要的系统工具已经安装完毕。
9 合适的启动引导程序 (Bootloader) 已经安装配置完毕。
10 登录系统,你就可以在已经全新安装完毕的 Gentoo Linux 系统中尽情探索了!

当面临选择的时候,手册上会尽量说明每个选择的利弊。虽然手册会以默认选择(标题中有 "默认Default:" 标记)继续描述下去,但其他可能的选择同样也会在文档中说明(标题中有 "可选Alternative:" 标记)。请不要认为默认选项是 Gentoo的推荐选项。这只是 Gentoo 认为大多数用户会使用的选项。

有时候你也可以进行一些可选的步骤。这样的步骤会被标注为"可选Optional:",当然这些步骤对于安装Gentoo来说就不是必须的。然而,有些可选的步骤依赖于你先前所做出的决定。我们将会在你需要做这样决定以及可选步骤出现的时候提醒你。

选择合适的方法安装Gentoo

Gentoo可以以许多不同的方式安装。 它可以从官方Gentoo安装介质(如我们的可引导ISO文件)下载和安装。 安装介质可以安装在USB盘上或通过网络引导环境访问。 或者,Gentoo可以从非官方介质安装,如已安装的发行版或非Gentoo可启动磁盘(如Knoppix)。

本文讲解了如何使用Gentoo官方安装光盘或者在某些情况下使用网络启动来安装Gentoo。

附注
需要其他安装方式的帮助(包括使用非Gentoo的Linux引导介质)请阅读我们的其他安装方式

我们也提供一篇 Gentoo 安装提示和技巧文档,它可能会有用。

遇到麻烦

如果在安装(或安装文档中)发现问题,请访问我们的 bug 跟踪系统,并确认这个 Bug 是否已经被提交。如果没有提交,请为它创建一个错误报告以方便我们的后续处理。不要害怕和被分配解决这个问题的开发人员交流——他们(通常)不吃人。

虽然你当前阅读的文档是针对某一特定的硬件架构,但是它可能还是会包含对其他平台架构的引用,因为Gentoo手册中的绝大部分在所有硬件架构都相同(避免重复劳动)。为了避免混淆,我们把这样的引用保持在最低限度。

如果你不能确定你的问题是使用者的操作问题(尽管你已经仔细地阅读了文档但仍然出了错)还是一个软件问题(尽管我们已经仔细地测试了安装步骤/文档但仍然出了错)。请联系我们: irc.libera.chat 上的 #gentoo (webchat)。当然,如果你有其他方面的关于Gentoo的问题,我们也欢迎你来这里讨论。

说到这里,如果还有任何额外的Gentoo问题,看看我们常见问题 ,或者Gentoo论坛 上的 FAQs





硬件需求

安装之前,为了使 ppc 系统架构能成功安装 Gentoo,我们应该满足最低硬件要求。

Handbook:PPC/Blocks/HWReqs/zh-cn

使用Gentoo Linux安装光盘

提示
虽然推荐使用官方安装媒介,但还是可以选择其他非 Gentoo 安装媒介。Gentoo 安装媒介可以确保 live 操作系统环境中有必要的工具。当使用非 Gentoo 安装媒介时,可以直接跳到准备磁盘

最小化安装CD

Gentoo最小化安装CD是一张可引导镜像:包含有完整Gentoo环境的。它允许用户从CD或其它安装媒介引导进入Linux。在引导过程中将检测硬件并加载适当的驱动。这个镜像由Gentoo开发人员维护,能让任何有Internet连接的人来安装Gentoo。

最小化安装 CD 命名的格式为: install-<arch>-minimal-<release timestamp>.iso

偶尔用到的Gentoo LiveDVD

有时,需要用一张特制的DVD安装Gentoo。本章的介绍是针对最小化安装CD的,因此从LiveDVD引导可能会有一点不同。不管怎么样,LiveDVD(或任何其他官方 Gentoo Linux 环境)支持通过在终端输入 sudo su - 或者 sudo -i 来获取root权限。

stage 文件是什么?

stage3压缩包是一个包含有最小化的特定profile的Gentoo环境的压缩包,Stage3可用来按照本手册介绍继续安装Gentoo。以前的Gentoo手册描述了使用三个 stage tarballs 的其中一个来进行安装。Gentoo不再提供stage1和stage2压缩包供下载,因为它们主要用于内部使用和在新架构上对Gentoo进行bootstrap。

stage 3 文件可以在任意一个Gentoo官方镜像站releases/ppc/autobuilds/ 内下载。Stage 文件更新比较频繁因此不不包含在官方 live 镜像中。

提示
For now, stage files can be ignored. They will be described in greater detail later when they are needed
附注
Historically, the handbook described installation steps for stage files with versions lower than 3. These stages contained environments unsuitable for typical installations, and are no longer covered in the handbook.

下载

获得安装媒介

Gentoo Linux使用最小化安装CD做为默认安装媒介,它带有一个非常小的可引导的Gentoo Linux环境。此环境包含所有正确的安装工具. CD镜像本身可以从官方下载页(推荐)或任意一个镜像站下载。

Navigating Gentoo mirrors

在这些镜像站上,最小化安装CD可以通过以下方式找到:

  1. 连接到镜像,通常在 Gentoo source mirrors 找到一个本地镜像使用。
  2. 导航到 releases/ 目录
  3. 选择相应的架构, 如 ppc/
  4. 选择 autobuilds/ 目录
  5. 对于 amd64x86 平台的用户,请选择 current-install-amd64-minimal/current-install-x86-minimal/ 目录。如果需要所有其它平台的,请进入 current-iso/ 目录。
附注
一些架构例如armmips,和s390 是没有最小化安装 CD 的。 这是因为 Gentoo 发行工程项目 ( Gentoo Release Engineering project ) 不支持构建这些平台的.iso文件。

在这个位置,安装媒体文件是那些带有.iso扩展名的文件。比如下面的清单:

代码 releases/amd64/autobuilds/current-install-amd64-minimal/ 内可下载的文件列表示例
[TXT]	install-amd64-minimal-20231112T170154Z.iso.asc	        2023-11-12 20:41        488
[TXT]	install-amd64-minimal-20231119T164701Z.iso.asc	        2023-11-19 18:41        488
[TXT]	install-amd64-minimal-20231126T163200Z.iso.asc	        2023-11-26 18:41        488
[TXT]	install-amd64-minimal-20231203T170204Z.iso.asc	        2023-12-03 18:41        488
[TXT]	install-amd64-minimal-20231210T170356Z.iso.asc	        2023-12-10 19:01        488
[TXT]	install-amd64-minimal-20231217T170203Z.iso.asc	        2023-12-17 20:01        488
[TXT]	install-amd64-minimal-20231224T164659Z.iso.asc	        2023-12-24 20:41        488
[TXT]	install-amd64-minimal-20231231T163203Z.iso.asc	        2023-12-31 19:01        488
[ ]     install-amd64-minimal-20240107T170309Z.iso              2024-01-07 20:42        466M
[ ]     install-amd64-minimal-20240107T170309Z.iso.CONTENTS.gz	2024-01-07 20:42        9.8K
[ ]     install-amd64-minimal-20240107T170309Z.iso.DIGESTS      2024-01-07 21:01        1.3K
[TXT]   install-amd64-minimal-20240107T170309Z.iso.asc	        2024-01-07 21:01        488
[ ]     install-amd64-minimal-20240107T170309Z.iso.sha256       2024-01-07 21:01        660
[TXT]	latest-install-amd64-minimal.txt                        2024-01-08 02:01        653

在上面的例子中,install-amd64-minimal-20240107T170309Z.iso 文件是最小化安装CD。但可以看到,还有其他相关文件存在:

  • .CONTENTS.gz 文件是使用 gz 压缩的文本文件,它列出了安装媒介中的所有文件。这个文件可用于在下载前确认安装媒介是否包含特定的固件和驱动程序。
  • .DIGESTS 文件包含了ISO文件的 Hash 值,有不同的 Hash 格式/算法。这个文件可以用来验证已 ISO 文件完整性。
  • .asc 文件是 ISO 文件的加密签名。这个文件即可用于验证镜像完整性和准确性 —— 下载的文件确实是由 Gentoo 发行工程团队 提供的,以免文件被篡改。

现在可以先忽略当前位置的其他文件——它们在安装的后续步骤中会被提到。下载 .ISO,另外如果想要验证下载的文件,同时下载ISO文件对应的 .iso.asc

提示
.DIGESTS 文件只在 .iso.asc 文件签名未验证时需要。

校验下载的文件

附注
这是一个可选步骤,并不是安装 Gentoo Linux 所必须的。但是,我们仍然推荐这么做,以此来确保下载的文件没有损坏,以及确保下载文件确实由 Gentoo基础设施团队提供。

.asc 文件提供了 ISO 的加密签名。验证了加密签名,可以确保安装文件是由Gentoo发行工程组( Gentoo Release Engineering team )提供,并且没有损坏和修改。

在微软 Windows 操作系统上校验

首先验证文件加密签名,可以使用类似 GPG4Win 这样的工具。安装完工具后,需要导入 Gentoo 发行工程组(Gentoo Release Engineering Team)的公钥。 公钥列表在: 数字签名页。导入完成后,用户就可以验证 .DIGESTS.asc 文件的签名。

在已有的 Linux 系统上校验

在 Linux 系统上,最常用的验证加密签名的方法就是使用 app-crypt/gnupg 这个软件。安装此程序后,就可以使用以下命令来验证 .asc 文件中的加密签名。

提示
导入 Gentoo 密钥时,需要验证指纹与 (BB572E0E2D182910) 匹配。
Gentoo 密钥可以从 hkps://keys.gentoo.org 下载,可用的指纹可以在数字签名页 找到:
user $gpg --keyserver hkps://keys.gentoo.org --recv-keys 13EBBDBEDE7A12775DFDB1BABB572E0E2D182910
gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key BB572E0E2D182910: public key "Gentoo Linux Release Engineering (Automated Weekly Release Key) <releng@gentoo.org>" imported
gpg: Total number processed: 1
gpg:               imported: 1

或者,您可以使用 WKD 来下载密钥:

user $gpg --auto-key-locate=clear,nodefault,wkd --locate-key releng@gentoo.org
gpg: key 9E6438C817072058: public key "Gentoo Linux Release Engineering (Gentoo Linux Release Signing Key) <releng@gentoo.org>" imported
gpg: key BB572E0E2D182910: public key "Gentoo Linux Release Engineering (Automated Weekly Release Key) <releng@gentoo.org>" imported
gpg: Total number processed: 2
gpg:               imported: 2
gpg: no ultimately trusted keys found
pub   dsa1024 2004-07-20 [SC] [expires: 2025-07-01]
      D99EAC7379A850BCE47DA5F29E6438C817072058
uid           [ unknown] Gentoo Linux Release Engineering (Gentoo Linux Release Signing Key) <releng@gentoo.org>
sub   elg2048 2004-07-20 [E] [expires: 2025-07-01]

或者使用 Gentoo 官方发行的安装媒介,从 /usr/share/openpgp-keys/gentoo-release.asc 导入密钥(由 sec-keys/openpgp-keys-gentoo-release 提供):

user $gpg --import /usr/share/openpgp-keys/gentoo-release.asc
gpg: directory '/home/larry/.gnupg' created
gpg: keybox '/home/larry/.gnupg/pubring.kbx' created
gpg: key DB6B8C1F96D8BF6D: 2 signatures not checked due to missing keys
gpg: /home/larry/.gnupg/trustdb.gpg: trustdb created
gpg: key DB6B8C1F96D8BF6D: public key "Gentoo ebuild repository signing key (Automated Signing Key) <infrastructure@gentoo.org>" imported
gpg: key 9E6438C817072058: 3 signatures not checked due to missing keys
gpg: key 9E6438C817072058: public key "Gentoo Linux Release Engineering (Gentoo Linux Release Signing Key) <releng@gentoo.org>" imported
gpg: key BB572E0E2D182910: 1 signature not checked due to a missing key
gpg: key BB572E0E2D182910: public key "Gentoo Linux Release Engineering (Automated Weekly Release Key) <releng@gentoo.org>" imported
gpg: key A13D0EF1914E7A72: 1 signature not checked due to a missing key
gpg: key A13D0EF1914E7A72: public key "Gentoo repository mirrors (automated git signing key) <repomirrorci@gentoo.org>" imported
gpg: Total number processed: 4
gpg:               imported: 4
gpg: no ultimately trusted keys found

下一步,验证加密签名:

user $gpg --verify install-amd64-minimal-20240107T170309Z.iso.asc
gpg: assuming signed data in 'install-amd64-minimal-20240107T170309Z.iso'
gpg: Signature made Sun 07 Jan 2024 03:01:10 PM CST
gpg:                using RSA key 534E4209AB49EEE1C19D96162C44695DB9F6043D
gpg: Good signature from "Gentoo Linux Release Engineering (Automated Weekly Release Key) <releng@gentoo.org>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 13EB BDBE DE7A 1277 5DFD  B1BA BB57 2E0E 2D18 2910
     Subkey fingerprint: 534E 4209 AB49 EEE1 C19D  9616 2C44 695D B9F6 043D

为了绝对确定所有文件都是有效的,验证上面显示的密匙指纹信息是否和 数字签名页 的密匙指纹信息一致。

附注
It's generally good practice to mark an imported key as trusted, once it's certain the key is trustworthy. When trusted keys are verified, gpg will not say unknown and warn about the signature being untrusted.

Writing the boot media

当然,只是下载一个 ISO 文件是无法开始 Gentoo Linux 的安装的。需要将这个ISO文件刻录成一张用来启动的 CD 光盘,是要将 ISO 文件里的内容而不是 ISO 文件本身刻录到CD光盘上。下面介绍了一些常见的方式 - 这里可以找到其他更复杂的方式:如何刻录ISO文件

Writing a bootable USB

大多数的现代系统支持从 USB 设备启动。

使用 Linux 写入

dd is typically available on most Linux distros, and can be used to write the Gentoo boot media to a USB drive.

Determining the USB device path

Before writing, the path to the desired storage device must be determined.

dmesg will display detailed information describing the storage device as it is added to the system:

root #dmesg
[268385.319745] sd 19:0:0:0: [sdd] 60628992 512-byte logical blocks: (31.0 GB/28.9 GiB)

Alternatively, lsblk can be used to display available storage devices:

root #lsblk
sdd           8:48   1  28.9G  0 disk
├─sdd1        8:49   1   246K  0 part
├─sdd2        8:50   1   2.8M  0 part
├─sdd3        8:51   1 463.5M  0 part
└─sdd4        8:52   1   300K  0 part

Once the device name has been determined, this can be added to the path prefix /dev/ to get the device path /dev/sdd.

提示
Using the base device path, ie. sdd opposed to sdd1, is recommend as the Gentoo boot media contains a full GPT partition scheme.
使用 dd 写入
警告
Be sure to check the target (of=target) path before executing dd, as it will be overwritten.

With the device path (/dev/sdd) and boot media install-amd64-minimal-<release timestamp>.iso ready:

root #dd if=install-amd64-minimal-<release timestamp>.iso of=/dev/sdd bs=4096 status=progress && sync
附注
if= specifies the input file, of= specifies the output file, which in this case, is a device.
提示
bs=4096 is used as it speeds up transfers in most cases, status=progress displays transfers stats.

刻录光盘

另请参阅
A more elaborate set of instructions can be found in CD/DVD/BD_writing#Image_writing.

在Microsoft Windows 7和更高版本上刻录

Microsoft Windows 7 及更高版本可以将 ISO 映像装载和刻录到光学媒体,无需第三方软件。 只需插入可刻录磁盘,浏览到下载的 ISO 文件,在 Windows 资源管理器中右键单击该文件,然后选择“刻录磁盘映像”。

在已有的 Linux 系统上刻录

app-cdr/cdrtools中的cdrecord可以在Linux下烧录ISO镜像

将ISO文件刻录到 /dev/sr0 设备的 CD 光碟上(这是系统上的第一个 CD 设备-在必要时将其替换为正确的设备):

user $cdrecord dev=/dev/sr0 install-ppc-minimal-20141204.iso

喜欢使用图形化界面的用户可以使用 K3B ,它由 kde-app/k3b 软件包提供。在 K3B 软件中,选择“工具”Tools)菜单,然后选择“刻录CD镜像”(Burn CD Image)。

启动

Handbook:PPC/Blocks/Booting/zh-cn

额外的硬件配置

当安装媒介启动时,它会尝试检测所有的硬件设备并加载合适的内核模块来支持硬件。在绝大多数的情况下,它工作得很好。然而,在某些情况下它可能没有自动加载系统所需的内核模块。如果 PCI 自动检测错过了一些系统硬件,相应的内核模块就必须手动加载了。

下面例子手工加载了 8139too 模块(它提供对某些类型的网卡的支持):

root #modprobe 8139too

可选:用户账号

如果其他人需要访问安装环境,或者需要以非 root 用户的身份在安装媒介上运行命令(例如出于安全原因使用没有 root 特权的 irssi 聊天),这时就需要创建额外的用户帐户,并将 root 用户密码设为强密码。

使用 passwd 命令来修改 root 用户密码:

root #passwd
New password: (Enter the new password)
Re-enter password: (Re-enter the password)

要创建一个用户账户,先输入他们的信息,然后设置密码。用 useraddpasswd 命令来完成这些操作。

在下面的例子中,创建了一个名为“john”的用户。

root #useradd -m -G users john
root #passwd john
New password: (Enter john's password)
Re-enter password: (Re-enter john's password)

使用 su 命令可以从 root 用户(当前用户)切换到新建的用户:

root #su - john

可选:在安装时查看文档

终端

要在安装期间查看 Gentoo 安装手册,首先要按照上面的方法创建一个新的用户帐户。然后按 Alt+F2 进入一个新的终端(TTY)。

在安装期间,可以用 links web 浏览器来浏览 Gentoo 安装手册——当然,只有在互联网连接可用的时候才行。

user $links https://wiki.gentoo.org/wiki/Handbook:PPC/zh-cn

要回到原来的终端,请按 Alt+F1

提示
启动到最小化 Gentoo 或者 Gentoo 管理环境后,有 7 个终端可供使用。可以按 AltF1F7 之间的功能键来切换。当等待任务完成的时候,切换到一个新的终端可以很方便的用来打开文档等。

GNU Screen

Screen 是官方Gentoo安装介质中默认安装的实用程序。对于经验丰富的Linux爱好者来说,使用 screen 分割窗口查看安装说明,而不是上面提到的多个终端的方法, 这可能更高效。

可选:启动SSH服务

要在安装期间允许其他用户访问你的系统(可能是为了在安装过程中提供技术支持,甚至远程安装),需要添加一个用户账户(就像之前的文档描述的那样)同时 SSH 服务也要启动。

若要在 OpenRC init 启动 SSH 服务,请执行以下命令:

root #rc-service sshd start
附注
如果用户登录到系统,他们将看到一个本系统主机密钥需要确认的信息(也就是我们说的密匙指纹)。此行为是典型的并且可以像预期一样与SSH服务器进行初始连接。但是,以后当系统设置好,并有人登录到新安装的系统时,SSH客户端会警告主机密钥已被更改。这是因为现在用户登录 - 对于SSH来讲 - 是一个不同的服务器(即新安装的Gentoo系统,而不是现在正在使用的安装系统环境)。请按照屏幕上的指示,去替换用户端的主机密钥

网络需要能正常工作,sshd 才能使用。请参照 配置网络 的内容继续安装。





自动网络检测配置

它能够自动检测到么?

如果系统接入到一个有 DHCP 服务器的以太网络,那么很可能会自动配置好网络。这样的话,安装媒介所包含的很多网络命令,比如sshscppingirssiwgetlinks,以及其他的一些命令, 都可以立即工作。

使用DHCP

DHCP(动态主机配置协议)使自动接受网络信息(IP地址、掩码、广播地址、网关、名称服务器等)变得容易。这只在网络中有DHCP服务器(或者如果ISP提供商提供一个DHCP服务)时有用。要使一个网络接口自动接受信息,使用dhcpcd

DHCP requires that a server be running on the same Layer 2 (Ethernet) segment as the client requesting a lease. DHCP is often used on RFC1918 (private) networks, but is also used to acquire public IP information from ISPs.

提示
Official Gentoo boot media runs dhcpcd automatically at startup. This behavior can be disabled by adding the nodhcp argument to the boot media kernel commandline.

If it is not already running, dhcpcd can be started on enp1s0 with:

root #dhcpcd enp1s0

一些网络管理员要求你使用DHCP服务器所提供的主机名和域名。 这种情况下请用:

root #dhcpcd -HD enp1s0

如果要停止 dhcpcd,可以使用 -x

root #dhcpcd -x
sending signal Term to pid 10831
waiting for pid 10831 to exit
另请参阅
使用 Dhcpcd

测试网络

A properly configured default route is a critical component of Internet connectivity, route configuration can be checked with:

root #ip route
default via 192.168.0.1 dev enp1s0

If no default route is defined, Internet connectivity is unavailable, and additional configuration is required.

Basic internet connectivity can be confirmed with a ping:

root #ping -c 3 1.1.1.1
提示
It's helpful to start by pinging a known IP address instead of a hostname. This can isolate DNS issues from basic Internet connectivity issues.

Outbound HTTPS access and DNS resolution can be confirmed with:

root #curl --location gentoo.org --output /dev/null

如果这些都工作,则本章节中其余的部分可跳过,直接跳到安装介绍的下一步骤(准备磁盘)。

If curl reports an error, but Internet-bound pings work, DNS may need configuration.

If Internet connectivity has not been established, first interface information should be verified, then:

获取接口信息

If networking doesn't work out of the box, additional steps must be taken to enable Internet connectivity. Generally, the first step is to enumerate host network interfaces.

ip 命令,属于 sys-apps/iproute2 软件包,他可以用来查询和配置系统网络。

link 参数可以用来显示网络接口的链接:

root #ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether e8:40:f2:ac:25:7a brd ff:ff:ff:ff:ff:ff

address 参数可以查询设备地址信息:

root #ip address
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether e8:40:f2:ac:25:7a brd ff:ff:ff:ff:ff:ff
    inet 10.0.20.77/22 brd 10.0.23.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::ea40:f2ff:feac:257a/64 scope link 
       valid_lft forever preferred_lft forever

The output of this command contains information for each network interface on the system. Entries begin with the device index, followed by the device name: enp1s0.

提示
如果使用标准的ifconfig命令没有显示出接口,尝试使用带有-a选项的相同的命令。这个选项强制这个工具去显示系统检测到的所有的网络接口,不管他们是up或down状态。如果ifconfig -a没有提供结果,则硬件有错误或者接口驱动没有加载到内核中。这些情况都超过本手册的范围。联系#gentoo (webchat)需求支持。

为了保持一致性,本手册中假设主要的网络接口为 enp1s0

因为名称变成了预测的网络接口名称(Predictable Network Interface Names), 所以系统的接口名称可能和旧的 eth0 命名规则很不一样。近期的安装媒介上常规网络接口名字可能显示为 eno0ens1enp5s0。查看 ifconfig 输出中找到有你本地网络相关的IP地址的接口。

Optional: Application specific configuration

The following methods are not generally required, but may be helpful in situations where additional configuration is required for Internet connectivity.

可选:配置网络代理

如果需要通过代理来访问互联网。那么必须为 Portage 定义代理信息,这样才能正确访问每个支持协议的代理。 Portage 使用 http_proxyftp_proxyRSYNC_PROXY 环境变量,通过 wgetrsync 的检索机制来下载软件包。

Certain text-mode web browsers such as links can also make use of environment variables that define web proxy settings; in particular for the HTTPS access it also will require the https_proxy environment variable to be defined. While Portage will be influenced without passing extra run time parameters during invocation, links will require proxy settings to be set.

大多数情况下,只要将这个环境变量定义为代理服务器主机名。在下面的例子中,假定代理服务器的主机是 proxy.gentoo.org 并且端口为 8080。

附注
下列命令中的 # 符号是注释。添加 # 符号只是为了清楚起见,在输入命令时需要输入 # 符号。

定义一个 HTTP 代理(用于 HTTP 和 HTTPS 流量):

root #export http_proxy="http://proxy.gentoo.org:8080" # 同时应用到 Portage 和 Links
root #export https_proxy="http://proxy.gentoo.org:8080" # 只应用到 Links

如果代理需要验证,使用下面的语法来设置用户名和密码:

root #export http_proxy="http://username:password@proxy.gentoo.org:8080" # 同时应用到 Portage 和 Links
root #export https_proxy="http://username:password@proxy.gentoo.org:8080" # 只应用到 Links

使用下列参数启动可以为 links 使用代理:

user $links -http-proxy ${http_proxy} -https-proxy ${https_proxy}

为 Portage 和 links 定义 FTP 代理:

root #export ftp_proxy="ftp://proxy.gentoo.org:8080" # 同时应用到 Portage 和 Links

使用下列参数启动可以为 links 使用 FTP 代理:

user $links -ftp-proxy ${ftp_proxy}

为 Portage 定义 RSYNC 代理:

root #export RSYNC_PROXY="proxy.gentoo.org:8080" # 应用到 Portage:Links 不支持 rsync 代理

对 ADSL 使用 pppoe-setup

If PPPoE is required for Internet access, the Gentoo boot media includes the pppoe-setup script to simplify ppp configuration.

安装时,pppoe-setup 会询问:

  • 连接到 ADSL 调制解调器的以太网 接口 名称。
  • PPPoE 用户名和密码。
  • DNS 服务器 IP。
  • 是否需要防火墙。
root #pppoe-setup
root #pppoe-start

In the event of failure, credentials in /etc/ppp/pap-secrets or /etc/ppp/chap-secrets should be verified. If credentials are correct, PPPoE Ethernet interface selection should be checked.

使用 PPTP

如果需要 PPTP 支持,可以使用 pptpclient,但是需要在使用前提前配置。

编辑 /etc/ppp/pap-secrets 或者 /etc/ppp/chap-secrets,让他们包含正确的用户名和密码:

root #nano /etc/ppp/chap-secrets

如果需要,继续调整/etc/ppp/options.pptp

root #nano /etc/ppp/options.pptp

配置完成后,运行 pptp(带着一些options.pptp无法设定的选项)来连接到服务器:

root #pptp <server ipv4 address>

配置 WEP

警告
Do not use WEP unless it is the only option. WEP provides essentially no security over an open network.
附注
可能只有特定的架构支持iw命令。如果这个命令不可用,检查net-wireless/iw包是否可用于当前架构。除非安装net-wireless/iw包,否则iw命令将一直不可用。

当使用一块无线(802.11)网卡,在继续之前需要先配置无线设置。要查看当前无线网卡的设置,你可以使用iw。运行iw可能会显示如下:

root #iw dev wlp9s0 info
Interface wlp9s0
	ifindex 3
	wdev 0x1
	addr 00:00:00:00:00:00
	type managed
	wiphy 0
	channel 11 (2462 MHz), width: 20 MHz (no HT), center1: 2462 MHz
	txpower 30.00 dBm

检查当前连接:

root #iw dev wlp9s0 link
Not connected.

root #iw dev wlp9s0 link
Connected to 00:00:00:00:00:00 (on wlp9s0)
	SSID: GentooNode
	freq: 2462
	RX: 3279 bytes (25 packets)
	TX: 1049 bytes (7 packets)
	signal: -23 dBm
	tx bitrate: 1.0 MBit/s
附注
一些无线网卡的设备名可能是wlan0ra0而不是 wlp9s0。运行 ip link 可以识别正确的设备名称。

对于大多数用户,只需要两个设置来连接,即ESSID(也称无线网络名称)和可选的WEP密钥。

  • 首先,确保接口处于活动状态:
root #ip link set dev wlp9s0 up
  • 连接到名为“GentooNode”的开放网络:
root #iw dev wlp9s0 connect -w GentooNode
  • 设置一个WEP密钥:使用d:前缀:
root #iw dev wlp9s0 connect -w GentooNode key 0:d:1234123412341234abcd
  • 使用ASCII WEP密钥连接:
root #iw dev wlp9s0 connect -w GentooNode key 0:some-password
附注
如果无线网络配置为WPA或WPA2,则需要使用wpa_supplicant。关于为Gentoo Linux配置无线网络的更多信息,请阅读Gentoo手册中的无线网络章节

使用iw dev wlp9s0 link确认无线设置。如果无线已经工作,继续按下一章节(了解网络属于)配置IP级别的网络选项或者使用前面描述的net-setup工具。

使用 net-setup

In cases where automatic network configuration is unsuccessful, the Gentoo boot media provides scripts to aid in network configuration. net-setup can be used to configure wireless network information and static IPs.

root #net-setup enp1s0

net-setup将会询问关于网络环境的一些问题。当所有这些完成后,网络连接就应该工作。以前面的方式测试网络连接。如果测试通过,恭喜!跳过本章节剩余部分并继续准备磁盘

重要
Network status should be tested after any configuration steps are taken. In the event that configuration scripts do not work, manual network configuration is required.

互联网和 IP 基础

If all of the above fails, the network must be configured manually. This is not particularly difficult, but should be done with consideration. This section serves to clarify terminology and introduce users to basic networking concepts pertaining to manually configuring an Internet connection.

提示
Some CPE (Carrier Provided Equipment) combines the functions of a router, access point, modem, DHCP server, and DNS server into one unit. It's important to differentiate the functions of a device from the physical appliance.

接口和地址

Network interfaces are logical representations of network devices. An interface needs an address to communicate with other devices on the network. While only a single address is required, multiple addresses can be assigned to a single interface. This is especially useful for dual stack (IPv4 + IPv6) configurations.

For consistency, this primer will assume the interface enp1s0 will be using the address 192.168.0.2.

重要
IP addresses can be set arbitrarily. As a result, it's possible for multiple devices to use the same IP address, resulting in an address conflict. Address conflicts should be avoided by using DHCP or SLAAC.
提示
IPv6 typically uses StateLess Address AutoConfiguration (SLAAC) for address configuration. In most cases, manually setting IPv6 addresses is a bad practice. If a specific address suffix is preferred, interface identification tokens can be used.

网络和 CIDR

Once an address is chosen, how does a device know how to talk to other devices?

IP addresses are associated with networks. IP networks are contiguous logical ranges of addresses.

Classless Inter-Domain Routing or CIDR notation is used to distinguish network sizes.

  • The CIDR value, often notated starting with a /, represents the size of the network.
    • The formula 2 ^ (32 - CIDR) can be used to calculate network size.
    • Once network size is calculated, usable node count must be reduced by 2.
      • The first IP in a network is the Network address, and the last is typically the Broadcast address. These addresses are special and cannot be used by normal hosts.
提示
The most common CIDR values are /24, and /32, representing 254 nodes and a single node respectively.

A CIDR of /24 is the de-facto default network size. This corresponds to a subnet mask of 255.255.255.0, where the last 8 bits are reserved for IP addresses for nodes on a network.

The notation: 192.168.0.2/24 can be interpreted as:

  • The address 192.168.0.2
  • On the network 192.168.0.0
  • With a size of 254 (2 ^ (32 - 24) - 2)
    • Usable IPs are in the range 192.168.0.1 - 192.168.0.254
  • With a broadcast address of 192.168.0.255
    • In most cases, the last address on a network is used as the broadcast address, but this can be changed.

Using this configuration, a device should be able to communicate with any host on the same network (192.168.0.0).

The Internet

Once a device is on a network, how does it know how to talk to devices on the Internet?

To communicate with devices outside of local networks, routing must be used. A router is simply a network device that forwards traffic for other devices. The term default route or gateway typically refers to whatever device on the current network is used for external network access.

提示
It's a standard practice to make the gateway the first or last IP on a network.

If an Internet-connected router is available at 192.168.0.1, it can be used as the default route, granting Internet access.

To summarize:

  • Interfaces must be configured with an address and network information, such as the CIDR value.
  • Local network access is used to access a router on the same network.
  • The default route is configured, so traffic destined for external networks is forwarded to the gateway, providing Internet access.

域名系统

Remembering IPs is hard. The Domain Name System was created to allow mapping between Domain Names and IP addresses.

Linux systems use /etc/resolv.conf to define nameservers to be used for DNS resolution.

提示
Many routers can also function as a DNS server, and using a local DNS server can augment privacy and speed up queries through caching.

Many ISPs run a DNS server that is generally advertised to the gateway over DHCP. Using a local DNS server tends to improve query latency, but most public DNS servers will return the same results, so server usage is largely based on preference.

手动配置网络

配置接口地址

重要
When manually configuring IP addresses, the local network topology must be considered. IP addresses can be set arbitrarily; conflicts may cause network disruption.

To configure enp1s0 with the address 192.168.0.2 and CIDR /24:

root #ip address add 192.168.0.2/24 dev enp1s0
提示
The start of this command can be shortened to ip a.

配置默认路由

Configuring address and network information for an interface will configure link routes, allowing communication with that network segment:

root #ip route
192.168.0.0/24 dev enp1s0 proto kernel scope link src 192.168.0.2
提示
This command can be shortened to ip r.

The default route can be set to 192.168.0.1 with:

root #ip route add default via 192.168.0.1

配置 DNS

Nameserver info is typically acquired using DHCP, but can be set manually by adding nameserver entries to /etc/resolv.conf.

警告
If dhcpcd is running, changes to /etc/resolv.conf will not persist. Status can be checked with ps x | grep dhcpcd.

nano is included in Gentoo boot media and can be used to edit /etc/resolv.conf with:

root #nano /etc/resolv.conf

Lines containing the keyword nameserver followed by a DNS server IP address are queried in order of definition:

文件 /etc/resolv.confUse Quad9 DNS.
nameserver 9.9.9.9
nameserver 149.112.112.112
文件 /etc/resolv.confUse Cloudflare DNS.
nameserver 1.1.1.1
nameserver 1.0.0.1

DNS status can be checked by pinging a domain name:

root #ping -c 3 gentoo.org

Once connectivity has been verified, continue with Preparing the disks.





块设备简介

块设备

让我们来好好看看Gentoo Linux以及普通Linux中有关磁盘方面的知识,包括块设备、分区和Linux文件系统。一旦磁盘的来龙去脉都了解了,我们将设置分区和文件系统以进行安装。

首先,让我们来看看块设备。SCSI和SATA磁盘以/dev/sda,/dev/sdb,/dev/sdc等形式被标注。在更先进的设备中,基于PCI Express的NVMe固态磁盘一般以/dev/nvme0n1,/dev/nvme0n2等形式被标注。

下表将帮助读者确定在系统中哪里可以找到块设备的类型:

设备类型 默认设备句柄 社论笔记和注意事项
IDE,SATA,SAS,SCSI 或 USB 闪存 /dev/sda 从大约 2007 年到现在,这可能是 Linux 中最常用的设备句柄。这类设备可以连接在 SATA 总线SCSIUSB 总线上作为块储存。例如,在第一个 SATA 设备的第一个分区称为 /dev/sda1
NVM Express (NVMe) /dev/nvme0n1 NVMe设备是最新的固态技术,它连接在 PCI Express 总线,并且拥有市面上最快的传输速度。2014 年前后的系统可能会支持 NVMe 硬件。在第一个 NVMe 设备的第一个分区称为 /dev/nvme0n1p1
MMC,eMMC 和 SD /dev/mmcblk0 嵌入式 MMC 设备,SD 卡和其它类型的记忆卡 可以作为数据存储使用。也就是说,许多系统可能不允许从这些类型的设备启动。建议使用这些设备用来安装 Linux,而是考虑用它们来传输文件,这也是它们主要的设计意图。另外,这种储存类型很适合用来做短期的文件备份和快照。

上面的块设备代表磁盘的抽象接口。用户程序可以使用这些块设备来与你的磁盘进行交互,而无需担心驱动器到底是 SATA,SCSI 还是其他什么东西。该程序可以把磁盘当作一系列连续的,可随机访问的 4096 字节块(4K)的存储。

Handbook:PPC/Blocks/Disks/zh-cn

创建文件系统

警告
如果使用 SSD 或者 NVMe 驱动,请检查是否需要升级固件。特别是有些英特尔的 SSD(600p 和 6000p)需要升级固件来修复关键错误,以避免XFS I/O 使用模式导致的数据损坏。(尽管这并非文件系统的问题)。smartctl 可以检查型号和固件版本。

介绍

现在分区已经创建,该在上面设置文件系统了。下一章节中描述了 Linux 所支持的众多文件系统。知道使用哪一个文件系统的读者可以继续阅读为分区应用文件系统。剩下的人应该学习可用的文件系统……

文件系统

Linux 支持数十种文件系统,尽管其中许多只是为了特定目的而部署。在 ppc 架构上只能找到某些稳定的文件系统 - 建议在为重要分区选择更具实验性的文件系统之前查阅文件系统及其支持状态。XFS 是推荐的全平台通用的文件系统。下面是一个不完全的文件系统列表:

btrfs
下一代文件系统,提供许多高级功能,例如快照、通过校验和进行自我修复、透明压缩、子卷和集成 RAID。不能保证 5.4.y 之前的内核在生产中与 btrfs 一起使用是安全的,因为对严重问题的修复仅存在于 LTS 内核分支的最新版本中。文件系统损坏问题在较旧的内核分支上很常见,比如说启用压缩后,较旧的内核(比 5.4.y 小)更可能发生损坏。 RAID 5/6 和配额组在所有版本的 btrfs 上都不安全。
ext4
Ext4 是一个可靠的、通用的全平台文件系统,但是它缺乏诸如引用链接之类的现代化功能。
f2fs
Flash-Friendly File System 最初是由三星为与 NAND 闪存一起使用而创建的。截至 2016 年第二季度,这个文件系统仍然被认为是不成熟的,但在将 Gentoo 安装到 microSD 卡、USB 驱动器或其他基于闪存的存储设备上时,它是一个不错的选择。
XFS
具有元数据日志的文件系统,具有强大的功能集并针对可扩展性进行了优化。 XFS 不断升级来支持现代化功能。 XFS 唯一的缺点是还不能缩减分区,不过这个问题正在解决中。XFS 特别支持反向链接和写入时复制(CoW),因为用户需要完成大量编译工作,所以对 Gentoo 系统很有用。推荐使用 XFS 这个现代化的通用全平台文件系统。XFS 要求分区至少300MB。
VFAT
也称为 FAT32,Linux 支持但不支持标准的 UNIX 权限设置。它主要用于与其他操作系统(Microsoft Windows 或 Apple 的 macOS)的互操作和交换,但也是某些系统引导加载程序固件(如 UEFI)的必需品。UEFI 系统的用户需要使用 VFAT 格式化的 EFI 系统分区才能启动。
NTFS
这个“新技术”文件系统是自 Windows NT 3.1 以来 Microsoft Windows 的旗舰文件系统。与 vfat 类似,它不存储 BSD 或 Linux 正常运行所需的 UNIX 权限设置或扩展属性,大多数情况下,不应将其用作为根文件系统。它应该用于与Microsoft Windows 系统的互操作和数据交换(注意强调)。

更多有关于文件系统的信息可以在社区维护的 文件系统文章 中找到。

为分区应用文件系统

附注
安装结束后,请确保在重新启动之前,为之后在手册中选择的文件系统 emerge 相应软件包。

在一个分区或卷上创建一个文件系统,这里有用于每一个可能的分区的工具。 单击下表中的文件系统名称,了解每个文件系统的更多信息:

文件系统 创建命令 是否在最小化 CD 中已包含? 软件包
btrfs mkfs.btrfs sys-fs/btrfs-progs
ext4 mkfs.ext4 sys-fs/e2fsprogs
f2fs mkfs.f2fs sys-fs/f2fs-tools
xfs mkfs.xfs sys-fs/xfsprogs
vfat mkfs.vfat sys-fs/dosfstools
NTFS mkfs.ntfs sys-fs/ntfs3g
重要
The handbook recommends new partitions as part of the installation process, but it is important to note running any mkfs command will erase any data contained within the partition. When necessary, ensure any data that exists within is appropriately backed up before creating a few filesystem.

比如,在示例分区结构中,有使用 FAT32 的引导分区(/dev/sda1)和使用 xfs 的根分区(/dev/sda3),会使用下面的命令:

root #mkfs.xfs /dev/sda3

EFI system partition filesystem

The EFI system partition (/dev/sda1) must be formatted as FAT32:

root #mkfs.vfat -F 32 /dev/sda1

Legacy BIOS boot partition filesystem

Systems booting via legacy BIOS with a MBR/DOS disklabel can use any filesystem format supported by the bootloader.

For example, to format with XFS:

root #mkfs.xfs /dev/sda1

Small ext4 partitions

如果在较小的分区(少于8 GiB)上使用 ext4,则创建文件系统时必须带适当的选项以保留足够的 inode。可以使用以下命令创建文件系统:

root #mkfs.ext4 -T small /dev/<device>

这一般将是对于给定的文件系统inode数量的四倍,它的“字节每inode”从16kB每个减少到4kB每个。

激活 swap 分区

mkswap是用来初始化swap分区的命令:

root #mkswap /dev/sda2

要激活swap分区,使用swapon

root #swapon /dev/sda2

This 'activation' step is only necessary because the swap partition is newly created within the live environment. Once the system has been rebooted, as long as the swap partition is properly defined within fstab or other mount mechanism, swap space will activate automatically.

挂载 root 分区

附注
Installations which were previously started, but did not finish the installation process can resume the installation from this point in the handbook. Use this link as the permalink: Resumed installations start here.
提示
非 Gentoo 安装介质的用户需要通过运行以下命令来创建挂载点:
root #mkdir --parents /mnt/gentoo
root #mkdir --parents

For EFI installs only, the ESP should be mounted under the root partition location:

root #mkdir --parents

Continue creating additional mount points necessary for any additional (custom) partition(s) created during previous steps by using the mkdir command.

现在分区都已初始化并有文件系统,接下来该挂载那些分区了。使用 mount 命令,但是不要忘记为每一个创建的分区创建需要的挂载目录。比如示例中我们挂载根分区:

Mount the root partition:

root #mount /dev/sda3 /mnt/gentoo

Continue mounting additional (custom) partitions as necessary using the mount command.

附注
如果/tmp/需要放在一个独立分区,确保在挂载后变更它的权限:
root #chmod 1777 /mnt/gentoo/tmp
这同样适用于/var/tmp

后面的介绍中将挂载proc文件系统(一个内核的虚拟接口)和其它内核伪文件系统。不过我们首先安装 Gentoo 安装文件



手册:片段/安装/安装stage3



Chrooting

复制DNS信息

在进行新环境之前,还有一件要做的事情就是复制/etc/resolv.conf中的DNS信息。需要完成这个来确保即使进入到新环境后网络仍然可以使用。/etc/resolv.conf包含着当前网络中的DNS服务器。

要复制这个信息,建议通过cp命令的 --dereference 选项。这可以保障如果/etc/resolv.conf是一个符号链接的话,复制的是那个目标文件而不是这个符号文件自己。否则在新环境中,符号文件将指向一个不存在的文件(因为链接目标非常可能不会在新环境中)。

root #cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

挂载必要的文件系统

稍等片刻,Linux 的根目录将变更到新的位置。

需要提供的文件系统是:

  • /proc/ 是一个伪文件系统,虽然它看起来像是常规文件,但是却是由 Linux 内核生成
  • /sys/ 是一个伪文件系统,它类似被取代的 /proc/,但是比 /proc/ 更结构化
  • /dev/ 是一个包含全部设备文件的常规文件系统,一部分由Linux设备管理器(通常是udev)管理
  • /run/ 是一个临时文件系统,用于运行时生成的文件,例如 PID 文件和锁

/proc/位置将要挂载到/mnt/gentoo/proc/,而其它的都是绑定挂载。字面上的意思是,例如/mnt/gentoo/sys/事实上就是/sys/(它只是同一个文件系统的第二个条目点),而/mnt/gentoo/proc/是(可以说是)文件系统的一个新的挂载。

提示
If using Gentoo's install media, this step can be replaced with simply: arch-chroot /mnt/gentoo.
root #mount --types proc /proc /mnt/gentoo/proc
root #mount --rbind /sys /mnt/gentoo/sys
root #mount --make-rslave /mnt/gentoo/sys
root #mount --rbind /dev /mnt/gentoo/dev
root #mount --make-rslave /mnt/gentoo/dev
root #mount --bind /run /mnt/gentoo/run
root #mount --make-slave /mnt/gentoo/run
附注
--make-rslave操作是稍后安装systemd支持时所需要的。
警告
当使用非Gentoo安装媒介时,这时可能还不算完。一些发行版将/dev/shm符号链接到/run/shm/,在chroot后将变得不可用。为了让/dev/shm/是一个正常挂载的tmpfs,可以这样修复:
root #test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
root #mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm

同时确保设置了权限为1777:

root #chmod 1777 /dev/shm /run/shm

进入新环境

现在所有的分区已经初始化,并且基础环境已经安装,是时候进入到新的安装环境了。这意思着会话将把根目录(能访问到最顶层的位置)从当前的安装环境(安装CD或其他安装媒介)变为安装系统(叫做初始化分区)。因此叫作 change rootchroot

完成chroot有三个步骤:

  1. 如果可以的话,使用 chroot 或 arch-chroot 将根目录的位置从 /(在安装媒介里)更改成 /mnt/gentoo/ (在分区里)
  2. 使用 source 命令将一些设置(那些在 /etc/profile 中的)重新载入到内存中
  3. 更改主提示符来帮助我们记住当前会话在一个 chroot 环境里面。
root #chroot /mnt/gentoo /bin/bash
root #source /etc/profile
root #export PS1="(chroot) ${PS1}"

从现在开始,所有的动作将立即在新 Gentoo Linux 环境里生效。

提示
如果安装Gentoo时在这一步之后的任何地方中断,那么“应该”可以从这一步“继续”安装。不必再重新给磁盘分区!只需要挂载 root 分区 并运行上述步骤,然后通过复制 DNS 信息重新进入工作环境。 这也对修复引导程序问题很有用。更多的信息可以在 chroot 文章中找到。

Preparing for a bootloader

Now that the new environment has been entered, it is necessary to prepare the new environment for the bootloader. It will be important to have the correct partition mounted when it is time to install the bootloader.

UEFI 系统

For UEFI systems, /dev/sda1 was formatted with the FAT32 filesystem and will be used as the EFI System Partition (ESP). Create a new directory (if not yet created), and then mount ESP there:

root #mkdir
root #mount /dev/sda1

DOS/Legacy BIOS systems

For DOS/Legacy BIOS systems, the bootloader will be installed into the directory, therefore mount as follows:

root #mount /dev/sda1

配置 Portage

Gentoo ebuild 软件仓库

选择镜像的第二个重要步骤是通过/etc/portage/repos.conf/gentoo.conf文件来配置 Gentoo的 ebuild 软件仓库。这个文件包含了更新 Portage 数据库(包含 Portage 需要下载和安装软件包所需要的信息的一个 ebuild 和相关文件的集合)所需要的同步信息。

通过几个简单的步骤就可以完成软件仓库的配置。首先,如果它不存在,则创建 repos.conf 目录:

root #mkdir --parents /mnt/gentoo/etc/portage/repos.conf

接下来,复制 Portage 提供的 Gentoo 仓库配置文件到这个(新创建的)目录:

root #cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf

使用一个文件编辑器或通过使用cat命令来看一眼。文件里的内容应该是.ini格式并且看起来像是这样:

文件 /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
[DEFAULT]
main-repo = gentoo
 
[gentoo]
location = /var/db/repos/gentoo
sync-type = rsync
sync-uri = rsync://rsync.gentoo.org/gentoo-portage
auto-sync = yes
sync-rsync-verify-jobs = 1
sync-rsync-verify-metamanifest = yes
sync-rsync-verify-max-age = 24
sync-openpgp-key-path = /usr/share/openpgp-keys/gentoo-release.asc
sync-openpgp-key-refresh-retry-count = 40
sync-openpgp-key-refresh-retry-overall-timeout = 1200
sync-openpgp-key-refresh-retry-delay-exp-base = 2
sync-openpgp-key-refresh-retry-delay-max = 60
sync-openpgp-key-refresh-retry-delay-mult = 4
sync-webrsync-verify-signature = yes
sync-git-verify-commit-signature = yes

上面列出的 sync-uri 变量默认值将根据轮询的确定一个镜像地址。这会缓解 Gentoo 基础设施上带宽的压力,并能在特定镜像离线时保证失效安全。除非使用本地或者私有的镜像,否则建议保留默认 URI。

提示
可以在 Portage 同步主题中找到关于 Portage 的同步API插件的官方规范。

从网站安装 Gentoo ebuild 数据库快照

接下来,是安装 Gentoo ebuild 数据库。这个快照包含一组文件,包括通知 Portage 中有关可用软件的标题(用于安装),系统管理员可以选择哪些配置文件,软件包或 profile 特定新闻 (news) 项目等。

建议那些使用限制性防火墙的用户使用 emerge-webrsync 命令(它使用 HTTP / FTP 协议下载快照)节省网络带宽。 没有网络或带宽限制的读者可以愉快地跳到下一节。

这将从Gentoo的一个镜像中获取最新的快照(每天发布)并将其安装到系统上:

root #emerge-webrsync
附注
在这个操作中,emerge-webrsync可能会报找不到 /var/db/repos/gentoo/ 位置。这是预期内的并且不用担心——这个工具将会创建这个位置。

从现在开始,Portage 可能会提示建议运行某些更新。这是因为在安装了一个新的repository 快照后,Portage 发现了 stage 文件中已经安装的某些软件包有更新的版本。现在可以安全的忽略包的更新;可以延迟到 Gentoo 安装完成之后更新。


可选:选择镜像站点

为了能更快的下载源代码,这里推荐选择一个快的镜像。Portage 将会在make.conf文件中查找GENTOO_MIRRORS变量,并使用其中所列的镜像。可以通过浏览 Gentoo 镜像列表搜索一个(或一组)最接近系统物理位置(往往那是最快的)的镜像。另外,我们提供一个叫作mirrorselect的好工具,它为用户选择所需镜像提供了一个很好的交换。只需要移动光标选择镜像并按Spacebar选择一个或多个镜像。

A tool called mirrorselect provides a pretty text interface to more quickly query and select suitable mirrors. Just navigate to the mirrors of choice and press Spacebar to select one or more mirrors.

root #mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

Alternatively, a list of active mirrors are available online.

可选:更新Portage ebuild 数据库

Gentoo 数据库可以更新到最新版本。前面的emerge-webrsync命令将安装一个最近的快照(通常是24小时以内),所以这一步是可选的。

假设需要最新更新的软件包(1小时以内),可以使用emerge --sync。这个命令将使用rsync协议来更新 Gentoo ebuild 数据库(之前通过emerge-webrsync获得的)到最新状态。

root #emerge --sync

在慢速的终端上,比如一些framebuffer或者串口控制台,建议使用--quiet选项来加速这个进程:

root #emerge --sync --quiet

阅读新闻条目

当同步Portage ebuild 数据库时,Portage 可能会输出类似于下面的信息:

* IMPORTANT: 2 news items need reading for repository 'gentoo'.
* Use eselect news to read news items.

创建新闻条目是为了提供一个通信媒介,通过 Gentoo ebuild 数据库来给用户推送重要的消息。可以使用 eselect news 管理新闻条目。eselect 应用程序是一个Gentoo 特有的应用程序,它允许使用通用管理接口来管理系统。在这里,要用到 eselectnews 模块。

对于news模块,最常用的有三个操作:

  • 使用list显示一个可用新闻条目的预览。
  • 使用read来阅读新闻条目。
  • 使用purge将在新闻条目阅读后删除,并且不能再次阅读。
root #eselect news list
root #eselect news read

可以通过新闻阅读器手册页查看更多关于新闻阅读器的信息:

root #man news.eselect

选择正确的配置文件

提示
桌面配置文件并非只是 桌面环境。也可能是小的窗口管理器,例如 i3 或 sway。

配置文件是任何一个Gentoo系统的积木。它不仅指定USECFLAGS和其它重要变量的默认值,还会锁定系统的包版本范围。这些设定全是由Gentoo的Portage开发者们来维护。

运行 eselect 使用 profile模块,能看到当前系统正在使用什么配置文件:

root #eselect profile list
Available profile symlink targets:
  [1]   default/linux/ppc/ *
  [2]   default/linux/ppc//desktop
  [3]   default/linux/ppc//desktop/gnome
  [4]   default/linux/ppc//desktop/kde
附注
命令的这个输出只是一个示例,并会随时间演变。
附注
若要使用 systemd, 请选择名称中包含 "systemd" 的配置文件。否则,选择相反的配置文件。

一些架构还会有桌面的子配置文件。

警告
升级 profile 不能掉以轻心。 选择初始 profile 时,使用与最初使用的 stage3 “相同的版本”(例如 )。 每个新的 profile 版本都通过新闻项目公布,新闻项目中包含了迁移说明。 在切换到较新的 profile 之前,请按照说明操作。

在看完框架的可用配置文件ppc之后,用户可以键入以下命令为系统选择一个不同的配置文件:

root #eselect profile set 2



附注
developer 子配置文件是专用于Gentoo Linux开发,也就是说不适用于普通用户。

Optional: Adding a binary package host

Since December 2023, Gentoo's Release Engineering team has offered an official binary package host (colloquially shorted to just "binhost") for use by the general community to retrieve and install binary packages (binpkgs).[1]

Adding a binary package host allows Portage to install cryptographically signed, compiled packages. In many cases, adding a binary package host will greatly decrease the mean time to package installation and adds much benefit when running Gentoo on older, slower, or low power systems.

Repository configuration

The repository configuration for a binhost is found in Portage's /etc/portage/binrepos.conf/ directory, which functions similarly to the configuration mentioned in the Gentoo ebuild repository section.

When defining a binary host, there are two important aspects to consider:

  1. The architecture and profile targets within the sync-uri value do matter and should align to the respective computer architecture (ppc in this case) and system profile selected in the Choosing the right profile section.
  2. Selecting a fast, geographically close mirror will generally shorten retrieval time. Review the mirrorselect tool mentioned in the Optional: Selecting mirrors section or review the online list of mirrors where URL values can be discovered.

文件 /etc/portage/binrepos.conf/gentoo.confCDN-based binary package host example
[binhost]
priority = 9999
sync-uri = https://distfiles.gentoo.org/releases/<arch>/binpackages/<profile>/x86-64/

Installing binary packages

Portage will compile packages from code source by default. It can be instructed to use binary packages in the following ways:

  1. The --getbinpkg option can be passed when invoking the emerge command. This method of for binary package installation is useful to install only a particular binary package.
  2. Changing the system's default via Portage's FEATURES variable, which is exposed through the /etc/portage/make.conf file. Applying this configuration change will cause Portage to query the binary package host for the package(s) to be requested and fall back to compiling locally when no results are found.

For example, to have Portage always install available binary packages:

文件 /etc/portage/make.confConfigure Portage to use binary packages by default
# Appending getbinpkg to the list of values within the FEATURES variable
FEATURES="${FEATURES} getbinpkg"
# Require signatures
FEATURES="${FEATURES} binpkg-request-signature"

Additional Portage features will be discussed in the the next chapter of the handbook.

配置 USE 变量

USE是Gentoo为用户提供的最具威力的变量之一。很多程序通过它可以选择编译或者不编译某些可选的支持。例如,一些程序可以在编译时加入对 GTK+或是对Qt的支持。其它的程序可以在编译时加入或不加入对于SLL的支持。有些程序甚至可以在编译时加入对framebuffer的支持(svgalib)以取代X11(X服务器)。

大多数的发行版会使用尽可能多的支持特性编译它们的软件包,这既增加了软件的大小也减慢了启动时间,而这些还没有算上可能会涉及到的大量依赖性问题。Gentoo可以让你自己定义软件编译的选项,而这正是USE要做的事。

USE变量里你可以定义关键字,它被用来对应相应的编译选项。例如,ssl将会把SSL支持编译到程序中以支持它。-X会移除其对于X服务器的支持(注意前面的减号)。gnome gtk -kde -qt5 将会以支持GNOME(和GTK+)但不支持KDE(和Qt)的方式编译软件,使系统为GNOME做完全调整(如果架构支持)。

默认的USE设置全放在了系统所使用的Gentoo配置文件的make.defaults文件中。Gentoo对它的配置文件们使用了一个(复杂的)继承系统,在这个阶段我们不去深入。最简单的检查当前活动的USE标记的办法是运行emerge --info并选择以USE开头的那一行:

root #emerge --info | grep ^USE
USE="X acl alsa amd64 berkdb bindist bzip2 cli cracklib crypt cxx dri ..."
附注
上面的示例被截断了,实际上的USE列表值是非常非常多的。

可以在系统的 /var/db/repos/gentoo/profiles/use.desc 中找到可用的USE标记的完整描述。

root #less /var/db/repos/gentoo/profiles/use.desc

less命令中,可以通过使用键来滚动,并且可以按q退出。

作为示例,我们展示一个支持DVD、ALSA,以及CD录制的基于KDE系统的USE设置:

root #nano /etc/portage/make.conf
文件 /etc/portage/make.conf为基于 KDE/Plasma 系统启用 DVD、ALSA 和 CD录制支持 flag
USE="-gtk -gnome qt5 kde dvd alsa cdr"

当在 /etc/portage/make.conf中定义一个 USE 值,会添加到系统 USE 标志中。USE 标志可以通过在列表内的值前面中添加 - 减号来全局移除。例如,禁用 X 图形化环境的支持,可以设置 -X

文件 /etc/portage/make.conf忽略默认USE标记
USE="-X acl alsa"
警告
尽管可以设置 -*(这将禁用除 make.conf 中指定的值之外的所有 USE 值),但这样做不推荐,也不理智。Ebuild 开发人员在 ebuild 中选择某些默认的 USE 标志值以防止冲突,增强安全性,避免错误,以及其他原因。禁用 所有 USE 标志将否定默认行为,并可能导致重大问题。

CPU_FLAGS_*

一些架构(包括 AMD64/X86、ARM、PPC)有称为 CPU_FLAGS_<ARCH>USE_EXPAND 变量,请将 <ARCH> 替换为相应的系统架构名称。

重要
不要糊涂! AMD64X86 系统有一些共同的架构,所以 AMD64 正确的变量名称是 CPU_FLAGS_X86

该变量用于构建编译特定的汇编代码或其他内置函数——通常是手写或其它的, 并且与要求编译器输出针对某个 CPU 功能的优化代码同。(例如 -march=

如果需要,用户除了配置他们的 COMMON_FLAGS ,还应该设置此变量。

需要几个步骤来设置它:

root #emerge --ask app-portage/cpuid2cpuflags

如果有疑问,请手动检查输出:

root #cpuid2cpuflags

然后复制输出到 package.use

root #echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags

VIDEO_CARDS

VIDEO_CARDS USE_EXPAND 变量应根据使用的 GPU 进行适当配置。仅控制台安装则不需​​要设置 VIDEO_CARDS。

Below is an example of a properly set VIDEO_CARDS variable. Substitute the name of the driver(s) to be used.

文件 /etc/portage/make.conf
VIDEO_CARDS="amdgpu radeonsi"

Details for various GPU(s) can be found at the AMDGPU, Intel, Nouveau (Open Source), or NVIDIA (Proprietary) articles.

可选:配置 ACCEPT_LICENSE 变量

Starting with Gentoo Linux Enhancement Proposal 23 (GLEP 23), a mechanism was created to allow system administrators the ability to "regulate the software they install with regards to licenses... Some want a system free of any software that is not OSI-approved; others are simply curious as to what licenses they are implicitly accepting."[2] With a motivation to have more granular control over the type of software running on a Gentoo system, the ACCEPT_LICENSE variable was born.

Portage 在 ACCEPT_LICENSE 中查找允许安装的软件包。打印当前系统范围的值运行:

user $portageq envvar ACCEPT_LICENSE
@FREE

在 Gentoo 仓库中定义的许可证组,由 Gentoo Licenses project 项目管理,有:

组别名称 描述
@GPL-COMPATIBLE 由自由软件基金会批准的 GPL 兼容许可 GPL [a_license 1]
@FSF-APPROVED 由 FSF 批准的自由软件许可证(包括@GPL-COMPATIBLE )
@OSI-APPROVED 由开放源代码促进会批准的许可证 [a_license 2]
@MISC-FREE Misc 许可证可能是自由软件,即遵循自由软件定义 [a_license 3] ,但不被 FSF 或 OSI 批准
@FREE-SOFTWARE 结合 @FSF-APPROVED,@OSI-APPROVED 和 @MISC-FREE
@FSF-APPROVED-OTHER 经 FSF 批准的“免费文档”和“除软件和文档外的实际使用作品”(包括字体)许可证
@MISC-FREE-DOCS 遵循自由定义的免费文档和其他作品(包括字体) [a_license 4]且没有在 @FSF-APPROVED-OTHE 中列出的杂项许可
@FREE-DOCUMENTS 结合 @FSF-APPROVED-OTHER 和 @MISC-FREE-DOCS
@FREE 所有许可证的 metaset,可以自由使用,共享,修改和共享修改。结合 @FREE-SOFTWARE 和 @FREE-DOCUMENTS
@BINARY-REDISTRIBUTABLE 至少允许以二进制形式自由分发软件的许可证。包括 @FREE
@EULA 试图剥夺您的权利的许可协议。与“保留所有权利”和需要明确的批准相比,@EULA 有更多的限制

Some common license groups include:

A list of software licenses grouped according to their kinds.
Name Description
@GPL-COMPATIBLE GPL compatible licenses approved by the Free Software Foundation [a_license 5]
@FSF-APPROVED Free software licenses approved by the FSF (includes @GPL-COMPATIBLE)
@OSI-APPROVED Licenses approved by the Open Source Initiative [a_license 6]
@MISC-FREE Misc licenses that are probably free software, i.e. follow the Free Software Definition [a_license 7] but are not approved by either FSF or OSI
@FREE-SOFTWARE Combines @FSF-APPROVED, @OSI-APPROVED, and @MISC-FREE.
@FSF-APPROVED-OTHER FSF-approved licenses for "free documentation" and "works of practical use besides software and documentation" (including fonts)
@MISC-FREE-DOCS Misc licenses for free documents and other works (including fonts) that follow the free definition [a_license 8] but are NOT listed in @FSF-APPROVED-OTHER.
@FREE-DOCUMENTS Combines @FSF-APPROVED-OTHER and @MISC-FREE-DOCS.
@FREE Metaset of all licenses with the freedom to use, share, modify and share modifications. Combines @FREE-SOFTWARE and @FREE-DOCUMENTS.
@BINARY-REDISTRIBUTABLE Licenses that at least permit free redistribution of the software in binary form. Includes @FREE.
@EULA License agreements that try to take away your rights. These are more restrictive than "all-rights-reserved" or require explicit approval

Currently set system wide acceptable license values can be viewed via:

user $portageq envvar ACCEPT_LICENSE
@FREE

As visible in the output, the default value is to only allow software which has been grouped into the @FREE category to be installed.

Specific licenses or licenses groups for a system can be defined in the following locations:

  • 整个系统的在已选择的 profile。
  • 整个系统的在 /etc/portage/make.conf
  • 每个软件包的在 /etc/portage/package.license 文件。
  • 每个软件包的在/etc/portage/package.license/ 目录 或文件。

可选择通过在配置文件中更改 /etc/portage/make.conf 覆盖系统范围默认接受项。

文件 /etc/portage/make.conf如何在系统范围接受 ACCEPT_LICENSE 许可证示例
ACCEPT_LICENSE="-* @FREE @BINARY-REDISTRIBUTABLE"

也可以选择为每个软件包定义接受的许可证,如下面的文件目录所示。需要注意的是,如果 package.license 目录不存在的话,需要创建该目录。

root #mkdir /etc/portage/package.license

Software license details for an individual Gentoo package are stored within the LICENSE variable of the associated ebuild. One package may have one or many software licenses, therefore it be necessary to specify multiple acceptable licenses for a single package.

文件 /etc/portage/package.license/kernel如何接受每个软件包的许可证示例
app-arch/unrar unRAR
sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE
sys-firmware/intel-microcode intel-ucode
重要
ebuild 中 的 LICENSE 变量仅是为 Gentoo 开发人员和用户准备的一份指南。它既不是法律声明,也不保证其真实性。因此不要过度依赖它,您需要深入检查软件包的本身,以及已经安装到系统的所有文件。

更新@world集合

当系统应用了任何升级,或从 任何profile 构建了stage3 后,应用了变化的 use 标记时,下一步是必要的。

  1. A profile target different from the stage file has been selected.
  2. Additional USE flags have been set for installed packages.

Readers who are performing an 'install Gentoo speed run' may safely skip @world set updates until after their system has rebooted into the new Gentoo environment.

Readers who are performing a slow run can have Portage perform updates for package, profile, and/or USE flag changes at the present time:

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

Removing obsolete packages

It is important to always depclean after system upgrades to remove obsolete packages. Review the output carefully with emerge --depclean --pretend to see if any of the to-be-cleaned packages should be kept if personally using them. To keep a package which would otherwise be depcleaned, use emerge --noreplace foo.

root #emerge --ask --pretend --depclean

If happy, then proceed with a real depclean:

root #emerge --ask --depclean
提示
如果选择了桌面环境配置文件,则此过程可能大大增加安装过程所需的时间量。时间紧迫的人可以通过这个“经验法则”工作:配置文件名称越短,系统 @world 集 越不具体; @world 集越不具体,系统将需要的软件包越少。换一种说法:
  • 选择 default/linux/amd64/ 将只有很少的包被重装或更新
  • 选择 default/linux/amd64//desktop/gnome/systemd 将需要安装许多软件包,因为 init 系统要从 OpenRC 更改为 systemd,并且将安装 GNOME 桌面环境框架。


时区

附注
这一步不适用于 musl libc 用户。不知道 musl libc 是什么的用户应该执行此步骤。

请避免使用 /usr/share/zoneinfo/Etc/GMT* 时区,它们的名字并不意味着想要的时区。例如,GMT-8 实际上是 GMT+8

为系统选择时区。在/usr/share/zoneinfo/中查找可用的时区,然后写进/etc/timezone文件。

root #ls /usr/share/zoneinfo
root #ls -l /usr/share/zoneinfo/Europe/
total 256
-rw-r--r-- 1 root root 2933 Dec  3 17:19 Amsterdam
-rw-r--r-- 1 root root 1742 Dec  3 17:19 Andorra
-rw-r--r-- 1 root root 1151 Dec  3 17:19 Astrakhan
-rw-r--r-- 1 root root 2262 Dec  3 17:19 Athens
-rw-r--r-- 1 root root 3664 Dec  3 17:19 Belfast
-rw-r--r-- 1 root root 1920 Dec  3 17:19 Belgrade
-rw-r--r-- 1 root root 2298 Dec  3 17:19 Berlin
-rw-r--r-- 1 root root 2301 Dec  3 17:19 Bratislava
-rw-r--r-- 1 root root 2933 Dec  3 17:19 Brussels
...

假设要选择的时区是 “Europe/Brussels”。

OpenRC

我们把时区名称写入 /etc/timezone 文件。

root #echo "Europe/Brussels" > /etc/timezone

接下来,重新配置 sys-libs/timezone-data 包,将会为我们基于 /etc/timezone 条目更新 /etc/localtime 文件。 /etc/localtime 文件用于让系统的 C 类库知道系统在什么时区。

root #emerge --config sys-libs/timezone-data
附注
The /etc/localtime file is used by the system C library to know the timezone the system is in.

systemd

当使用 systemd 时,采用一种稍有不同的方法。生成一个符号链接:

root #ln -sf ../usr/share/zoneinfo/Europe/Brussels /etc/localtime

之后当 systemd 运行时,时区和相关设置可以使用 timedatectl 命令配置。

配置区域设置

附注
这一步不适用于 musl libc 用户。不知道 musl libc 是什么的用户应该执行此步骤。

生成区域设置

大多数用户只想在他们的系统上使用一或两个地区。

Locale 不只是指定用户应该使用与系统进行交互的语言,同时也指定了字符串排序,日期和时间的显示等规则。Locale 是 "区分大小写" 的,必须完全按照描述的方式表示。完整的 locale 可用列表可以在 /usr/share/i18n/SUPPORTED 文件中找到。

系统支持的 locale 必须在 /etc/locale.gen 文件中定义。

root #nano /etc/locale.gen

下面的地区是一个示例,展示了同时使用英语(美国)和德语(德国)及附加字符格式(如 UTF-8)。

文件 /etc/locale.gen启用US和 DE 地区及附加字符格式
en_US ISO-8859-1
en_US.UTF-8 UTF-8
de_DE ISO-8859-1
de_DE.UTF-8 UTF-8
警告
许多应用程序需要至少有 UTF-8 区域设置才能正确构建。

下一步是运行 locale-gen 命令。此命令会生成 /etc/locale.gen 文件中所有指定的地区。

root #locale-gen

要验证当前所选择的 locale 可用,可以运行 locale -a

在 systemd 安装中,可以使用 localectl,例如 localectl set-locale ... 或者 localectl list-locales

选择区域设置

等完成后,我们就来设定系统级别的区域设置。我们再次使用 eselect 设定区域设置,现在使用 locale 模块。

通过 eselect locale list 可显示可用的目标:

root #eselect locale list
Available targets for the LANG variable:
  [1]  C
  [2]  C.utf8
  [3]  en_US
  [4]  en_US.iso88591
  [5]  en_US.utf8
  [6]  de_DE
  [7]  de_DE.iso88591
  [8]  de_DE.utf8
  [9] POSIX
  [ ]  (free form)

可以使用 eselect locale set <NUMBER> 选择正确的区域设置:

root #eselect locale set 9

还可以手动编辑 /etc/env.d/02locale 文件,在 systemd 是 /etc/locale.conf 文件,来选择区域设置:

文件 /etc/env.d/02locale手动设置系统区域设置 定义
LANG="de_DE.UTF-8"
LC_COLLATE="C.UTF-8"

设定区域设置可以避免在后面安装中,内核和软件汇编时的警告和错误。

现在重新加载环境:

root #env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

更多有关区域设置选择过程的指导,另请参阅本地化指南UTF-8 指南。





可选:安装固件和微代码

固件

Linux Firmware

在开始配置内核部分之前,最好了解下,一些硬件设备需要先在系统上安装附加的固件,有时是非自由及开放源代码软件(FOSS)才能正常运行。我们经常网络接口上会使用附加的固件,特别是无线网络接口,常用于台式电脑和笔记本电脑。此外,来自 AMD,Nvidia 和 Intel 等供应商的现代视频芯片,要想使用完整的功能,通常也需要外部固件文件。现代硬件设备的大多数固件都可以在 sys-kernel/linux-firmware 软件包中找到。

为了在必要时提供固件,首次重启系统之前推荐安装 sys-kernel/linux-firmware 软件包:

root #emerge --ask sys-kernel/linux-firmware
附注
安装某些固件软件包时,经常需要接受固件关联的许可证。有需要的话,访问手册的许可证处理章节有助于你接受许可证。

注意,当内核以模块(M)加载内核符号时,将从文件系统中加载其相关的固件文件。对于以模块加载的符号,没有必要把设备固件文件加入内核二进制镜像中。

SOF Firmware

重要
Use of this firmware requires enabling certain Kernel options and is only supported on AMD64 currently. Enabling these options are only necessary if a manual configuration is planned, as the Distribution Kernels have them enabled already. The necessary options are covered in architecture specific kernel configuration.

Sound Open Firmware (SOF) is a new open source audio driver meant to replace the proprietary Smart Sound Technology (SST) audio driver from Intel. 10th gen+ and Apollo Lake (Atom E3900, Celeron N3350, and Pentium N4200) Intel CPUs require this firmware for certain features and certain AMD APUs also have support for this firmware. SOF's supported platforms matrix can be found here for more information.

root #emerge --ask sys-firmware/sof-firmware

微码

除了独立显卡硬件和网络接口之外,CPU 可能也需要固件更新。通常这种固件被称为微码(microcode)。有时需要更新版本的微码来修补 CPU 硬件中的不稳定性、安全问题或其他复杂的错误。

AMD CPU 的微码更新在前面提到的 sys-kernel/linux-firmware 软件包内分发。Intel CPU 的微码可以在 sys-firmware/intel-microcode 包中找到,并且需要单独安装。更多有关如何更新微码的细节,请查看微码文章

内核配置和编译

现在是时候来配置和编译内核源代码了。将介绍三种用内核管理安装的方法,但是安装后,任何时候都可以采用新的方法。

由操作最少到操作最多排序:

全自动方法:Distribution 内核
Distribution 内核用来配置、自动构建安装 Linux 内核、相关模块和 initramfs 文件(可选,但是默认启用)。将来内核就像其他的系统软件包一样,通过使用包管理器全自动升级。如果需要定制内核,它可以提供自定义内核配置文件。这种过程操作最少,并且非常适合新 Gentoo 用户,因为它开箱即用,并且系统管理员最少参与。
混合方法:Genkernel
通过系统包管理器安装新内核源代码。系统管理员可以使用 Gentoo 的 genkernel 工具的配置,构建和安装 Linux 内核、相关模块和 initramfs 文件(可选,但默认 启用)。如果要自定义内核,它可以提供自定义内核配置文件。将来每次更新内核配置、编译和安装都需要系统管理员运行 eselect kernelgenkernel和其他可能的命令。
全手动方法
通过系统包管理器安装新的内核源代码。使用 eselect kernel 和一大堆 make 命令手动配置、构建和安装内核。将来内核升级需要重复手动配置、构建和安装内核文件的过程。这是操作做多的过程,但是在内核更新过程提供最大程度控制。

Linux内核是所有发行版的核心。它位于用户程序和系统硬件之间。尽管手册提供给用户一些可选的内核源码,但是在内核概述页面有更全面的列表,上面有着更多的细节描述。

安装内核源码

附注
本小节只有关于使用 genkernel(混合)或手动内核管理方法

当为基于 ppc 的系统安装和编译内核时,Gentoo 推荐使用 sys-kernel/gentoo-sources 软件包。

选择一个合适的内核并使用 emerge 来安装它。

root #emerge --ask sys-kernel/gentoo-sources

这将在 /usr/src/ 中安装路径中特定版本的 Linux 内核源码。如果没有在所选内核源码包内启用 USE=symlink,它将不会自行创建符号链接。

我们习惯性的维护 /usr/src/linux 符号链接。这样,它指向与当前运行的内核相对应的源代码。然而,默认情况下不会创建这个符号链接。有一个简单创建符号链接的方法是利用 eselect 的内核模块。

更多有关符号链接的信息以及如何管理符号链接,请参考升级内核

首先,列出所有已安装的内核:

root #eselect kernel list
Available kernel symlink targets:
  [1]   linux-3.16.5-gentoo

要创建一个名为 linux 的符号链接,使用:

root #eselect kernel set 1
root #ls -l /usr/src/linux
lrwxrwxrwx    1 root   root    12 Oct 13 11:04 /usr/src/linux -> linux-3.16.5-gentoo

备选:genkernel

附注
In case it was missed, this section requires the kernel sources to be installed. Be sure to obtain the relevant kernel sources, then return here for the rest of section.

如果全手动配置看起来太恐怖,系统管理员应该考虑使用 genkernel 混合方法来维护内核。

Genkernel 提供了通用的内核配置文件,并且会编译内核和 initramfs,然后将生成的二进制文件安装到适当的位置。它提供了系统首次启动时最小的常规硬件支持,并允许将来自定义内核配置以及对内核额外升级。

请注意:虽然使用 genkernel 维护内核可以让系统管理员对系统内核,initramfs 和其他选项更新时有更多的操作,但当新的源代码发行时,却投入更多的时间和精力去更新内核。所以那些希望不手动内核维护的人应该使用 distribution 内核

更进一步说,认为 genkernel 可以为正在运行的硬件自动生成自定义的内核配置 是一种误解;genkernel 使用了支持大多数通用硬件的预定的内核配置文件,并且可以自动处理 make 命令来汇编和安装内核、相关模块以及 initramfs 文件。

二进制可再分发软件许可证组

如果已经预先安装了 linux-firmware 软件包,那么跳转到安装章节

由于 sys-kernel/genkernel 软件包默认启用 firwmare USE 标志,所以包管理器还会尝试拉取 sys-kernel/linux-firmware 软件包。安装 linux-firmware 之前,需要接受二进制可再分发软件许可证。

通过在 /etc/portage/make.conf 文件为 ACCEPT_LICENSE 变量添加 @BINARY-REDISTRIBUTABLE 值,可以接受系统范围任何软件包的许可证组。通过在 /etc/portage/package.license/linux-firmware 文件添加特定内容,可以单独接受 linux-firmware 软件包的许可证组。

如果有必要,查看手册安装基本系统里的接受软件许可证的方法章节,然后修改一些可接受的软件许可证。

如果分析不出来,可以这样做:

root #mkdir /etc/portage/package.license
文件 /etc/portage/package.license/linux-firmware为 linux-firmware 软件包接受二进制可再分发许可证(binary redistributable)
sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE

安装

说明完以及准备好之后,安装 sys-kernel/genkernel 软件包:

root #emerge --ask sys-kernel/genkernel

常规

运行genkernel all来编译内核源码。值得注意的是,使用 genkernel 编译的内核适用于不同计算机体系结构的各种硬件,这可能使编译过程需要一阵子来完成。

附注
如果 root 分区/卷 不是使用 ext4 作为文件系统,它可能需要使用 genkernel --menuconfig all 来手动配置内核,并在内核中添加对这个具体文件系统的支持(比如:不是作为一个模块)。LVM2用户可能要作为参数来添加--lvm
附注
LVM2 用户应该在下面 genkernel命令添加 --lvm 参数 。
root #genkernel --mountboot --install all

genkernel 完成后,将在 /boot 目录生成并安装内核和初始化内存文件(initial ram filesystem,initramfs)。/lib/modules 目录将安装相关模块。initramfs 将在内核加载后立即启动,然后进行硬件自动检测(就像在 live 磁盘镜像环境中一样)。

root #ls /boot/vmlinu* /boot/initramfs*
root #ls /lib/modules

可选:手动配置

介绍

附注
In case it was missed, this section requires the kernel sources to be installed. Be sure to obtain the relevant kernel sources, then return here for the rest of section.

手动配置内核经常被 Linux 用户认为是最困难的步骤。但是事实并非如此──当您手动配置几次内核之后,你就不会再觉得它有多么难了!

无论如何,有一件事是真实的:当手动配置内核时,了解(硬件)系统是至关重要的。大多数信息可以通过安装包含lspci命令的sys-apps/pciutils来收集:

root #emerge --ask sys-apps/pciutils
附注
在chroot中,可以安全的忽略任何lspci可能抛出的关于pcilib的警告(比如pcilib: cannot open /sys/bus/pci/devices)。

另一个系统信息来源是运行lsmod来查看安装CD使用什么内核模块,它可能对启用什么提供了一个好的暗示。

现在进入内核源码目录并执行make menuconfig。这将启动一个菜单驱动的配置屏幕。

root #cd /usr/src/linux
root #make menuconfig

Linux 内核配置有很多很多的章节。我们先列出一些必须激活的选项(否则 Gentoo 将无法工作,或者离开附加的调整将无法正常工作)。我们同时在 Gentoo 维基上有一个 Gentoo 内核配置指南可能会在将来有帮助。

启用必要的选项

当使用 sys-kernel/gentoo-sources 时,强烈推荐启用 Gentoo 特有的配置选项。这些确保了系统可以正常运行所需的最少内核特性:

内核 启用 Gentoo 特有选项
Gentoo Linux --->
  Generic Driver Options --->
    [*] Gentoo Linux support
    [*]   Linux dynamic and persistent device naming (userspace devfs) support
    [*]   Select options required by Portage features
        Support for init systems, system and service managers  --->
          [*] OpenRC, runit and other script based systems and managers
          [*] systemd

当然,最后两行的选择取决于所选择的 init 系统 (OpenRC 对比 systemd)。但是两种 init 系统都启用也并没有害处。

当使用 sys-kernel/vanilla-sources时,不能使用额外的 init 系统。可以使用已启用的 init 系统,但这超出了手册的范围。

启用典型的系统组件支持

确保引导系统的每一个至关重要的驱动(比如 SATA 控制器,NVMe 块设备支持,文件系统支持,等等)是编译进内核而不是作为一个模块,否则系统将无法完全引导。

接下来选择最正确的CPU类型。同时建议启用MCE功能(如果可用)能在硬件出现问题时通知用户。在一些架构(比如x86_64),这些错误不会打印到 dmesg,但是会到/dev/mcelog。这需要app-admin/mcelog包。

同时选择Maintain a devtmpfs file system to mount at /dev来让重要的设备文件在引导过程的早期就已就绪(CONFIG_DEVTMPFS and CONFIG_DEVTMPFS_MOUNT):

内核 启用 devtmpfs 支持(CONFIG_DEVTMPFS
Device Drivers --->
  Generic Driver Options --->
    [*] Maintain a devtmpfs filesystem to mount at /dev
    [*]   Automount devtmpfs at /dev, after the kernel mounted the rootfs

验证 SCSI 磁盘支持是否已激活(CONFIG_BLK_DEV_SD):

内核 启用 SCSI 磁盘支持(CONFIG_SCSI, CONFIG_BLK_DEV_SD
Device Drivers --->
  SCSI device support  ---> 
    <*> SCSI device support
    <*> SCSI disk support
内核 启用基础 SATA 和 PATA 支持(CONFIG_ATA_ACPI, CONFIG_SATA_PMP, CONFIG_SATA_AHCI, CONFIG_ATA_BMDMA, CONFIG_ATA_SFF, CONFIG_ATA_PIIX
Device Drivers --->
  <*> Serial ATA and Parallel ATA drivers (libata)  --->
    [*] ATA ACPI Support
    [*] SATA Port Multiplier support
    <*> AHCI SATA support (ahci)
    [*] ATA BMDMA support
    [*] ATA SFF support (for legacy IDE and PATA)
    <*> Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support (ata_piix)

验证已经启用基础 NVMe 支持:

内核 启用 Linux 4.4.x 基础 NVMe 支持(CONFIG_BLK_DEV_NVME
Device Drivers  --->
  <*> NVM Express block device
内核 启用 Linux 5.x.x 基础 NVMe 支持(CONFIG_DEVTMPFS
Device Drivers --->
  NVME Support --->
    <*> NVM Express block device

也可以启用下列额外的 NVMe 支持:

内核 启用额外的 NVMe 支持(CONFIG_NVME_MULTIPATHCONFIG_NVME_MULTIPATHCONFIG_NVME_HWMONCONFIG_NVME_FCCONFIG_NVME_TCPCONFIG_NVME_TARGETCONFIG_NVME_TARGET_PASSTHRUCONFIG_NVME_TARGET_LOOPCONFIG_NVME_TARGET_FCCONFIG_NVME_TARGET_FCLOOPCONFIG_NVME_TARGET_TCP
[*] NVMe multipath support
[*] NVMe hardware monitoring
<M> NVM Express over Fabrics FC host driver
<M> NVM Express over Fabrics TCP host driver
<M> NVMe Target support
  [*]   NVMe Target Passthrough support
  <M>   NVMe loopback device support
  <M>   NVMe over Fabrics FC target driver
  < >     NVMe over Fabrics FC Transport Loopback Test driver (NEW)
  <M>   NVMe over Fabrics TCP target support

现在进入File Systems并选择系统将使用的文件系统。不要作为模块来编译根文件系统所使用的文件系统,否则系统可能不挂载这个分区。同时选择Virtual memory/proc file system根据系统的需要选择一个或多个以下选项:

内核 启用文件系统支持 (CONFIG_EXT2_FS, CONFIG_EXT3_FS, CONFIG_EXT4_FS, CONFIG_BTRFS_FS, CONFIG_XFS_FS, CONFIG_MSDOS_FS, CONFIG_VFAT_FS, CONFIG_PROC_FS, and CONFIG_TMPFS)
File systems --->
  <*> Second extended fs support
  <*> The Extended 3 (ext3) filesystem
  <*> The Extended 4 (ext4) filesystem
  <*> Btrfs filesystem support
  <*> XFS filesystem support
  DOS/FAT/NT Filesystems  --->
    <*> MSDOS fs support
    <*> VFAT (Windows-95) fs support
  Pseudo Filesystems --->
    [*] /proc file system support
    [*] Tmpfs virtual memory file system support (former shm fs)

如果使用PPPoE连接到互联网,或者是拨号调制解调器,则启用下面的选项(CONFIG_PPP, CONFIG_PPP_ASYNC, and CONFIG_PPP_SYNC_TTY):

内核 启用 PPPoE 所需要的驱动(PPPoECONFIG_PPPOECONFIG_PPP_ASYNCCONFIG_PPP_SYNC_TTY
Device Drivers --->
  Network device support --->
    <*> PPP (point-to-point protocol) support
    <*>   PPP support for async serial ports
    <*>   PPP support for sync tty ports

这两个压缩选项将是无害的,但是它们一定是不需要的,包括基于以太网的PPP选项也是一样,只有在配置内核模式PPPoE时才会需要。

不要忘记在内核中包括网(以太网或无线)卡。

大多数系统会有多核心处理,所以激活 Symmetric multi-processing support(对称多处理) 很重要 (CONFIG_SMP):

内核 激活 SMP 支持(CONFIG_SMP
Processor type and features  --->
  [*] Symmetric multi-processing support
附注
在多核系统中,每个核心视为一个处理器。

如果使用USB输入设备(比如键盘和鼠标)或其他USB设备,不要忘记启用那些:

内核 启用 USB 和人类输入设备支持(CONFIG_HID_GENERICCONFIG_USB_HIDCONFIG_USB_SUPPORTCONFIG_USB_XHCI_HCD,var>CONFIG_USB_EHCI_HCD,CONFIG_USB_OHCI_HCD(CONFIG_HID_GENERICCONFIG_USB_HIDCONFIG_USB_SUPPORTCONFIG_USB_XHCI_HCDCONFIG_USB_EHCI_HCDCONFIG_USB_OHCI_HCDCONFIG_USB4
HID support  --->
    -*- HID bus support
    <*>   Generic HID driver
    [*]   Battery level reporting for HID devices
      USB HID support  --->
        <*> USB HID transport layer
  [*] USB support  --->
    <*>     xHCI HCD (USB 3.0) support
    <*>     EHCI HCD (USB 2.0) support
    <*>     OHCI HCD (USB 1.1) support

Optional: Signed kernel modules

To automatically sign the kernel modules enable CONFIG_MODULE_SIG_ALL:

内核 Sign kernel modules CONFIG_MODULE_SIG_ALL
[*] Enable loadable module support  
  -*-   Module signature verification    
    [*]     Automatically sign all modules    
    Which hash algorithm should modules be signed with? (Sign modules with SHA-512) --->

Optionally change the hash algorithm if desired.

To enforce that all modules are signed with a valid signature, enable CONFIG_MODULE_SIG_FORCE as well:

内核 Enforce signed kernel modules CONFIG_MODULE_SIG_FORCE
[*] Enable loadable module support  
  -*-   Module signature verification    
    [*]     Require modules to be validly signed
    [*]     Automatically sign all modules
    Which hash algorithm should modules be signed with? (Sign modules with SHA-512) --->

To use a custom key, specify the location of this key in CONFIG_MODULE_SIG_KEY, if unspecified the kernel build system will generate a key. It is recommended to generate one manually instead. This can be done with:

root #openssl req -new -nodes -utf8 -sha256 -x509 -outform PEM -out kernel_key.pem -keyout kernel_key.pem

OpenSSL will ask some questions about the user generating the key, it is recommended to fill in these questions as detailed as possible.

Store the key in a safe location, at the very least the key should be readable only by the root user. Verify this with:

root #ls -l kernel_key.pem
 -r-------- 1 root root 3164 Jan  4 10:38 kernel_key.pem 

If this outputs anything other then the above, correct the permissions with:

root #chown root:root kernel_key.pem
root #chmod 400 kernel_key.pem
内核 Specify signing key CONFIG_MODULE_SIG_KEY
-*- Cryptographic API  ---> 
  Certificates for signature checking  --->  
    (/path/to/kernel_key.pem) File name or PKCS#11 URI of module signing key

To also sign external kernel modules installed by other packages via linux-mod-r1.eclass, enable the modules-sign USE flag globally:

文件 /etc/portage/make.confEnable module signing
USE="modules-sign"
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
# Optionally, when using custom signing keys.
MODULES_SIGN_KEY="/path/to/kernel_key.pem"
MODULES_SIGN_CERT="/path/to/kernel_key.pem" # Only required if the MODULES_SIGN_KEY does not also contain the certificate
MODULES_SIGN_HASH="sha512" # Defaults to sha512
附注
The MODULES_SIGN_KEY and MODULES_SIGN_CERT may be different files. For this example the pem file generated by OpenSSL includes both the key and the accompanying certificate, and thus both variables are set to the same value.

Optional: Signing the kernel image (Secure Boot)

When signing the kernel image (for use on systems with Secure Boot enabled) it is recommended to set the following kernel config options:

内核 Lockdown for secureboot
General setup  --->
  Kexec and crash features  --->   
    [*] Enable kexec system call                                                                                          
    [*] Enable kexec file based system call                                                                               
    [*]   Verify kernel signature during kexec_file_load() syscall                                                        
    [*]     Require a valid signature in kexec_file_load() syscall                                                        
    [*]     Enable ""image"" signature verification support
</div>  

<div lang="en" dir="ltr" class="mw-content-ltr">
[*] Enable loadable module support  
  -*-   Module signature verification    
    [*]     Require modules to be validly signed
    [*]     Automatically sign all modules
    Which hash algorithm should modules be signed with? (Sign modules with SHA-512) --->
</div>  

<div lang="en" dir="ltr" class="mw-content-ltr">
Security options  ---> 
[*] Integrity subsystem   
  [*] Basic module for enforcing kernel lockdown                                                                       
  [*]   Enable lockdown LSM early in init                                                                       
        Kernel default lockdown mode (Integrity)  --->
</div>            

  <div lang="en" dir="ltr" class="mw-content-ltr">
[*]   Digital signature verification using multiple keyrings                                                            
  [*]     Enable asymmetric keys support                                                                                     
  -*-       Require all keys on the integrity keyrings be signed                                                              
  [*]       Provide keyring for platform/firmware trusted keys                                                                
  [*]       Provide a keyring to which Machine Owner Keys may be added                                                        
  [ ]         Enforce Machine Keyring CA Restrictions

Where ""image"" is a placeholder for the architecture specific image name. These options, from the top to the bottom: enforces that the kernel image in a kexec call must be signed (kexec allows replacing the kernel in-place), enforces that kernel modules are signed, enables lockdown integrity mode (prevents modifying the kernel at runtime), and enables various keychains.

On arches that do not natively support decompressing the kernel (e.g. arm64 and riscv), the kernel must be built with its own decompressor (zboot):

内核 zboot CONFIG_EFI_ZBOOT
Device Drivers --->                                                                                                                           
  Firmware Drivers --->                                                                                                                       
    EFI (Extensible Firmware Interface) Support --->                                                                                               
      [*] Enable the generic EFI decompressor

After compilation of the kernel, as explained in the next section, the kernel image must be signed. First install app-crypt/sbsigntools and then sign the kernel image:

root #emerge --ask app-crypt/sbsigntools
root #sbsign /usr/src/linux-x.y.z/path/to/kernel-image --cert /path/to/kernel_key.pem --key /path/to/kernel_key.pem --out /usr/src/linux-x.y.z/path/to/kernel-image
附注
For this example the same key that was generated to sign the modules is used to sign the kernel image. It is also possible to generate and use a second sperate key for signing the kernel image. The same OpenSSL command as in the previous section may be used again.

Then proceed with the installation.

To automatically sign EFI executables installed by other packages, enable the secureboot USE flag globally:

文件 /etc/portage/make.confEnable Secure Boot
USE="modules-sign secureboot"
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
# Optionally, to use custom signing keys.
MODULES_SIGN_KEY="/path/to/kernel_key.pem"
MODULES_SIGN_CERT="/path/to/kernel_key.pem" # Only required if the MODULES_SIGN_KEY does not also contain the certificate.
MODULES_SIGN_HASH="sha512" # Defaults to sha512
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
# Optionally, to boot with secureboot enabled, may be the same or different signing key.
SECUREBOOT_SIGN_KEY="/path/to/kernel_key.pem"
SECUREBOOT_SIGN_CERT="/path/to/kernel_key.pem"
附注
The SECUREBOOT_SIGN_KEY and SECUREBOOT_SIGN_CERT may be different files. For this example the pem file generated by OpenSSL includes both the key and the accompanying certificate, and thus both variables are set to the same value.
附注
When generating an Unified Kernel Image with systemd's ukify the kernel image will be signed automatically before inclusion in the unified kernel image and it is not necessary to sign it manually.

Handbook:PPC/Blocks/Kernel/zh-cn

Kernel installation

Installkernel

Installkernel may be used to automate, the kernel installation, initramfs generation, unified kernel image generation and/or bootloader configuration among other things. sys-kernel/installkernel implements two paths of achieving this: the traditional installkernel originating from Debian and systemd's kernel-install. Which one to choose depends, among other things, on the system's bootloader. By default systemd's kernel-install is used on systemd profiles, while the traditional installkernel is the default for other profiles.

If unsure, follow the 'Traditional layout' subsection below.

systemd-boot

When using systemd-boot (formerly gummiboot) as the bootloader, systemd's kernel-install must be used. Therefore ensure the systemd and the systemd-boot USE flags are enabled on sys-kernel/installkernel, and then install the relevant package for systemd-boot.

On OpenRC systems:

文件 /etc/portage/package.use/systemd-boot
sys-apps/systemd-utils boot kernel-install
sys-kernel/installkernel systemd systemd-boot
root #emerge --ask sys-apps/systemd-utils

On systemd systems:

文件 /etc/portage/package.use/systemd
sys-apps/systemd boot
sys-kernel/installkernel systemd-boot
# Needed for <systemd-254
sys-apps/systemd gnuefi
root #emerge --ask sys-apps/systemd

GRUB

Users of GRUB can use either systemd's kernel-install or the traditional Debian installkernel. The systemd USE flag switches between these implementations. To automatically run grub-mkconfig when installing the kernel, enable the grub USE flag.

文件 /etc/portage/package.use/installkernel
sys-kernel/installkernel grub
root #emerge --ask sys-kernel/installkernel

When systemd's kernel-install is used, it should be configured to use the grub layout, this is the default if the grub USE flag is enabled:

文件 /etc/kernel/install.conf
layout=grub

Traditional layout, other bootloaders (e.g. lilo, etc.)

The traditional /boot layout (for e.g. LILO, etc.) is used by default if the grub, systemd-boot and uki USE flags are not enabled. No further action is required.


Building an initramfs

In certain cases it is necessary to build an initramfs - an initial ram-based file system. The most common reason is when important file system locations (like /usr/ or /var/) are on separate partitions. With an initramfs, these partitions can be mounted using the tools available inside the initramfs. The default configuration of the Project:Distribution Kernel requires an initramfs.

Without an initramfs, there is a risk that the system will not boot properly as the tools that are responsible for mounting the file systems require information that resides on unmounted file systems. An initramfs will pull in the necessary files into an archive which is used right after the kernel boots, but before the control is handed over to the init tool. Scripts on the initramfs will then make sure that the partitions are properly mounted before the system continues booting.

重要
If using genkernel, it should be used for both building the kernel and the initramfs. When using genkernel only for generating an initramfs, it is crucial to pass --kernel-config=/path/to/kernel.config to genkernel or the generated initramfs may not work with a manually built kernel. Note that manually built kernels go beyond the scope of support for the handbook. See the kernel configuration article for more information.

Installkernel can automatically generate an initramfs when installing the kernel if the dracut USE flag is enabled:

文件 /etc/portage/package.use/installkernel
sys-kernel/installkernel dracut

Alternatively, dracut may be called manually to generate an initramfs. Install sys-kernel/dracut first, then have it generate an initramfs:

root #emerge --ask sys-kernel/dracut
root #dracut --kver=3.16.5-gentoo

The initramfs will be stored in /boot/. The resulting file can be found by simply listing the files starting with initramfs:

root #ls /boot/initramfs*

Optional: Building an Unified Kernel Image

An Unified Kernel Image (UKI) combines, among other things, the kernel, the initramfs and the kernel command line into a single executable. Since the kernel command line is embedded into the unified kernel image it should be specified before generating the unified kernel image (see below). Note that any kernel command line arguments supplied by the bootloader or firmware at boot are ignored when booting with secure boot enabled.

An unified kernel image requires a stub loader, currently the only one available is systemd-stub. To enable it:

For systemd systems:

文件 /etc/portage/package.use/systemd
sys-apps/systemd boot

For OpenRC systems:

文件 /etc/portage/package.use/systemd-utils
sys-apps/systemd-utils boot

Installkernel can automatically generate an unified kernel image using either dracut or ukify, by enabling the respective flag. The uki USE flag should be enabled as well to install the generated unified kernel image to the $ESP/EFI/Linux directory on the EFI system partition (ESP).

For dracut:

文件 /etc/portage/package.use/installkernel
sys-kernel/installkernel dracut uki
文件 /etc/dracut.conf
uefi="yes"
kernel_cmdline="some-kernel-command-line-arguments"

For ukify:

文件 /etc/portage/package.use/installkernel
sys-kernel/installkernel dracut ukify uki
文件 /etc/kernel/cmdline
some-kernel-command-line-arguments

Note that while dracut can generate both an initramfs and an unified kernel image, ukify can only generate the latter and therefore the initramfs must be generated separately with dracut.

Generic Unified Kernel Image

The prebuilt sys-kernel/gentoo-kernel-bin can optionally install a prebuilt generic unified kernel image containing a generic initramfs that is able to boot most systemd based systems. It can be installed by enabling the generic-uki USE flag, and configuring installkernel to not generate a custom initramfs or unified kernel image:

文件 /etc/portage/package.use/generic-uki
sys-kernel/gentoo-kernel-bin generic-uki
sys-kernel/installkernel -dracut -ukify uki

Secure Boot

The generic Unified Kernel Image optionally distributed by sys-kernel/gentoo-kernel-bin is already pre-signed. How to sign a locally generated unified kernel image depends on whether dracut or ukify is used. Note that the location of the key and certificate should be the same as the SECUREBOOT_SIGN_KEY and SECUREBOOT_SIGN_CERT as specified in /etc/portage/make.conf.

For dracut:

文件 /etc/dracut.conf
uefi="yes"
kernel_cmdline="some-kernel-command-line-arguments"
uefi_secureboot_key="/path/to/kernel_key.pem"
uefi_secureboot_cert="/path/to/kernel_key.pem"

For ukify:

文件 /etc/kernel/uki.conf
[UKI]
SecureBootPrivateKey=/path/to/kernel_key.pem
SecureBootCertificate=/path/to/kernel_key.pem

Rebuilding external kernel modules

External kernel modules installed by other packages via linux-mod-r1.eclass must be rebuilt for each new kernel version. When the distribution kernels are used this may be automated by enabling the dist-kernel flag globally.

文件 /etc/portage/package.use/module-rebuild
*/* dist-kernel

External kernel modules may also be rebuilt manually with:

root #emerge --ask @module-rebuild

内核模块

列出可用的内核模块

附注
硬件模块手动列出是可选的。在大多数情况下,udev 通常将加载所有被检测为已连接的硬件模块。然而,列出自动检测到的模块并没有什么不良影响的。有时,一些奇特硬件需要帮助来加载其驱动程序。

可以在 /etc/modules-load.d/*.conf 文件中添加需要在每次启动时加载的模块,格式为每行一个模块。如果模块需要附加选项,可以在 /etc/modprobe.d/*.conf 文件内设置。

对于特定的内核版本,如果要查看所有可用模块,使用下面的 find 命令。不要忘记在查找时替换 “<kernel version>” 为对应的内核版本:

root #find /lib/modules/<kernel version>/ -type f -iname '*.o' -or -iname '*.ko' | less

强制加载特定内核模块

要强制加载内核 3c59x.ko 模块(3Com 网卡家族的特定驱动),编辑/etc/modules-load.d/network.conf 文件并在里面输入模块名字。

root #mkdir -p /etc/modules-load.d
root #nano -w /etc/modules-load.d/network.conf

注意,模块的 .ko 文件后缀对加载机制影响不大,所以配置文件中没有文件后缀:

文件 /etc/modules-load.d/network.conf强制加载 3c59x 模块
3c59x

继续到配置系统来安装。





文件系统信息

分区表和 UUID

MBR(BIOS)和GPT都支持“文件系统”标签和“文件系统”的UUID。 这些属性可以在尝试查找和挂载块设备时使用,作为 mount 命令的替代方法,在 /etc/fstab 中定义。文件系统标签和 UUID 由 LABELUUID 前缀标识,可以使用 blkid 命令查看:

root #blkid
警告
如果分区中的文件系统被擦除,则文件系统标签和UUID值将随后被更改或删除。

出于唯一性,建议使用 MBR 分区表的读者使用 UUID 来定义/etc/fstab 中的可挂载卷。

重要
LVM 卷文件系统的 UUID 与其 LVM 快照相同,因此应避免使用 UUID 挂载 LVM 卷。

分区卷标和 UUID

已经使用 GPT 磁盘的用户有一些更稳定的选项可用于在 /etc/fstab 中定义分区。分区卷标和分区 UUID 可以用来标识块设备的单独分区,而不管为分区本身选择了什么文件系统。分区卷标和 UUID 分别由 PARTLABEL PARTUUID 前缀标识,可以通过运行 blkid 命令在终端中很好地查看分区标签。EFI 系统的输出如下所示:

Output for an amd64 EFI system using the Discoverable Partition Specification UUIDs may like the following:

root #blkid
/dev/sr0: BLOCK_SIZE="2048" UUID="2023-08-28-03-54-40-00" LABEL="ISOIMAGE" TYPE="iso9660" PTTYPE="PMBR"
/dev/loop0: TYPE="squashfs"
/dev/sda2: UUID="12c37dea-624b-48b6-88b8-fba427f5f341" TYPE="swap" PARTLABEL="swap" PARTUUID="0657fd6d-a4ab-43c4-84e5-0933c84b4f4f"
/dev/sda3: UUID="9bd83a8f-75c6-4a04-b155-6f6b748509a9" BLOCK_SIZE="512" TYPE="xfs" PARTLABEL="rootfs" PARTUUID="4f68bce3-e8cd-4db1-96e7-fbcaf984b709"
/dev/sda1: UUID="166F-2917" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="efi" PARTUUID="c12a7328-f81f-11d2-ba4b-00a0c93ec93b"

虽然对于分区表不总是正确的,但使用UUID来标识fstab 中的分区,即使文件系统更改,也可以保证在寻找某个卷时引导加载程序不会被混淆。对于经常重新启动并定期添加和删除SATA设备时,在 fstab 中定义分区,使用旧的默认分区文件 (/dev/sd*N非常危险) 。

块设备文件的命名取决于许多因素,包括磁盘如何以及以什么顺序加载到系统。它们也可能以不同的顺序显示,具体情况取决于在早期启动过程中内核首先检测到哪些设备。因此,除非系统管理员打算经常调整磁盘顺序,否则可以简单直接地使用默认块设备文件。

关于 fstab

在Linux系统下,系统所用到的所有分区都必须在 /etc/fstab 文件中指明。这个文件包含了这些分区的挂载点(在系统目录树中的位置)、挂载方法和特殊挂载选项(是否自动挂载,是否某个用户可以挂载它等)。

创建 /etc/fstab 文件

/etc/fstab 文件使用一种特殊语法格式。每行都包含六个字段。这些字段之间由空白键(空格键,tab键,或者两者混合使用)分隔。每个字段都有自己的含意:

  1. #第一个字段显示要挂载的特殊 block 设备或远程文件系统。 有几种设备标识符可用于特殊块设备节点,包括设备文件路径,文件系统标签,UUID,分区标签以及UUID。
  2. 第二个字段是分区挂载点,也就是分区应该挂载到的地方。
  3. 第三个字段给出分区所用的文件系统的类型。
  4. 第四个字段给出的是挂载分区时 mount 命令所用的挂载选项。由于每个文件系统都有自己的挂载选项,我们建议系统管理员阅读 mount 手册(man mount)以获得所有挂载选项的列表。多个挂载选项之间是用逗号分隔的。
  5. 第五个字段是给dump使用的,用以决定这个分区是否需要dump。一般情况下,你可以把该字段设为 0(零)。
  6. 第六个字段是给fsck使用的,用以决定系统非正常关机之后文件系统的检查顺序。根文件系统应该为 1,而其它的应该为 2(如果不需要文件系统自检的话可以设为 0)。
重要
Gentoo stage 文件默认提供的 /etc/fstab “不”是有效的fstab 文件,它只是提供了几个模板,可用于输入相关值。
root #nano /etc/fstab

DOS/传统 BIOS 系统

让我们来看看如何写下/boot/分区的选项。 这只是一个示例,应根据安装时的具体情况进行修改。 在ppc分区示例中, /boot/ 通常是/dev/sda1 xfs 作为文件系统。 它需要在启动期间进行检查,所以我们写下:

文件 /etc/fstab/etc/fstab 中 DOS/传统 BIOS 启动行的示例
# 调整与"准备磁盘"步骤的任何格式差异
/dev/sda1            defaults        0 2

有些用户不希望 /boot/ 分区自动挂载,以提高系统的安全性。 他们应该用noauto.代替 defaults。这意味着这些用户将需要在每次他们想要使用它时手动挂载这个分区。

增加符合你分区方案的规则,为你的光驱(当然,如果你有其他分区或者驱动器,也为它们加上)添加挂载规则。

下面是/etc/fstab文件的例子:

文件 /etc/fstab针对 DOS/传统 BIOS 系统 的完整 /etc/fstab 例子
# 调整与"准备磁盘"步骤的任何格式差异
/dev/sda1               defaults    0 2
/dev/sda2   none         swap    sw                   0 0
/dev/sda3   /            xfs    defaults,noatime              0 1
</div>

/dev/cdrom  /mnt/cdrom   auto    noauto,user          0 0

UEFI 系统

Below is an example of an /etc/fstab file for a system that will boot via UEFI firmware:

文件 /etc/fstabA full /etc/fstab example for an UEFI system
# Adjust for any formatting differences and/or additional partitions created from the "Preparing the disks" step
/dev/sda1                    0 2
/dev/sda2   none             sw                   0 0
/dev/sda3   /            xfs    defaults,noatime              0 1
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
/dev/cdrom  /mnt/cdrom   auto    noauto,user          0 0

DPS UEFI PARTUUID

Below is an example of an /etc/fstab file for a disk formatted with a GPT disklabel and Discoverable Partition Specification (DPS) UUIDs set for UEFI firmware:

文件 /etc/fstabGPT disklabel DPS PARTUUID fstab example
# Adjust any formatting difference and additional partitions created from the "Preparing the disks" step.
# This example shows a GPT disklabel with Discoverable Partition Specification (DSP) UUID set:
PARTUUID=c12a7328-f81f-11d2-ba4b-00a0c93ec93b                                  0 2
PARTUUID=0657fd6d-a4ab-43c4-84e5-0933c84b4f4f   none            sw                           0 0
PARTUUID=   /           xfs    defaults,noatime              0 1

auto选项可以使mount 猜测文件系统(推荐对于可移动设备采用这个选项,因为它们可能采用很多不同的文件系统),而 user选项使得非root用户可以挂载光驱。

To improve performance, most users would want to add the noatime mount option, which results in a faster system since access times are not registered (those are not needed generally anyway). This is also recommended for systems with solid state drives (SSDs). Users may wish to consider lazytime instead.

提示
由于会使性能下降,所以不推荐在 /etc/fstab 定义 discard 挂载选项。一般来说,最好使用作业调度器(例如 cron 或 timer (systemd))定期丢弃块。查看定期 fstrim 作业来获取更多信息。

仔细检查/etc/fstab文件,保存并退出以继续。

网络信息

特别注意,以下部分可以帮助读者快速设置他们的系统接入局域网。

对于运行 OpenRC 的系统,更多网络设置的细节参考高级网络配置章节,手册末尾附近有介绍。有更具体网络需求的系统可能需要跳过此章节,然后返回此处继续后续的安装。

更多关于 systemd 具体的网络设置,请参考 systemd 文章的网络部分

主机名

系统管理员必须要做的事情之一就是命名他们的机器。尽管这看上去很容易,但是很多用户觉得很难起一个合适的主机名。为了加快进度,应该知道所有你所命名的名字都是可以在今后重新修改的。下面的示例使用 tux 作为主机名。

设置主机名(OpenRC 和 systemd)

root #echo tux > /etc/hostname

systemd

可以使用 hostnamectl 工具在正运行 systemd 的系统设置系统的主机名。但是,在安装过程中,应当使用 systemd-firstboot 命令(参见手册的后续部分)。

可以将设置主机名为 "tux":

root #hostnamectl hostname tux

运行 hostnamectl --helpman 1 hostnamectl 查看帮助。

网络

配置网络接口有许多可用的方法。本章节只介绍了其中一些方法。你可以选择一个看起来最合适的设置方法。

通过 dhcpcd 使用 DHCP (任何 init 系统)

大多数 LAN 网络都运行 DHCP 服务器。如果是这种情况,则建议使用 dhcpcd 程序获取 IP 地址。

安装:

root #emerge --ask net-misc/dhcpcd

在 OpenRC 系统中启用和开始服务:

root #rc-update add dhcpcd default
root #rc-service dhcpcd start

在 systemd 系统中启用服务:

root #systemctl enable dhcpcd

完成这些步骤后,下次系统启动时,dhcpcd 应该就会从 DHCP 服务器获取 IP 地址。 更多细节请查看 Dhcpcd 文章。

netifrc (OpenRC)

提示
在 OpenRC 使用 Netifrc 设置网络是一种特殊的方法。还有更简单的方法设置,比如 Dhcpcd

配置网络

在Gentoo Linux安装时,网络已经配置。然而,这是安装的 live 环境本身的配置,并不是新的系统环境的网络配置。现在你所要设置的是 Gentoo 系统的永久网络配置。

附注
更多关于网络配置的详细信息,包括网卡绑定、网桥、802.1Q VLANs和无线网络在内的高级配置会在高级网络配置这一部分介绍.

/etc/conf.d/net 当中收集了所有的网络信息。尽管这个文件采用直接易懂的语法,如果你还是因为觉得不够直观而完全不知道如何手动进行网络配置的话,请不用担心,我们将一一解释。在 /usr/share/doc/netifrc-*/net.example.bz2 中有一个详细注释过的例子,它涵盖了许多种类不同的配置。

首先安装net-misc/netifrc:

root #emerge --ask --noreplace net-misc/netifrc

系统默认使用DHCP。如果使用DHCP的话,你需要安装一个DHCP客户端。这个将在稍后的安装必要的系统工具部分介绍。

如果你需要配置你的网络连接,不管是因为你是需要指定DHCP选项还是你不使用DHCP,打开 /etc/conf.d/net:;

root #nano /etc/conf.d/net

设置 config_eth0routes_eth0 输入IP地址信息和路由信息:

附注
假定网络接口名称是 eth0。这个名称非常依赖于系统,如果安装介质足够新,则建议在从安装介质引导时重命名接口。更多信息可以在网络接口命名章节中找到。
文件 /etc/conf.d/net静态IP定义
config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255"
routes_eth0="default via 192.168.0.1"

要使用DHCP,定义 config_eth0:

文件 /etc/conf.d/netDHCP 配置
config_eth0="dhcp"

请阅读 /usr/share/doc/netifrc-*/net.example.bz2 获取额外的配置文件选项的列表。如果你需要设定特殊的 DHCP 选项,请参考你的 DHCP 客户端的 man 手册页。

如果你有多个网络接口,那么重复之前对于config_eth1config_eth2等操作步骤。

现在保存配置并退出。

在启动时自动启用网络连接

为了在启动时自动激活网络接口,你必须添加这些到default运行级别。

root #cd /etc/init.d
root #ln -s net.lo net.eth0
root #rc-update add net.eth0 default

如果系统有多个网络接口,那么需要创建适当的net.* 文件,就像我们使用net.eth0一样。

如果在引导系统后,发现网络接口名称(目前写作 eth0)是错误的,那么执行以下步骤来纠正这一点:

  1. 用正确的名称更新 /etc/conf.d/net(比如说 enp3s0 或者 enp5s0 取代 eth0)。
  2. 创建符号链接(比如 /etc/init.d/net.enp3s0)。
  3. 删除旧的符号链接(rm /etc/init.d/net.eth0)。
  4. 创建新的默认运行级别。
  5. 删除旧的运行级别,使用 rc-update del net.eth0 default

hosts 文件

现在你需要告诉Linux有关你的网络的信息。这需要在/etc/hosts文件中定义,它将帮助你将那些无法被域名解析器解析的主机名解析成IP地址。

root #nano /etc/hosts
文件 /etc/hostsFilling in the networking information
# 定义当前系统
127.0.0.1     tux.homenetwork tux localhost
  
# 可选,定义网络上的其它系统
192.168.0.5   jenny.homenetwork jenny
192.168.0.6   benny.homenetwork benny

保存并退出编辑器,继续


系统信息

Root 密码

使用passwd命令设置root密码。

root #passwd

稍后将为日常操作创建其他常规用户帐户。

配置引导和启动

OpenRC

当在 Gentoo 中使用 OpenRC 时,系统使用/etc/rc.conf配置系服务,启动和关闭。 打开 /etc/rc.conf 并查看文件中的所有注释。查看设置并根据需要进行更改。

root #nano /etc/rc.conf

接下来,打开/etc/conf.d/keymaps 来处理键盘设置。编辑它就可以设置你的键盘。

root #nano /etc/conf.d/keymaps

要特别注意keymap这个变量 。如果你选择了错误的KEYMAP,在你敲击键盘的时候会有奇怪的结果。

完成 /etc/conf.d/hwclock 的配置之后,保存并退出。

root #nano /etc/conf.d/hwclock

如果你机器上的时钟不用UTC,你需要在配置文件加上clock="local"。否则,你的时钟就有可能出现偏差。

systemd

首先,建议运行 systemd-machine-id-setup ,然后运行 systemd-firstboot ,这将准备正确设置系统的各个组件,以便首次启动进入新的systemd环境。 传递以下选项将包括提示用户设置区域设置、时区、主机名、root 密码和 root shell 值。 它还会为安装分配一个随机机器 ID:

root #systemd-machine-id-setup
root #systemd-firstboot --prompt

接下来,用户应该运行 systemctl 来重置所有已安装工具的文件为预设的策略值:

root #systemctl preset-all --preset-mode=enable-only

虽然可以运行完整的预设更改,但这可能会重置在此过程中已配置的任何服务:

root #systemctl preset-all

这两个步骤将有助于确保从 live 环境平滑过渡到安装过程的首次启动。





系统日志工具

OpenRC

因为有一些工具提供给用户的功能比较类似,它们就没有包含在stage3当中。现在就是你选择安装哪一个的时候了。

首先需要决定的工具就是系统日志机制。Unix 和 Linux 在日志记录功能方面有良好的传统——如果愿意的话,可以把系统发生的所有事件都记录到日志文件中。

Gentoo提供了多种系统日志工具可供选择。包括:

  • app-admin/sysklogd -提供传统的系统日志记录守护程序。默认日志配置容易学习,这个包是初学者的好选择。
  • app-admin/syslog-ng -高级系统记录器。 需要额外配置很多东西, 更高级的用户可以根据它的日志潜力选择这个包; 注意额外的配置是任何种类的智能日志记录的必要条件。
  • app-admin/metalog -一个可以灵活配置的系统日志工具。

Gentoo ebuild 仓库内或许还有其他系统日志工具,因为可用软件包数量每天在增加。

提示
如果打算使用 syslog-ng ,建议安装并且配置 logrotate。syslog-ng 并没有提供系统日志文件的滚动功能。新版本(>= 2.0)的 sysklogd 会自己处理日志滚动。

要安装你所选择的系统日志工具,你可以用 emerge 命令安装它。在 OpenRC 中,使用 rc-update 将它加入默认运行级别。以下就是一个安装 app-admin/sysklogd 并作为系统 syslog 工具的例子:

root #emerge --ask app-admin/sysklogd
root #rc-update add sysklogd default

systemd

日志记录工具一般只有使用 OpenRC 的系统需要选择,systemd 已经自带了一个叫 systemd-journald 的服务作为日志记录工具。systemd-journald 服务通常能够支持并处理大部分上面提到的日志记录工具的功能。换而言之,使用 systemd 运行系统作为服务管理器可以安全跳过添加额外的系统日志记录工具。

更多关于使用 journalctl 审查系统的细节,请查看 man journalctl

对于因为某种原因需要将日志转发到中心主机的情况,在使用 systemd 的系统上支持冗余的系统记录机制可能很重要。但对于本手册的受众和目的来说,这是一个非典型常见且高阶的情况。因此本手册没有涵盖它。

可选:Cron守护进程

OpenRC

尽管这是可选的并且不是系统所必须的,但是最好能够安装一个 cron 守护进程。

cron守护程序执行计划中的命令。 如果某些命令需要定期执行(例如每天,每周或每月),这是非常方便的。

All cron daemons support high levels of granularity for scheduled tasks, and generally include the ability to send an email or other form of notification if a scheduled task does not complete as expected.

Gentoo 提供了三个可选的 cron 守护进程,包括:

  • sys-process/cronie - cronie is based on the original cron and has security and configuration enhancements like the ability to use PAM and SELinux.
  • sys-process/dcron - This lightweight cron daemon aims to be simple and secure, with just enough features to stay useful.
  • sys-process/fcron - A command scheduler with extended capabilities over cron and anacron.
  • sys-process/bcron - A younger cron system designed with secure operations in mind. To do this, the system is divided into several separate programs, each responsible for a separate task, with strictly controlled communications between parts.

cronie

下面的示例使用 sys-process/cronie

root #emerge --ask sys-process/cronie

添加 cronie 作为默认系统运行级别后,将会开机自启。

root #rc-update add cronie default

可选:dcron

root #emerge --ask sys-process/dcron

如果 dcron 是前置 cron agent,则需要执行额外的初始化命令:

root #crontab /etc/crontab

可选:fcron

root #emerge --ask sys-process/fcron

如果选择 fcron 作为任务调度器,则需要额外的 emerge 步骤:

root #emerge --config sys-process/fcron

可选:bcron

bcron 是一款新的内建特权分离的 cron agent。

root #emerge --ask sys-process/bcron

systemd

提示
systemd 不需要 cron 守护进程,因为它有 timers,但仍然可以运行 cron 守护程序。

可选:文件索引

如果你想索引你的系统文件使得你能够使用locate工具很快定位它们,你需要安装sys-apps/mlocate

root #emerge --ask sys-apps/mlocate

可选:远程 shell 访问

提示
opensshd 默认配置不允许远程登录 root 用户。如果有需要的话,请在安装后创建一个非 root 用户,并且配置合适的权限,或者调整 /etc/ssh/sshd_config,使其允许 root 远程登录。

要在安装后远程访问系统,必须配置为在启动时运行sshd

OpenRC

在 OpenRC 上将 sshd init 脚本添加到默认运行级别:

root #rc-update add sshd default

如果需要访问串行控制台(在远程服务器的情况下这是可能的),必须配置 agetty

/etc/inittab 中取消串行控制台部分的注释:

root #nano -w /etc/inittab
# SERIAL CONSOLES
s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100
s1:12345:respawn:/sbin/agetty 9600 ttyS1 vt100

systemd

运行以下命令来启用 SSH 服务端:

root #systemctl enable sshd

运行以下命令来启用串行控制台支持:

root #systemctl enable getty@tty1.service

可选:Shell 补全

Bash

Bash 是Gentoo系统里默认的shell,所以安装补全建议插件支持可以更有效率,更便捷。app-shells/bash-completion 将会提供Gentooo系统特有的和其他常用命令和工具的可用的建议补全

root #emerge --ask app-shells/bash-completion

完成安装后,可以使用eselect命令管理bash的补全支持的项目 。 查阅关于bash补全的文章获取更多详情:Shell completion integrations section

时间同步

使用一些同步系统时钟的方法很重要。通常使用 NTP 协议和软件。有一些 NTP 协议的其他实现,例如 Chrony

设置 Chrony,例如

root #emerge --ask net-misc/chrony

OpenRC

在 OpenRC 上,运行:

root #rc-update add chronyd default

systemd

在 systemd 上,运行:

root #systemctl enable chronyd.service

另外,systemd 用户可能希望使用默认安装的更简单的 systemd-timesyncd SNTP 客户端。

root #systemctl enable systemd-timesyncd.service

文件系统工具

根据你所使用的文件系统的不同,可能需要安装需要的文件系统工具(用于检查文件系统完整性、(重新)格式化文件系统等)。请注意,作为 @system 集一部分的,已经安装了 ext4 用户空间的工具 (sys-fs/e2fsprogs)。

以下的表格列出了特定文件系统所需要安装的工具。

文件系统 软件包
XFS sys-fs/xfsprogs
ext4 sys-fs/e2fsprogs
VFAT (FAT32, ...) sys-fs/dosfstools
Btrfs sys-fs/btrfs-progs
ZFS sys-fs/zfs
JFS sys-fs/jfsutils

It's recommended that sys-block/io-scheduler-udev-rules is installed for the correct scheduler behavior with e.g. nvme devices:

root #emerge --ask sys-block/io-scheduler-udev-rules
提示
获取更多关于Gentoo上文件系统的信息请看文件系统文章

网络工具

如果在之前配置系统步骤配置好网络,并且完成网络设置,那么本‘网络工具’章节可以安全地跳过。这样的话,继续配置引导程序章节。

安装DHCP客户端

重要
大多数用户需要 DHCP 客户端连接到他们网络。如果没有安装的话,则系统可能无法访问网络,从而使之后也无法下载 DHCP 客户端。

DHCP 客户端可以使用 netifrc 脚本自动获取一个或多个IP地址。我们建议使用 net-misc/dhcpcd(另请参阅 dhcpcd):

root #emerge --ask net-misc/dhcpcd

可选:安装PPPoE客户端

如果你需要ppp来连接网络,你需要安装它 net-dialup/ppp

root #emerge --ask net-dialup/ppp

可选:安装无线网络工具

如果系统将连接无线网络,请为开放网络或 WEP 网络安装 net-wireless/iw 包,为 WPA 或 WPA2 网络安装 net-wireless/wpa_supplicant 包。iw 也是一个有用的无线网络扫描的基本诊断工具

root #emerge --ask net-wireless/iw net-wireless/wpa_supplicant

现在继续配置引导启动程序





Handbook:PPC/Blocks/Bootloader/zh-cn

重启系统

退出chroot环境并unmount全部已持载分区。然后敲入一条有魔力的命令来初始化最终的、真实的测试:reboot

(chroot) livecd #exit
livecd~#cd
livecd~#umount -l /mnt/gentoo/dev{/shm,/pts,}
livecd~#umount -R /mnt/gentoo
livecd~#reboot

当别忘了移除 live 镜像,否则可能再次从 live 镜像启动,而不是新安装的 Gentoo 系统!

当重启进全新安装的 Gentoo 环境后,最好进行完成Gentoo安装





用户管理

添加一个日常使用的用户

在 Unix/Linux 系统中,用 root 进行工作是一件危险的事情,应该尽量避免。因此我们强烈推荐您为日常使用添加一个或更多的标准用户账户。

用户所属的组定义了其可以执行的活动。下表中列出了许多您可能希望使用的重要组:

Group Description
audio 允许使用声音设备
cdrom 允许直接使用光驱设备
floppy 允许直接使用软驱
games 允许运行游戏
portage 能够访问portage受限资源。
usb 允许使用USB设备
video 允许使用视频采集设备和硬件加速
wheel 可以使用su.

比如,创建一个叫作 larrywheelusersaudio 组的成员用户,首先使用 root 登录(只有 root 能创建用户)并运行 useradd

Login:root
Password: (Enter the root password)

When setting passwords for standard user accounts, it is good security practice to avoid using the same or a similar password as set for the root user.

Handbook authors recommended to use a password at least 16 characters in length, with a value fully unique from every other user on the system.

root #useradd -m -G users,wheel,audio -s /bin/bash larry
root #passwd larry
Password: (Enter the password for larry)
Re-enter password: (Re-enter the password to verify)

如果一个用户仍需要以 root 身份做一些任务,他们可以使用 su - 来临时得到 root 权限。另一种方式是使用 sudoapp-admin/sudo)或者 doas (app-admin/doas) 工具,如果配置正确的话,非常安全。

磁盘清理

删除安装后的残留文件

如果 Gentoo 安装完毕并且系统已经重启过,并且所有事情都完成好了,那么我们现在就要从硬盘上删除下载的 stage3 的 tar 包。记住它们下载在 / 目录。

The files are located in the / directory and can be removed with the following command:

root #rm /stage3-*.tar.*

下一步该做什么?

不知道接下来该做什么?现在有许多途径可以探索……Getoo 为用户提供了大量的可能性,因此也已经在 wiki 和其他与 Gentoo 相关的子域名上提供大量的文档(少量没有),可以通过这些文档来进行探索(参见下面的 Gentoo 在线章节)。

额外的文档

需要注意的是,由于 Gentoo 中可用的选项数量众多,手册提供的文档范围有限——它主要侧重于启动和运行 Gentoo 系统的基础知识以及基本的系统管理活动。该手册有意排除了有关图形环境的说明、有关强化的详细信息以及其他重要的管理任务。话虽如此,本手册还有更多部分可以帮助读者使用更多基本功能。

读者一定要看一下手册的下一章节使用 Gentoo,讲述了如何保障软件是最新的、如何安装额外的软件包、USE 标记的更多细节、OpenRC init 系统,以及与 Gentoo 系统安装后,管理相关的各种其他信息话题。

除了这本手册,也鼓励读者去探索Gentoo维基的其他角落来寻找更多的、社区提供的文档。Gentoo wiki 组同时提供一个文档概述,其中按照类别列出了一系列的维基文档。比如,它指向的本地化指南能使系统更有家的感觉(特别适用于以英语为第二语言的用户)。

大多数使用桌面的用户将设置图形环境。有许多社区维护支持桌面环境(DEs)窗口管理器 (WMs)的 'meta' 文章。读者应该知道,每个桌面环境设置有略微不同的步骤,这会增加 Bootstrap 的复杂性。

许多其他的 Meta 文章 为我们的读者提供了对 Gentoo 中可用软件的高级概述。

Gentoo 在线

重要
读者应注意,所有在线的 Gentoo 官方网站均受Gentoo的 行为准则约束。活跃于 Gentoo 社区是一种特权,而不是一种权利,用户应该知道行为准则的存在是有原因的。

除了 Libera.Chat 托管的因特网中继聊天( internet relay chat IRC)网络和邮件列表之外,大多数Gentoo 网站要求每个站点都有一个帐户,以便提问、展开讨论或上报 Bug。

论坛 和 IRC

欢迎每个用户来我们的 Gentoo 论坛 或我们的 Gentoo 的 因特网中继聊天( internet relay chat IRC)频道。有很多以前发现的新 Gentoo 安装遇到的问题,在获得一些反馈后得以解决,这些问题的经验可以在论坛中轻松地搜索查看。其他用户第一次使用 Gentoo 遇到安装问题的可能性非常令人惊讶。建议用户在 Gentoo 支持频道寻求帮助之前搜索论坛和 wiki。

邮件列表

这些是提供给社区成员的一些邮件列表,他们更愿意通过电子邮件请求支持或反馈,而不是在论坛或IRC上创建用户帐户。用户需要按照说明进行操作,以便订阅特定的邮件列表。

Bug

有时,在查看 wiki、搜索论坛、在IRC频道或邮件列表中寻求支持之后,并没有问题已知的解决方案。一般来说,这是在 Gentoo 的 Bugzilla 网站 上报告 bug 的信号。

开发指南

希望了解更多有关开发 Gentoo 的读者可以查看开发指南。该指南提供了有关编写 ebuild、使用 eclass 的说明,并提供了 Gentoo 开发中许多基本概念的定义。

结语

Gentoo 是一个健壮、灵活、维护良好的发行版。开发者社区很高兴听到关于如何使Gentoo 成为一个“更好的”发行版的反馈。

在此提醒,任何关于 “本手册”的反馈应该按照如何改进手册?章节中开头的详细准则。

我们期待看到我们的用户将如何选择使用 Gentoo 满足他们独特的用例和需求。



Warning: Display title "Gentoo Linux 手册:安装Gentoo" overrides earlier display title "手册:PPC/全部/安装".