Gentoo systemd migration
So…
… you have this old Gentoo machine that has been kept up to date, nurtured and pruned regularly but that still uses OpenRC? Yes, yes, start the flame wars now about how systemd is the root of all evil. Go ahead. I’ll wait.
All done? Got it out of your system? Okay. Let’s migrate a current Gentoo system from OpenRC to systemd!
Preparation
Get your system up to date first (emerge -avuDN @world), maybe use --getbinpkg if you’re so inclined
and want to speed things up a bit.
Make sure to read and follow up on all the items in eselect news read new in order to minimize
problems later on.
Take a backup. Seriously. Don’t skip this.
Switch profile
Now then. See which profile you’re currently using and switch to one of the systemd profiles.
# eselect profile list
Available profile symlink targets:
[1] default/linux/amd64/23.0 (stable) *
[2] default/linux/amd64/23.0/systemd (stable)
[3] default/linux/amd64/23.0/desktop (stable)
[4] default/linux/amd64/23.0/desktop/systemd (stable)
[5] default/linux/amd64/23.0/desktop/gnome (stable)
[6] default/linux/amd64/23.0/desktop/gnome/systemd (stable)
[7] default/linux/amd64/23.0/desktop/plasma (stable)
[8] default/linux/amd64/23.0/desktop/plasma/systemd (stable)
[9] default/linux/amd64/23.0/no-multilib (stable)
[10] default/linux/amd64/23.0/no-multilib/systemd (stable)
...
See which profile has the asterisk and change it to a matching systemd profile using
eselect profile set [n]. This updates the symlink in /etc/portage/make.profile and
makes sure the right USE flags get enabled.
Update (again)
Now the changed use flags need to take effect. For that, update again using
emerge -avuDN @world. This will rebuild all the packages that have had systemd support
disabled until now.
When emerge installs systemd itself, this already (if the sysv-utils USE flag is set)
updates a bunch of stuff that used to be managed by OpenRC. Using shutdown, reboot,
init and the like in this state will cause you pain. More on that below…
You might face a blocker about OpenRC and systemd. In that case just tell the system
you don’t really care about OpenRC that much by running emerge -av --deselect openrc.
This doesn’t remove OpenRC!
Kernel configuration
If you’re compiling your own kernel (why wouldn’t you…), you need to enable the option
Gentoo Linux -> Support for init systems, system and service managers -> systemd. This
makes sure you have everything you need in order to run systemd. Rebuild and install the
kernel. Don’t reboot yet…
If you’re using a distribution kernel, this should already be handled for you.
systemd configuration
Interaction with systemd is limited at the moment because it’s not yet managing your running system. There is a bunch of stuff, however, that you can do beforehand to make your first-boot experience nicer:
Use
systemd-machine-id-setupto create a unique ID for your machine.Use
systemctl preset-allto configure the system with a minimal default set of services.Enable your necessary services to start on boot by running
systemctl enable [service]. If you’re working on a remote machine, ssh might be a good idea for instance.Configure your network. If you’ve been using the OpenRC net.* scripts before, you need to switch to either NetworkManager or systemd-networkd. The latter can be configured by placing a file in
/etc/systemd/network/50-static.networkthat looks something like this:[Match] Name=[your network device name] [Network] Address=[your ip address] Gateway=[your default gateway] DNS=[your DNS server] Domains=[your DNS domain]
Reboot
This has actually mystified me and even now after having done this migration a couple of times, I’m not entirely sure how you’re supposed to handle this.
You’re in a pickle. The running system is managed by OpenRC but all the binaries and scripts have already been replaced by their systemd variants. If you try to reboot as usual, systemd will yell at you because it’s not managing the system yet. But I also haven’t found a nice way to talk to OpenRC in this state.
So, I just ran sync a couple of times to write everything out to disk that hasn’t yet
been and initiated a reboot from outside, either via ACPI events, pressing the power
button on the machine or rebooting the VM.
Not great, not terrible.
Deal with the fallout and clean up
This migration now works rather painlessly and your system should come up fine. If there’s anything not working or missing, your first step should be the Gentoo wiki article on systemd.
After everything is working to your satisfaction, you should clean up and remove all
now unneeded packages by running emerge -av --depclean @world.
Beyond
Now you get to enjoy your new systemd based machine. You could for instance see whether you still need syslog-ng or whether journal does all you need.
You could also convert your cron jobs to systemd timers. While a lot more verbose to write, I feel especially inspecting their state and analyzing failures is a lot nicer.
Again, have a look at the Gentoo wiki article on systemd for a lot more detail.