OpenRC
OpenRC is an init system for operating systems such as GNU/Linux, GNU/Hurd and Unix. It is a POSIX-compatible alternative solution to the problematic systemd software-suite. OpenRC was created by the Gentoo GNU/Linux development team. Its purpose is to enable, disable and/or manage the services of the operating system.
OpenRC emerged at the end of 2007, 1) when Roy Marples retired as a Gentoo GNU/Linux developer. However, he wanted to keep the baselayout-2 project as an independent project. The Gentoo Project Board has allowed it to continue being maintained as an external project, once the project name was modified to OpenRC with the two-clause BSD license.
In 2010, OpenRC was transferred back to the development of Gentoo GNU/Linux, after Roy Marples decided that he would not keep his project. William Hubbs and several other developers took over OpenRC from this point, with 0.8.x being the first release made by the new team. In 2011, OpenRC returned to the stable Gentoo GNU/Linux tree.
In 2013, the OpenRC team became independent from Gentoo GNU/Linux again and changed the primary development to GitHub.
Features
OpenRC provides a number of interesting features:
- Compatible with UNIX philosophy
- Portable to non-GNU/Linux systems
- Cgroups (control groups) support
- Parallel service initialization
- Dependency-based initialization
- Automatic dependency calculation
- Enables per-service resource limiting and unlimiting
- Sections of split configurations: init.d and conf.d
- Well-explained and self-explanatory configuration files
- Startup scripts are extensible and customizable
- Designed to be 100% compatible with virtualization environments
- Modular architecture suitable and separate optional components: cron, syslog, etc.
- Expressive and flexible network handling (including VPN, bridges, etc.)
- Verbose mode to debug service activity
Runlevels
OpenRC, as well as sysvinit and init (BSD), has a concept of task execution levels (i.e., runlevels). To define them in the conventional way, OpenRC uses names instead of numbers. This allows, for example, to have a default runlevel with “everything” enabled with a “powersaving” runlevel where some services are disabled.
The rc-status helper command will print all currently active runlevels and the state of services in them:
# rc-status * Caching service dependencies ... [ ok ] Runlevel: default modules [ started ] lvm [ started ]
All runlevels are represented as folders in /etc/runlevels/ with symbolic links to the actual service scripts.
Calling openrc
with an argument (e.g., openrc default) will switch to that runlevel; this will start and stop services as needed.
Managing runlevels is usually done through the rc-update helper, but it could of course be done by hand if desired. For example, to add nginx to the default
runlevel (with the need of root privileges): rc-update add nginx default
rc-update
will not start nginx! You would still have to trigger rc, run the service script by hand, or start it with rc-service nginx start
.
The default startup uses the runlevels sysinit, boot, and default, in that order. Shutdown uses the shutdown runlevel. The defined runlevel nonetwork is used only for non-network services.
Groups
Users have to be manually added to some groups in order to be able to access the corresponding devices. One problem is that you would not have any sound on your computer if you did not make sure that your user is in the audio group, like so:
# passwd -a <your-user> audio
Same as above for video: your games and other graphics output might be slow or lack acceleration without the below:
# passwd -a <your-user> video
For networking:
# passwd -a <your-user> network
For webcam:
# passwd -a <your-user> optical
Also for storage:
# passwd -a <your-user> storage
# passwd -a <your-user> disk
And for CUPS:
# passwd -a <your-user> sys
Migration
Configuration
Services often required
Here with OpenRC, you might need to add services to support lvm2, etc.
Here is the procedure for lvm2:
# rc-update add lvm boot
For cryptsetup:
# rc-update add dmcrypt boot
For alsa-utils:
# rc-update add alsasound default
For cronie:
# rc-update add cronie default
On each package containing an OpenRC service, you will have this message:
==> rc 'rc-update add ... default'
Boot logs
Open the configuration file /etc/rc.conf, and uncomment the reference line rc_logger=“YES”.
The log files for the entire rc process will be stored in /var/log/rc.log.
Hostname
OpenRC has its configuration files under the directory /etc/conf.d/.
In order to set your hostname, edit /etc/conf.d/hostname:
# nano /etc/conf.d/hostname
And redefine localhost with the name that you want. (Ideally, do not simply leave it as “localhost”.)
# Set to the hostname of this machine hostname="localhost"
Keyboard and Keymap
To modify the key map for use in the console: edit the file /etc/conf.d/consolefont
. See the full list of all the options available under /usr/share/kbd/keymaps/
. The below setting is just one example for US-English keyboard maps.
keymap="us"
To configure the keyboard for use with a graphical interface, edit the file /etc/conf.d/keymaps
. Again, the full list of options is available under /usr/share/kbd/keymaps/
. The following example is for US-English keyboard maps:
keymap="us"
After editing the files, run the command:
# rc-service keymaps restart
Network settings
You need to enable the daemon dhcpcd at runlevel default:
# rc-update add dhcpcd default
Login manager
xorg-xdm
To enable the login manager, edit /etc/conf.d/xdm.
If that file does not already exist, then first make sure to install the package xorg-xdm:
pacman -S xorg-xdm
As an example, to use slim as the graphical login manager (with the precondition to install the package slim), replace with the line:
DISPLAYMANAGER="slim"
In order for changes to take effect, make sure to enable the xdm daemon, like so:
# rc-update add xdm default
slim
The alternative would be to use slim direct. So first make sure to install the package slim:
pacman -S slim
You can add the service direct at the corresponding runlevel:
# rc-update add slim default
Kernel modules
For the automatic loading of any module of the Kernel Linux-Libre edit the file /etc/conf.d/modules.
modules="module_name"
This is only necessary after installation of an application or driver, made by the system administrator, by default all native modules of Kernel Linux-Libre are loaded automatically.
Adaptation between systemctl and rc-update
Add or delete a service
You can add a service using this way:
# rc-update add <service> <runlevel>
You also can delete a service as follows:
# rc-update del <service> <runlevel>
Services currently running
In order to have a summary of all the services running, stopped etc, you can run this command:
# rc-status --all -v
Stop / Start / Restart a service
To restart a service, you need to use rc-service:
# rc-service <service> restart
Troubleshooting
Consistent network device naming is not disabled
To disable consistent network device naming, disable the assignment of fixed names, so that the unpredictable kernel names are used again, by masking udev's rule file for the default policy. This “masking” can be done by making a symbolic link to /dev/null. As root, issue a command as follows:
# ln -s /dev/null /lib/udev/rules.d/80-net-name-slot.rules
Sysctl.conf is missing
You can encounter an issue if /etc/sysctl.conf is missing. To fix this, you need to create the file:
# touch /etc/sysctl.conf
/usr/libexec/rc/cache doesn't exist
If you have this error when you shutdown the computer:
WARNING: /usr/libexec/rc/cache is not writable!
The solution is to create the folder:
# mkdir /usr/libexec/rc/cache
Swap isn't enabled
You need to manually add the swap partition in /etc/fstab as follows:
# /dev/sda2 UUID=0c3e9434-bc5c-461c-a5e4-4e9fe5f9a149 swap swap sw 0 0
tmpfs isn't present
Add it in /etc/fstab:
tmpfs /tmp tmpfs nodev,nosuid 0 0
The system can't shutdown correctly
Please add your user to the group power:
# passwd -a <your-user> power
Afterwards you should be able to use the command as follows:
doas poweroff