跳转至内容

OpenRC

来自 ArchWiki
警告 Arch Linux 仅官方支持 systemd[1] 在提交支持请求时,如果使用了 OpenRC,请予以说明。

OpenRC 是由 Gentoo 开发者维护的服务管理器。OpenRC 基于依赖关系,并与系统提供的 init 程序(通常是 SysVinit)配合工作。

安装

有关 init 组件的详细信息,请参阅 Init

安装 openrcAUR 软件包。

从 0.25 版本开始,OpenRC 在 /usr/bin/openrc-init 提供了自己的 init。可选地,您可以使用其他 init,例如来自 busybox 的。请注意,当使用 openrc-init 时,必须配合使用 openrc-shutdown,而不能使用其他软件包中的 shutdownreboot 命令,否则会遇到错误。

基础的服务文件集可以通过 openrc-arch-services-gitAUR 软件包获得。其他软件包可能会在外部提供服务文件;建议在 AUR 中进行搜索。

为了与历史 init 脚本保持兼容,配置文件被安装在 /etc/openrc/ 目录下。

引导

若要使用 OpenRC 启动,请在 内核参数 中设置 init 选项。

要使用 OpenRC 内置的 init,请设置 init=/usr/bin/openrc-init

请注意,使用 openrc-init 时,/etc/inittab 文件不会被使用。

配置

/etc/openrc/conf.d 目录和 /etc/openrc/rc.d 文件用于配置。

有关配置 OpenRC 的通用信息,请参阅

有关从 systemd 迁移的说明,请参阅 Init#Configuration

服务

以 root 身份执行 rc-update add 服务名称 运行级别 即可启用 OpenRC 服务。建议至少启用以下服务:

服务名称 运行级别 描述
udev sysinit 设备热插拔
alsa default ALSA 状态
acpid default ACPI 事件
dbus default 消息总线
dcron default 调度
syslog-ng default 系统日志
警告 如果在内核参数中使用 init=/usr/bin/openrc-init,您需要手动启用 getty 服务,否则您将没有交互式 TTY,正如文档中所述。

如有必要,可以通过创建指向 /etc/openrc/init.d/getty 的符号链接,为每个需要的 getty 创建服务。例如,针对 /dev/tty1

# ln -s /etc/openrc/init.d/agetty{,.tty1}
# rc-update add agetty.tty1 default

本文或本节是迁移到 Init#Configuration 的候选内容。

注: 不仅适用于 OpenRC(在 Talk:OpenRC 中讨论)

为了防止 PAM 在登录 TTY 后尝试向 systemd 注册(这有时会引起问题),可以安全地删除或注释掉 /etc/pam.d/system-auth 中提及 systemd 的行。

另请参阅 Gentoo:Systemd#Native services

网络

网络通过 newnet 配置 [2]。修改 /etc/openrc/conf.d/network 文件;同时支持 ip (iproute2) 和 ifconfig (net-tools) 命令。以下是使用 ip 的配置示例。

ip_eth0="192.168.1.2/24"
defaultiproute="via 192.168.1.1"
ifup_eth0="ip link set \$int mtu 1500"

网络服务默认添加到启动运行级别中,因此无需进一步操作。通用网络信息请参阅 网络配置

您也可以通过启用相应的服务来使用 NetworkManagerdhcpcd

启动日志

要启用启动日志,请取消 /etc/openrc/rc.confrc_logger="YES" 行的注释。启用后,启动日志将存储在 /var/log/rc.log 中。

主机名

OpenRC 从 /etc/openrc/conf.d/hostname 设置主机名。文件内容如下:

# Set to the hostname of this machine
hostname="myhostname"

内核模块

OpenRC 使用 /etc/openrc/conf.d/modules 而非 /etc/modules-load.d。例如:

/etc/openrc/conf.d/modules
# You should consult your kernel documentation and configuration
# for a list of modules and their options.

modules="vboxdrv acpi_cpufreq"

区域设置

键盘布局可以通过 /etc/openrc/conf.d/keymaps/etc/openrc/conf.d/consolefont 进行配置。您也可以通过 /etc/locale.conf 文件配置设置,该文件由 /etc/profile.d/locale.sh 调用。

详见 Gentoo:Localization/Guide#Keyboard layout for the consoleLocale

用法

本节对比了 systemd 与其他 init 系统。

您可以省略 .service.target 扩展名,尤其是在临时编辑 内核参数 时。

systemd SysVinit OpenRC 描述
systemctl list-units rc.d list rc-status 列出正在运行的服务状态
systemctl --failed rc-status --crashed 检查失败的服务
systemctl --all rc-update -v show 显示所有可用服务。
systemctl (start, stop, restart, status) daemon.service rc.d (start, stop, restart) daemon rc-service daemon (start, stop, restart, status) 更改服务状态。
systemctl (enable, disable) daemon.service chkconfig daemon (on, off) rc-update (add, del) daemon 开启或关闭服务。
systemctl daemon-reload chkconfig daemon --add 创建或修改配置。

技巧与提示

静默启动

要隐藏 OpenRC 的启动消息,您可以编辑 /etc/inittab 并在每个 openrc 命令中添加 --quiet。更多信息请检查 $ openrc -h

故障排除

卸载 /tmp 时出错

在关闭系统时,您可能会收到类似这样的错误消息:

* Unmounting /tmp ... 
* in use but fuser finds nothing [ !! ]

可以通过将以下内容添加到/etc/environment并重启来修复此问题:

no_umounts="/tmp"

/etc/openrc/conf.d/localmount

这个问题仅在您的 tmp 被挂载为 tmpfs 时才会出现。

禁用 IPv6 无效

一种方案是添加

# Disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1

/etc/openrc/sysctl.d 目录下以 .conf 为扩展名的文件中

关机期间将根目录重新挂载为只读失败

如果发生上述情况,请编辑 /etc/openrc/init.d/mount-ro 文件并放入

telinit u

在以下行之后

# Flush all pending disk writes now
sync; sync

未找到 /etc/sysctl.conf

默认情况下,调用 sysctl --system 来加载 sysctl 配置。[3] 这包括 /etc/sysctl.conf 文件,但该文件已从 Arch 中移除。[4]

为了防止文件缺失错误,请创建该文件:

# touch /etc/sysctl.conf

opentmpfiles-setup 启动失败

在启动 openrc 时,您可能会看到类似这些行:

* Setting up tmpfiles.d entries ...
chattr: Operation not supported while setting flags on /var/log/journal
chattr: No such file or directory while trying to stat /var/log/journal/%m
chattr: Operation not supported while setting flags on /var/log/journal/remote
[ !! ]
ERROR: opentmpfiles-setup failed to start

这是由于 /usr/lib/tmpfiles.d/journal-nocow.conf 使用了仅在 journal 位于 btrfs 文件系统上时才有效的选项。

详见 https://github.com/OpenRC/opentmpfiles/issues/2

一种解决方法是创建一个空的 /etc/tmpfiles.d/journal-nocow.conf 来覆盖这些设置。

还原至 systemd

在大多数情况下,还原至 systemd 应该很直接。它本质上是迁移到 OpenRC 的逆过程,请注意以下几点:

  • 移除或编辑内核命令行中的 init= 参数
  • 将任何为 OpenRC 定制或非 systemd 的软件包替换为官方标准版本

参见

© . This site is unofficial and not affiliated with Arch Linux.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.