systemd -> openRC

Posted on GNU/LinuxGentoo

Recently I switched from systemd to openRC on my Gentoo laptop.

最近我把我践兔的笔记本高头的 systemd 换到了 openRC。


Contrast to what you might think, this article would not do a comparison between systemd and openRC. I switched purely for fun.

没得想到吧,这篇文章不搞 systemd 跟 openRC 的对比。我纯粹为了好玩。


First update the whole system, as it is a good practice before doing any invasive change.


emerge -av1uUD --with-bdeps=y world

Then switch to a non-systemd profile.

然后切到一个不是 systemd 的 profile。

eselect profile list
eselect profile set X

Change USE="elogind -systemd" in make.conf.

在 make.conf 里头,改个 USE="elogind -systemd"

I first tried to do the same as updating the system, but it still does not rid me of the systemd dependencies. So check now what packages still have a hard-dependency on systemd.

我先试到搞跟更新系统的时候一样的事情,但是它还是没得办法把我从 systemd 依赖里头解脱出来。 所以现在检查一下哪些包还对 systemd 有硬依赖的。

] equery d systemd
 * These packages depend on systemd:
app-crypt/p11-kit-0.23.22 (systemd ? sys-apps/systemd)
app-editors/emacs-27.2-r5 (systemd ? sys-apps/systemd)
app-i18n/fcitx5-5.0.1 (sys-apps/systemd)
dev-db/mariadb-10.5.10-r2 (systemd ? sys-apps/systemd)
dev-db/postgresql-13.3 (systemd ? sys-apps/systemd)
dev-lang/erlang-24.0.2 (systemd ? sys-apps/systemd)
dev-libs/libratbag-0.16 (systemd ? sys-apps/systemd)
dev-libs/weston-9.0.0-r1 (systemd ? >=sys-apps/systemd-209[pam])
dev-qt/qtcore-5.15.2-r3 (systemd ? sys-apps/systemd)
gnome-base/gnome-desktop-40.3 (systemd ? sys-apps/systemd)
kde-plasma/plasma-meta-5.22.5 (systemd ? sys-apps/systemd[pam])
media-sound/pulseaudio-13.0-r1 (systemd ? sys-apps/systemd:0[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_s390_32(-)?,abi_s390_64(-)?])
net-libs/webkit-gtk-2.32.4 (systemd ? sys-apps/systemd)
net-misc/modemmanager-1.16.8 (systemd ? >=sys-apps/systemd-209)
net-misc/networkmanager-1.32.4-r1 (systemd ? >=sys-apps/systemd-209:0)
net-print/cups-2.3.3_p2-r2 (systemd ? sys-apps/systemd)
net-wireless/bluez-5.61 (systemd ? sys-apps/systemd)
sys-apps/accountsservice-0.6.55-r1 (systemd ? >=sys-apps/systemd-186:0)
sys-apps/dbus-1.12.20-r3 (systemd ? sys-apps/systemd:0)
sys-apps/gentoo-systemd-integration-8 (>=sys-apps/systemd-207)
sys-apps/hwids-20210613-r1 (systemd ? sys-apps/systemd[hwdb])
sys-apps/smartmontools-7.2 (systemd ? sys-apps/systemd)
sys-apps/util-linux-2.37.2-r1 (systemd ? sys-apps/systemd)
sys-auth/pambase-20210201.1 (homed ? sys-apps/systemd[homed])
                            (systemd ? sys-apps/systemd[pam])
sys-auth/polkit-0.119-r2 (systemd ? sys-apps/systemd:0[policykit])
sys-auth/rtkit-0.13-r1 (systemd ? sys-apps/systemd)
sys-fs/lvm2-2.02.188-r2 (systemd ? >=sys-apps/systemd-205:0)
sys-fs/udisks-2.9.3 (systemd ? >=sys-apps/systemd-209)
sys-kernel/dracut-053-r1 (sys-apps/systemd[sysv-utils])
sys-process/procps-3.3.17-r1 (systemd ? sys-apps/systemd[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_s390_32(-)?,abi_s390_64(-)?])
virtual/libudev-232-r5 (systemd ? >=sys-apps/systemd-232:0/2[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_s390_32(-)?,abi_s390_64(-)?])
virtual/logger-0-r1 (>=sys-apps/systemd-38)
virtual/service-manager-1 (kernel_linux ? sys-apps/systemd)
virtual/tmpfiles-0-r1 (!prefix-guest ? sys-apps/systemd)
virtual/udev-217-r3 (>=sys-apps/systemd-217)
x11-base/xorg-server-1.20.13-r1 (systemd ? sys-apps/systemd)
x11-misc/sddm-0.18.1-r5 (systemd ? sys-apps/systemd)

It turns out that virtual/logger, virtual/service-manager, virtual/tmpfiles have dependencies on systemd, and they are not willing to switch to another provider. I had to pull them in manually. Here, I chose openrc for service-manager (obviously), systemd-tmpfiles for tmpfiles (only other sensible package to provide this), and syslog-ng for logger (this one has many choices).

看样子 virtual/loggervirtual/service-managervirtual/tmpfiles 有 systemd 的依赖,而且这些都不愿意切换到另一个 提供者的。我就得把这些手动拉进来了。在这块,我选了 openrc 来提供 service-manager(显然),systemd-tmpfiles 来提供 tmpfiles(唯一的别的提供这玩意儿的理智的包),然后是 syslog-ng 来提供 logger(这个就有蛮多选择的了)。

emerge -av1uUD --with-bdeps=y openrc systemd-tmpfiles sysvinit syslog-ng world

In the meantime, prepare other parts of the system for openRC. First backup the current kernel (bzImage, and initramfs), and check the kernel config to make sure we supported openRC.

与此同时,把系统的别的地方给 openRC 准备一下子。 首先备份一下当前的内核(bzImage、 跟 initramfs),然后检查一下内核配置,确保支持了 openRC。

Gentoo Linux  --->
  Support for init systems, system and service managers  --->
    [*] OpenRC, runit and other script based systems and managers

Bid farewell to systemd and express gratitude:

跟 systemd 讲再见,表达一下感谢:

] systemd-analyze
Startup finished in 6.575s (firmware) + 2.132s (loader) + 2.835s (kernel) + 2.130s (userspace) = 13.674s reached after 2.087s in userspace

Always good to have some root ttys and sessions:

有几个 root 的 tty 跟会话总是好的:

sudo su -

Install a busybox in case of misfortune.

装个 busybox 以防不测。

euse -E static -p sys-apps/busybox
euse -D pam -p sys-apps/busybox
emerge -av busybox

After the emerge finished, I was prompted to run emerge @preserved-rebuild so just ran it.

emerge 结束之后,它提示我要运行 emerge @preserved-rebuild,那就运行吧。

Update the initramfs to pickup any changes. This may not be needed; I ran it just to be safe.

更新 initramfs 来捡起来任何更改。这个可能不需要,为了保险起见我还是执行了。

genkernel --no-clean initramfs


# cat /etc/timezone
# echo "......." > /etc/timezone
# emerge --config sys-libs/timezone-data
# cat /etc/locale.gen
# eselect locale list
emerge -av app-admin/logrotate
# cat /etc/conf.d/hwclock
# cat /etc/conf.d/hostname
# cat /etc/hostname


rc-update add NetworkManager default

Display manager显示管理器

rc-update add display-manager default
nano -w /etc/conf.d/display-manager

keymaps (replacement for localectl)keymaps(localectl的替代)

nano -w /etc/conf.d/keymaps
rc-update add keymaps boot
# cat /etc/X11/xorg.conf.d/00-keyboard.conf


rc-update add lvm boot

tmpfs on /tmp (systemd auto-mount)在 /tmp 高头的 tmpfs(systemd 自动挂载的)

# nano -w /etc/fstab

tmpfs /tmp tmpfs rw,nosuid,noatime,nodev,size=4G,mode=1777 0 0

backlight (replacement for systemd-backlight)backlight(systemd-backlight 的替代)

eselect repository enable beatussum-overlay
emaint sync --repo beatussum-overlay
echo '*/*::beatussum-overlay' |sudo tee /etc/portage/package.mask/beatussum-overlay
echo 'sys-apps/save-backlight::beatussum-overlay' |sudo tee /etc/portage/package.unmask/save-backlight
emerge -av save-backlight
rc-update add save-backlight default


Note that the alsasound service only saves and loads mixer state. You will still be able to use sound without this service.

注意 alsasound 服务只是保存跟读取混音器的状态。就算不用这个服务,也可以用声音的。

rc-update add alsasound default
rc-update add alsasound nonetwork


rc-update add cronie boot

time sync (replacement for systemd-timesync)时间同步(systemd-timesync 的替代)

emerge -av ntp
rc-update add ntp-client default
rc-update add ntpd default


rc-update add ufw default


rc-update add bluetooth


# emerge -avuUD world
# reboot

But in fact after the reboot command it just hangs indefinitely. I ended up rebooting via sysrq.

但是实际上重启命令之后它就一直卡到那块了。我最后用 sysrq 重启的。

What's next?然后呢?

Nothing. What are you expecting?