手册:IA64/安装/安装基本系统

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


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, 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

DOS/Legacy BIOS systems

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

root #mount

配置 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/ia64/ *
  [2]   default/linux/ia64//desktop
  [3]   default/linux/ia64//desktop/gnome
  [4]   default/linux/ia64//desktop/kde
附注
命令的这个输出只是一个示例,并会随时间演变。
附注
若要使用 systemd, 请选择名称中包含 "systemd" 的配置文件。否则,选择相反的配置文件。

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

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

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

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 (ia64 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 指南。