In a recent article covering the use of cinit to implement a parallel boot process, I managed to turn a booting time of 2 minutes 54 seconds into 2 minutes 3 seconds -- a massive saving of 51 seconds. By converting the same Linux machine to runit, I was able to reduce booting time to 55 seconds. And as for ease of use, it took me two days of work to convert to using cinit, and only one hour to do the same with runit.
Moving from init to runit
Of course, runit's precise ease of use depends on the distro you're using. You'll find it either easy or very easy. If you use Debian then you just need to install the runit, runit-services, and runit-run packages. Even easier, just add the following line to /etc/apt/sources.list:
deb http://ftp.us.debian.org/debian unstable main non-free contrib
sudo apt-get update sudo apt-get install runit runit-services runit-run
Debian will handle all of the conversion from using init to using runit for you. However -- don't reboot yet! Before you do that you're going to have to tell the kernel to use runit instead of init. Edit /boot/grub/menu.lst, find the line that loads your Linux kernel, and make an addition to its end. For instance, on my system, I changed
kernel /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro
kernel /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro init=/sbin/runit-init
Now you can reboot and use runit for the first time by typing:
sudo runit-init 6
Not using Debian?
If you're not using Debian then you'll have to do a bit more work, but not much. Follow the instructions in the runit installation Web page, then move on to runit - replacing init. Once you have replaced init, make sure that you don't reboot until you've told LILO or GRUB that you're using runit now. If do reboot without having done that then you'll end up with a dead Linux box, and it'll be time to find your old installation disks.
When you reboot you'll be pleasantly surprised at how quickly the system comes back up, because you've only got a minimal system at the moment -- just the bare basics so that you can access your Linux box. You will want to start adding services to get your machine running exactly as you want. This is where it starts to get difficult. No, only joking -- this is where it remains really easy. If you're using the Debian installation then you've already got some key services waiting for you to start. Have a look in the /etc/sv directory:
$ ls -l /etc/sv total 68 drwxr-xr-x 3 root root 4096 2006-04-24 16:15 apache drwxr-xr-x 2 root root 4096 2006-04-24 16:15 cron drwxr-xr-x 3 root root 4096 2006-04-24 16:15 dhclient drwxr-xr-x 3 root root 4096 2006-04-24 16:15 dhcp drwxr-xr-x 3 root root 4096 2006-04-24 16:15 exim drwxr-xr-x 2 root root 4096 2006-04-24 16:15 gdm drwxr-xr-x 2 root root 4096 2006-04-24 16:18 getty-1 drwxr-xr-x 2 root root 4096 2006-04-24 16:18 getty-2 drwxr-xr-x 2 root root 4096 2006-04-24 16:18 getty-3 drwxr-xr-x 2 root root 4096 2006-04-24 16:18 getty-4 drwxr-xr-x 2 root root 4096 2006-04-24 16:15 getty-5 drwxr-xr-x 3 root root 4096 2006-04-24 16:15 nfs-kernel-server drwxr-xr-x 3 root root 4096 2006-04-24 16:15 portmap drwxr-xr-x 2 root root 4096 2006-04-24 16:15 postfix lrwxrwxrwx 1 root root 36 2006-04-24 16:15 README -> /usr/share/doc/runit-services/README drwxr-xr-x 2 root root 4096 2006-04-24 16:15 squid drwxr-xr-x 3 root root 4096 1999-10-20 01:12 ssh drwxr-xr-x 2 root root 4096 2006-04-24 16:15 xdm
This directory contains one sub-directory for every service that is available, though not necessarily being used. To see the services that are actually being used, look in the directory /var/service:
$ ls -l /var/service/ total 0 lrwxrwxrwx 1 root root 15 2006-04-24 16:18 getty-1 -> /etc/sv/getty-1 lrwxrwxrwx 1 root root 15 2006-04-24 16:18 getty-2 -> /etc/sv/getty-2 lrwxrwxrwx 1 root root 15 2006-04-24 16:18 getty-3 -> /etc/sv/getty-3 lrwxrwxrwx 1 root root 15 2006-04-24 16:18 getty-4 -> /etc/sv/getty-4 lrwxrwxrwx 1 root root 15 2006-04-24 16:18 getty-5 -> /etc/sv/getty-5
If you want (for example) to start using SSH, you just need to add a link from /etc/sv/ssh to /var/service, as in:
sudo ln -s /etc/sv/ssh /var/service
Here's where you're can see that runit gives you full service supervision. There's no rebooting or manual starting of the service needed -- as soon as you add the link, runit starts the new service.
Adding a brand new service
Adding a new service is almost as easy. First of all you'll need a directory for it in /etc/sv. In that new directory you'll need an executable called
run which should contain the instructions for starting the service. Finally, you will have to create a link from /var/service to your new service directory. And that's all there is to it. As a matter of interest, the runit Web site contains a whole host of example run scripts.
You may be surprised to learn that the addition of extra services has no real effect on the booting time. This is because the services are started in parallel.
We've seen that rebooting is a thing of the past with runit, but you may want to shut your Linux box down at some point. For this you'll need the command
Try not to blink or you'll miss the box shutting down -- it really is that fast.