手册:MIPS/安装/安装stage3

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:MIPS/Installation/Stage and the translation is 100% complete.
MIPS 手册
安装
关于安装
选择安装媒介
配置网络
准备磁盘
安装 stage3
安装基础系统
配置内核
配置系统
安装系统工具
配置引导程序
安装收尾
使用 Gentoo
Portage 介绍
USE 标记
Portage 功能特性
Initscript 系统
环境变量
使用 Portage
文件和目录
变量
混合使用不同的软件分支
额外的工具
自定义软件包仓库
高级特性
配置网络
开始
高级配置
模块化网络
无线网络
添加功能
动态管理


选择 stage 文件

提示
On supported architectures, it is recommended for users targeting a desktop (graphical) operating system environment to use a stage file with the term desktop within the name. These files include packages such as sys-devel/llvm and dev-lang/rust-bin and USE flag tuning which will greatly improve install time.

The stage file acts as the seed of a Gentoo install. Stage files are generated with Catalyst by the Release Engineering Team. Stage files are based on specific profiles, and contain an almost-complete system.

When choosing a stage file, it's important to pick one with profile targets corresponding to the desired system type.

附注
从技术上来说,可以将正在安装的 Gentoo 从 OpenRC 切换到 systemd,然后再切换回来。然而,切换需要花费一些功夫,而且超出了安装手册的范围。在下载 stage tarball 之前,请决定是否使用 OpenRC 或 systemd 作为目标 init 系统并下载相关的 stage tarball。

大多数用户应该不需要使用“高级”tar包选项;它们用于特定的软件或硬件配置。

OpenRC

OpenRC 是一个基于依赖的 init 系统(负责在内核启动后启动系统服务),OpenRC 与系统提供的 init 程序保持兼容,通常在 /sbin/init。它是 Gentoo 原创的 init 系统,但也部署在一些其它的 Linux 发行版和 BSD 系统。

默认情况下,OpenRC 不能替代 /sbin/init 文件 以及 100% 兼容 Gentoo init 脚本。这意味着可以在 Gentoo ebuild 仓库找到运行多个守护进程的解决方案。

systemd

systemd 是Linux 系统上一个现代化的 SysV 风格的 init 以及 rc 替代方案。大多数 Linux 发行版使用 systemd 作为主要的 init 系统。Gentoo 全面支持 systemd,并且已经达到预期。如果手册中似乎缺少 systemd 安装路径的内容,在寻求支持之前,请查看 systemd 文章

multilib(32 位和 64 位)

附注
不是所有架构都有 multilib 选项。许多只使用原生代码运行。Multilib 最常应用于amd64

选择一个基础压缩包的系统可以在稍后的安装过程节省大量的时间,特别是当它是一次选择正确的配置文件。stage 包的选择将直接影响未来的系统配置,可以在以后省的头痛。该压缩包 multilib 尽可能使用64位的库,只必要时对32位版本兼容。这对于大多数安装一个很好的选择,因为它在未来的定制提供了极大的灵活性量。那些谁希望自己的系统,能够容易地切换配置,应该下载根据各自的处理器架构 multilib的压缩包选项。

提示
Using multilib targets makes it easier to switch profiles later, compared to no-multilib

no-multilib(纯64位)

警告
刚开始使用 Gentoo 的读者,除非很有必要,否则应该选择 no-multilib 包。把一个系统从 no-multilib 迁移到 multilib 需要极其丰富的使用Gentoo 的知识并熟悉底层的工具链。这一做法甚至可能使工具链开发者不寒而栗。因此不适合胆小的用户,而且也超出了本指南的范围。

选择 no-multilib 压缩包可以在系统的基础上提供完整的64 位操作系统环境。尽管在技术上可行,但这会造成不可切换到 multilib 的配置文件。

下载 stage 文件

设置日期和时间

Stage archives are generally obtained using HTTPS which requires relatively accurate system time. Clock skew can prevent downloads from working, and can cause unpredictable errors if the system time is adjusted by any considerable amount after installation.

可以使用 date 验证当前时间和日期:

root #date
Mon Oct  3 13:16:22 PDT 2021

如果显示的日期/时间超时几分钟,则应使用下列方法之一进行精准更新。

自动

Using NTP to correct clock skew is typically easier and more reliable than manually setting the system clock.

chronyd, part of net-misc/chrony can be used to update the system clock to UTC with:

root #chronyd -q
重要
Systems without a functioning Real-Time Clock (RTC) must sync the system clock at every system start, and on regular intervals thereafter. This is also beneficial for systems with a RTC, as the battery could fail, and clock skew can accumulate.
警告
Standard NTP traffic not authenticated, it is important to verify time data obtained from the network.

手动

When NTP access is unavailable, date can be used to manually set the system clock.

建议所有 Linux 系统使用 UTC 时间。稍后在安装期间将定义时区,这将修改时钟的显示为本地时间。

以下参数格式用于设置时间:MMDDhhmmYYYY 语法(Month(月),Day(天),hour(小时),minute(分钟) 和 Year(年))。

比如,设置时间到 2021 年 10 月 3 日的 13:16,示例:

root #date 100313162021

前往挂载根文件系统的 Gentoo 挂载点(类似于 /mnt/gentoo):

root #cd /mnt/gentoo

图形化浏览器

可以使用图形化网页浏览器从主网站下载小节复制 stage 文件 URL。只需选择适当的选项卡,右键单击 stage 文件的链接,然后复制链接到剪贴板,然后将链接粘贴到命令行中的 wget 程序来下载 stage 文件:

root #wget <PASTED_STAGE_FILE_URL>

命令行浏览器

更多传统的读者或是 Gentoo 的“老前辈”专门使用命令行工作,他们可能更喜欢使用非图形化菜单驱动的浏览器 linkswww-client/links)。 要下载一个 stage,请像下面这样访问Gentoo镜像列表:

root #links https://www.gentoo.org/downloads/mirrors/

要设置links使用一个HTTP代理,在传入URL上加一个-http-proxy选项:

root #links -http-proxy proxy.server.com:8080 https://www.gentoo.org/downloads/mirrors/

links之外还有一个 lynxwww-client/lynx)浏览器。和links 类似,它也是一个非图形化的浏览器,但不是自带的。

root #lynx https://www.gentoo.org/downloads/mirrors/

如果需要定义一个代理,设置http_proxy和/或ftp_proxy变量:

root #export http_proxy="http://proxy.server.com:port"
root #export ftp_proxy="http://proxy.server.com:port"

在镜像列表中,选择一个附近镜像站。通常HTTP镜像站就足够了,但其他网络协议是可用的。请访问releases/mips/autobuilds/ 。 那里将显示所有可用stage文件 (可能他们个别小组架构在命名的子目录中存储)。选择一个,然后按 d 下载。

stage 文件下载完成后,可以验证 stage 文件的完整性并验证其内容。感兴趣的人应该进行 下一节

对验证 stage 文件不感兴趣的用户可以通过按 q 来关闭命令行浏览器,并且可以直接移步到 解包 stage 文件 部分。

验证

附注
大多数 stages 现在明确带有 init 系统类型 (openrcsystemd)后缀,尽管某些架构现在可能仍然缺少后缀。

与最小安装CD一样,可以使用额外的下载来验证stage文件。 虽然这些步骤可以被跳过,但这些文件是为那些关心他们刚刚下载的文件合法性的用户提供的。

root #wget https://distfiles.gentoo.org/releases/
  • A .CONTENTS 文件包含stage压缩包内的所有文件的列表。
  • A .DIGESTS 文件,其中包含用不同的算法校验的stage文件。

使用 openssl,并且比较输出与 .DIGESTS 文件提供的校验和。

使用 openssl 验证 SHA512 校验值:

root #openssl dgst -r -sha512 stage3-mips-<release>-<init>.tar.xz

dgst instructs the openssl command to use the Message Digest sub-command, -r prints the digest output in coreutils format, and -sha512 selects the SHA512 digest.

使用 openssl 验证 BLAKE2B512 校验值:

root #openssl dgst -r -blake2b512 stage3-mips-<release>-<init>.tar.xz

将这些命令的输出与.DIGESTS 文件中的值进行对比。对应的值应该相同,否则下载的文件(或 digests 文件)可能已损坏。

使用sha512sum命令的另外一种方式:

root #sha256sum --check stage3-mips-<release>-<init>.tar.xz.sha256

The --check option instructs sha256sum to read a list of expected files and associated hashes, and then print an associated "OK" for each file that calculates correctly or a "FAILED" for files that do not.

就像在 ISO 文件中一样,它也可以来验证 tar.xz 文件的加密签名。使用 gpg 确保压缩包未被篡改:

For official Gentoo live images, the sec-keys/openpgp-keys-gentoo-release package provides PGP signing keys for automated releases. The keys must first be imported into the user's session in order to be used for verification:

root #gpg --import /usr/share/openpgp-keys/gentoo-release.asc

For all non-official live images which offer gpg and wget in the live environment, a bundle containing Gentoo keys can be fetched and imported:

root #wget -O - https://qa-reports.gentoo.org/output/service-keys.gpg | gpg --import

Verify the signature of the tarball and, optionally, associated checksum files:

root #gpg --verify stage3-mips-<release>-<init>.tar.xz.asc
root #gpg --verify stage3-mips-<release>-<init>.tar.xz.DIGEST
root #gpg --verify stage3-mips-<release>-<init>.tar.xz.sha256

If verification succeeds, "Good signature from" will be in the output of the previous command(s).

OpenPGP 密钥的指纹用来对释出的安装媒介签名,在 发行的安装媒介签名页面 上可以找到 OpenPGP 密钥的指纹。

安装 stage 文件

下载玩 stage 文件并且验证之后,可以使用 tar 提取 stage 文件:

root #tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

验证你在命令中使用了同样的参数 ( xpf--xattrs-include='*.*')。 x表示解开(Extract),v表示详细信息(Verbose)可以用来查看解压缩时发生了什么(可选参数), p 表示保留权限(Preserve permissions),还有f 表示我们要解开一个文件,而不是标准输入。最后,--numeric-owner 被用于确保从tarball中提取的文件的用户和组ID与Gentoo发布工程团队预期的保持一致,即使大胆的用户使用的不是 Gentoo live 环境。

  • x extract, instructs tar to extract the contents of the archive.
  • p preserve permissions.
  • v verbose output.
  • f file, provides tar with the name of the input archive.
  • --xattrs-include='*.*' Preserves extended attributes in all namespaces stored in the archive.
  • --numeric-owner Ensure that the user and group IDs of files being extracted from the tarball remain the same as Gentoo's release engineering team intended (even if adventurous users are not using official Gentoo live environments for the installation process).

现在stage文件已经解压好了,下面我们继续配置编译选项

配置编译选项

介绍

优化系统时,可以设置影响 Portage 的变量,Gentoo 官方支持包管理器。 所有这些变量可以设置为环境变量(使用export),但通过 export 设置不是永久的。

附注
从技术上来说,可以通过 shell 的 配置文件或 rc 文件来导出变量,但这不是基本系统管理的最佳实践。

Portage 在运行时会读取 make.conf 文件,将根据文件中保存的值更改运行时行为。make.conf 可以认为是 Portage 的主要配置文件,因此请谨慎处理其内容。

提示
所有可能的变量的注释列表可以在 /mnt/gentoo/usr/share/portage/config/make.conf.example中找到。额外的关于 make.conf 文档可以运行 man 5 make.conf 查找。

要成功安装 Gentoo,只需设置下面提到的变量。

启动编辑器(在本指南中,我们使用 nano)来更改我们将在下面讨论的优化变量。

root #nano /mnt/gentoo/etc/portage/make.conf

make.conf.example文件中可以明显看出文件的结构:注释行以 # 开头,其他行使用 VARIABLE="value" 语法定义变量。接下来选取其中的几个进行讨论。

CFLAGS 和 CXXFLAGS

CFLAGSCXXFLAGS 变量分别定义了GCC C和C ++编译器的优化标志。 尽管这些标志一般在这里默认被定义过,但为了性能最大化,需要分别优化每个程序的这些配置。 原因是因为每个程序都不同。 但是,这是不可管理的,因此这些标志在 make.conf 文件中定义。

应该在make.conf中定义优化标志,这将使系统的响应速度最快。 不要在此变量中放置实验性的设置; 太多的优化可能会使程序产生问题(崩溃,甚至更糟,产生故障)。

我们不会解释所有可能的优化选项。 要了解它们,请阅读GNU在线手册或 gcc 信息页面 (info gcc)。make.conf.example 文件本身也包含了很多例子和信息; 不要忘了读它。

第一个设置是标志 -march=-mtune= ,指定目标体系结构的名称。 可能用到的选项在make.conf.example文件中有描述(作为注释)。 一个常用的值是“native”,它告诉编译器选择当前系统体系结构(用户正在安装Gentoo时的系统)。

第二个是标志 -O(即大写的字母O,而不是数字零),它指定了gcc优化级别标志。 可能用到级别的是s(对于大小最优化),0(零 - 无优化),1,2或甚至3等更多的优化选项(每个级别具有与前面相同的标志,加上一些额外选项)。 -O2是建议的默认值。 -O3在整个系统范围内使用时会导致问题,因此我们建议您坚持使用-O2

另一个普遍使用的优化标记是-pipe(不同编译阶段通信使用管道而不是临时文件)。它对产生的代码没有任何影响,但是会使用更多的内存。在内存不多的系统里,gcc可能会被杀掉。如果是那样的话,就不要用这个标记。

使用 -fomit-frame-pointer(它将不在寄存器里为不需要帧指针的函数保存帧指针)可能会在调试程序的时候造成严重后果!

在你定义 CFLAGSCXXFLAGS的时候,你需要把这些优化标记都合并起来。stage3文件里包含的你解压缩出来的默认值已经足够好了。下面这个例子仅仅是个例子:

代码 CFLAGSCXXFLAGS 变量示例
# 为所有语言设置编译标志
COMMON_FLAGS="-mabi=32 -mips4 -pipe -O2"
# 为两个变量使用相同的设置
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
提示
通过 GCC 优化指导这篇文章获取有更多的信息,比如这些优化变量如何影响你的系统,Safe CFLAGS 也许是对初学者开始优化系统更实用的一篇文章

MAKEOPTS

通过使用 MAKEOPTS 可以定义在安装软件时,并行编译的数目。在 3.0.31 版本的 portage[1] 中,如果未定义该值, portage 默认的行为是,设置 MAKEOPTS 的值与 nproc 的返回线程数相同。

Further, as of Portage 3.0.53[2], if left undefined, Portage's default behavior is to set the MAKEOPTS load-average value to the same number of threads returned by nproc.

比较好的选择是从 CPU 线程数,或系统 RAM 总量除以 2 GiB 中选择是较小的那个值。

警告
大量的 job 显著消耗内存。建议每个 job 至少有 2 GiB RAM (所以,-j6 至少 需要 12 GiB)。避免内存溢出,根据可用内存降低 job 数量。
提示
当并行使用 emerge (--jobs),有效的 job 数量可以指数式加速(通过 emerge jobs 使 job 增加)。可以通过运行一个仅限于本地主机的 distcc 配置来解决这个问题,该配置将限制每个主机的编译器实例数量。
文件 /etc/portage/make.conf声明 MAKEOPTS 示例
# 如果未定义该值,portage 默认的行为是,设置 MAKEOPTS 的值与 `nproc` 的返回线程数相同。
MAKEOPTS="-j4"

man 5 make.conf 查找 MAKEOPTS 更多细节。

就位,预备,出发 !

根据你的喜好更新并保存 /mnt/gentoo/etc/portage/make.conf(nano 用户可以敲 Ctrl+o 可以保存更改,然后 Ctrl+x 退出)。

References