Gentoo with runit

MATE desktop environment running on the Gentoo runit install
I have been using Gentoo Linux for the last 13 years but I do like to try other distros whether on virtual machines or on bare metal, and whenever a distro has something interesting to offer, the thought that always comes to my mind is: "I can do this on gentoo but better".
Void Linux is one of those distros. Its biggest selling point is the fact that it uses runit as its init system and service supervisor, and runit is such a fantastic tool, it's fast, simple, and easy to use.
So I decided to try it on Gentoo. I would first try it on a virtual machine, and if it succeeded, I would move it to bare metal. I do my Gentoo installs using a live environment so I have access to a terminal, a file manager, and a web browser, and because I was going to type lots of commands and use some of my config files, it's handy to have a shared clipboard between virtual machine and host.
With that done, I started by creating the filesystems (went with ext4), downloading and extracting the Gentoo Linux stage 3 (I went with the stage3-amd64-openrc), and chrooting into it.
Once inside, I followed the normal steps for a Gentoo Linux installation and it was now time to install runit, from version 2.3.1 on, there's a system-init use flag that enables runit as the system service manager on the virtual/service-manager package, allowing me to remove openrc and sysvinit later on, making runit the default
~ # echo 'sys-process/runit ~amd64' > /etc/portage/package.accept_keywords/runit ~ # echo 'sys-process/runit scripts system-init' > /etc/portage/package.use/runit ~ # emerge --ask sys-process/runit
So runit created a /etc/runit/ directory a /etc/sv/ for the available services and a /etc/service/ to enable them instead of /var/service like on Void Linux. 
Alex Efros has a gentoo overlay with runit services and scripts, I looked into them and they work by editing the 1 and 3 scripts inside /etc/runit, but I wanted to try a modular approach without touching any of the files that the runit package installed. 
Looking inside /etc/runit scripts 1 and 3 source rc.sh and call run_rc_stage function with their stage number, whilst rc.sh loops through /etc/runit/rc directory and sources any file that matches the pattern (stage number).*.sh .
With this I could drop my own scripts into /etc/runit/rc and use a numbering system to control the execution order. So I wrote the boot scripts starting with 1, where 1.00-pseudofs.sh mounts /proc /sys and /dev, 1.01-udev.sh to start udev and 1.02-filesystems.sh etc.. and to shutdown 3.00-umount.sh.
I could now uninstall openrc and sysvinit and added init=/sbin/runit-init as a boot parameter and finally reboot into it.
It booted really quick but when I tried to login as a user I got
Terminal error shown after attempting to log in on tty1





At first I thought I was missing a service or maybe something missing on the boot scripts, but looking into it, this turned out to be a known runit quirk: runsv execs run scripts without giving them their own session and process group, which agetty needs in order to take proper control of the tty. Wrapping the call in chpst -P puts agetty into a new process group before it runs, which is what let it actually manage the terminal and let me log in. So to login on tty1 I had to edit /etc/sv/getty-tty1/run with:

exec chpst -P /sbin/agetty 38400 tty1 linux
and so on to the remaining ttys. I was now able to login.
To finish the task I decided to install a desktop environment, but first I needed to write some services to enable them, NetworkManager, dbus and elogind for a bare minimum functional desktop environment, I used Void Linux services as a reference, you really can't reinvent the wheel here. Finally I installed MATE desktop environment and everything seemed to be in good working order.
MATE desktop environment running on the Gentoo runit install


My original plan was to create a stage3 tar from this and move it to bare metal and maybe even share it, but I decided instead to create a Gentoo Linux runit overlay and do a fresh install on bare metal using the overlay.
It has been evolving ever since, I have been adding more services and adapting the scripts, for those interested here:

Comments

Popular Posts