OpenRC
OpenRC 是由 Gentoo 开发者维护的服务管理器。 OpenRC 基于依赖关系,并与系统提供的 init 程序(通常是 SysVinit)协同工作。
安装
关于 init 组件的详细信息,请参阅 Init。
从 0.25 版本开始,OpenRC 在 /usr/bin/openrc-init
提供了自己的 init。 可选地,您可以使用来自其他软件包的 init,例如 busybox。 请注意,当使用 openrc-init
时,它必须与 openrc-shutdown
配对使用,而不是来自其他软件包的 shutdown
或 reboot
命令,否则您将遇到错误。
一组基本的服务文件可从 openrc-arch-services-gitAUR 软件包获得。 其他软件包可能在此软件包之外提供服务文件;建议在 AUR 上搜索。
为了保持与 initscripts-forkAUR 的兼容性,配置文件安装到 /etc/openrc/
。
启动
要使用 OpenRC 启动,请在内核参数中设置 init
选项。
要使用 OpenRC 的内置 init,请设置 init=/usr/bin/openrc-init
。 要使用 SysVinit,请设置 init=/usr/bin/init-openrc
。
请注意,当使用 openrc-init
时,不会使用 /etc/inittab
文件。
配置
/etc/openrc/conf.d
目录和 /etc/openrc/rc.conf
文件用于配置。
有关配置 OpenRC 的一般信息,请参阅
有关从 systemd 迁移的说明,请参阅 Init#Configuration。
服务
OpenRC 服务通过以 root 身份执行 rc-update add service_name runlevel
来启用。 建议至少启用以下服务
服务名称 | 运行级别 | 描述 |
---|---|---|
udev | sysinit | 设备热插拔 |
alsa | default | ALSA 状态 |
acpid | default | ACPI 事件 |
dbus | default | 消息总线 |
dcron | default | 计划任务 |
syslog-ng | default | 系统日志 |
如有必要,通过创建指向 /etc/openrc/init.d/getty
的符号链接,为每个需要的 getty 创建服务。 例如,对于 /dev/tty1
# ln -s /etc/openrc/init.d/agetty{,.tty1} # rc-update add agetty.tty1 default
为了防止 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"
网络服务默认添加到启动运行级别,因此无需进一步操作。 有关常规网络信息,请参阅 网络配置。
启动日志
要启用启动日志记录,请取消注释 /etc/openrc/rc.conf
中的 rc_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 console 和 Locale。
用法
您可以省略 .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 [ !! ]
可以通过添加以下内容来修复此问题
no_umounts="/tmp"
到 /etc/openrc/conf.d/localmount
禁用 IPv6 无效
一种选择是添加
# Disable ipv6 net.ipv6.conf.all.disable_ipv6 = 1
在 /etc/openrc/sysctl.d
下的带有 .conf
扩展名的文件中
关机期间重新挂载 root 为只读失败
如果发生上述情况,请编辑 /etc/openrc/init.d/mount-ro
文件并将
telinit u
放在以下行之后
# Flush all pending disk writes now sync; sync
找不到 /etc/sysctl.conf
默认情况下,调用 sysctl --system
以加载 sysctl 配置。 [3] 这包括从 Arch 中删除的 /etc/sysctl.conf
文件。 [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 软件包