[HowTo] OpenRC as PID1 (init)

Share your own howto's etc. Not for support questions!

[HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2017-10-08 12:14

Warning: this method may break your system so please *do not* use this on any "mission critical" boxen.

For those who dislike bloat, OpenRC is an init system that offers a greatly simplified solution compared to systemd or sysvinit (specifically, sysv-rc) with a much smaller codebase and consequently increased security, stability and reliability.

From the package page:
OpenRC is a dependency based service manager. It provides support for System V init, for booting, changing runlevels, starting and stopping services, and shutting down.

Originally written as a Gentoo project, OpenRC aims at being platform-agnostic. It works equally well on Linux, BSD and Hurd. It supports the traditional init system in Debian in addition to many alternatives. OpenRC is implemented in C in a small, simple and efficient way, making it easy to understand, extend and reuse.

It is already possible to use OpenRC in BunsenLabs in conjunction with sysvinit by installing the systemd-shim and sysvinit-core packages along with the stock jessie (or stretch) openrc package.

However, the latest versions of OpenRC now include the openrc-init binary that can be used as a drop-in replacement for /sbin/init

The advantages of this are that it allows systemd to remain in place so it can be used as a backup PID1 in case anything goes wrong [1] and also that it does not require the un-maintained systemd-shim package.

To take advantage of this method, first install sysvinit (we need some of the installed scripts for OpenRC):
Code: Select all
sudo aptitude install sysvinit-core


Once the OpenRC package is installed (see below for details), the default init can be switched back to systemd so we can use that as a backup:
Code: Select all
sudo aptitude install systemd-sysv


For OpenRC itself, I have backported this version to Debian jessie & stretch:

https://download.opensuse.org/repositories/home:/Head_on_a_Stick:/Helium/Debian_8.0/

https://download.opensuse.org/repositories/home:/Head_on_a_Stick:/Helium/Debian_9.0/

Navigate to the amd64 (for 64-bit systems) or i386 (32-bit) folder, download the openrc .deb file and install the package with gdebi.

To use openrc-init instead of sysvinit, add this kernel commandline parameter:
Code: Select all
init=/sbin/openrc-init

In Debian this can be done by adding the parameter inside the quotation marks on the GRUB_CMDLINE, erm, line in /etc/default/grub then update the GRUB configuration with:
Code: Select all
# update-grub

However, this will break any multi-boot systems so in that case please use /etc/grub.d/40_custom instead to add the parameter to Debian alone.

Upon a reboot, test with:
Code: Select all
empty@testbed:~ $ cat /proc/1/comm
openrc-init
empty@testbed:~ $

A usage guide can be found at /usr/share/doc/openrc/guide.md.gz

The Gentoo Wiki also has some tips:

https://wiki.gentoo.org/wiki/OpenRC

To reboot under pure OpenRC, use:
Code: Select all
sudo openrc reboot

To poweroff, run:
Code: Select all
sudo /sbin/openrc-shutdown --poweroff

Other options are available for `openrc-shutdown`, see "--help" for details.

[1] boot with systemd again by pressing "e" with the Debian GRUB menu entry highlighted and simply delete the extra init=/sbin/openrc-init parameter and press <Ctrl>+x (at the same time) to boot the modified entry; remeber to modify grub.cfg to make this permanent if needed.
Last edited by Head_on_a_Stick on 2017-10-16 05:40, edited 2 times in total.
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby oswaldkelso » 2017-10-08 21:10

Damn you HOAS, now I'll have to reply to your other post before I post on this one! :mrgreen:
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
User avatar
oswaldkelso
 
Posts: 1136
Joined: 2005-07-26 23:20
Location: UK

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2017-10-10 17:36

^ :mrgreen:

I have discovered that OpenRC can be used without the systemd-shim so I have changed the guide somewhat, check the OP for details.

Also, the stock configuration only allows for a single TTY (console) screen, which I find somewhat limiting.

To generate more, copy this file to /etc/init.d/agetty:
Code: Select all
#!/sbin/openrc-run
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

description="start agetty on a terminal line"
supervisor=supervise-daemon
port="${RC_SVCNAME#*.}"
term_type="${term_type:-linux}"
command=/sbin/agetty
command_args_foreground="${agetty_options} ${port} ${baud} ${termtype}"
pidfile="/run/${RC_SVCNAME}.pid"

depend() {
   after local
}

start_pre() {
   if [ -z "$port" ]; then
      eerror "${RC_SVCNAME} cannot be started directly. You must create"
      eerror "symbolic links to it for the ports you want to start"
      eerror "agetty on and add those to the appropriate runlevels."
      return 1
   fi
}

Then symlink that to other agetty.$port files where $port is replaced with the console number (for example tty2), like this:
Code: Select all
cd /etc/init.d
sudo ln -s agetty agetty.tty2 # add others as required

A configuration file is also useful:
Code: Select all
sudo mkdir -p /etc/conf.d

Then create a file at /etc/conf.d/agetty with this content:
Code: Select all
# Set the baud rate of the terminal line
#baud=""

# set the terminal type
#termtype="linux"

# extra options to pass to agetty for this port
#agetty_options=""

This file can then be symlinked for the other TTYs:
Code: Select all
cd /etc/conf.d
ln -s agetty agetty.tty # etc

Finally, add the extra TTYs to the default runlevel:
Code: Select all
sudo rc-update add agetty.tty2

This will be started on a reboot or start it immediately with:
Code: Select all
sudo rc-service agetty.tty2 start
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2017-10-10 17:41

It may also be worth noting that OpenRC's native process supervision can be replaced with either runit or skarnet.org's small and secure supervision software suite (better known as s6) for an even more minimal setup.

See the guides in /usr/share/doc/openrc for more on this.
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby oswaldkelso » 2017-10-10 19:46

HOAS.

I'm a fan of runit and it has been great on my old D2 installs but Dragora3 is switching to sinit and perp.

If your only using runit for supervision then you may like to tale a look at perp.

http://b0llix.net/perp/
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
User avatar
oswaldkelso
 
Posts: 1136
Joined: 2005-07-26 23:20
Location: UK

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2017-10-10 19:48

oswaldkelso wrote:http://b0llix.net/perp/

Fascinating — thanks!
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2017-10-16 05:44

I have changed the guide slightly (because it was wrong), we now install sysvinit-core first to steal some of the init scripts, check the OP for details.

Any Debian jessie users may find that they also need a newer version of the init-system-helpers package:

https://download.opensuse.org/repositor ... ebian_8.0/

The OBS is still down for maintenance at the moment, I will update the link later.
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby praka123 » 2018-09-05 15:22

Is it still possible to use a Debian Stretch or testing distro installed from minimal packages to use OpenRC/runit or SysVinit? I know, it will be breaking Gnome 3, which seems to be tied to systemd. I'm hoping Cinnamon can be installable?
Debian (Testing/Unstable)
User avatar
praka123
 
Posts: 187
Joined: 2007-06-23 08:11
Location: Cochin,India

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2018-09-05 15:50

praka123 wrote:Is it still possible to use a Debian Stretch or testing distro installed from minimal packages to use OpenRC/runit or SysVinit?

Yes, there is no reason why it would not still work, the package versions are the same as when I tried it (with openbox, bspwm & dwm, IIRC).

Please note though that this method depends on the systemd-shim and that package is currently orphaned:

https://bugs.debian.org/cgi-bin/bugrepo ... =%23832508

EDIT: no, I'm wrong, this can be done without the systemd-shim, please refer to my earlier post.

I personally stick to systemd with Debian because it seems to work really well, for my OpenRC kicks I use a distribution that was designed around that init system:
Code: Select all
alpine:~$ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.8.0
PRETTY_NAME="Alpine Linux v3.8"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"
alpine:~$

No GNOME but it is awesome :)

OpenBSD offers a full GNOME desktop without a trace of systemd so that is also an option.
Last edited by Head_on_a_Stick on 2018-09-05 17:00, edited 1 time in total.
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby None1975 » 2018-09-05 16:34

As for OpenRc, i will write my notes. I tried it at my spare time in Devuan Ascii. At the beginning of the installation, i selected "Expert install" and go to step when you need to choose init system. There is a warning on that screen "it is a experimental software. Use it at own risk". This means openRC. I decided to insult myself, so I chose OpenRC. I installed the minimal system. No DE and DM, just i3wm. I used to access the graphical environment startx. I decided to check the system resources that were used with command "top". I was surprised. It turns out that a system, which is not overloaded, uses 20 percent of cpu. I found out that the culprit is an OpenRC process named "yes". Ten minutes later, the system began to jerk, the reboot took about 10 minutes. So, I understood one that the warning on the wiring screen it was not for nothing. OpenRC, in my opinion, is not ready for production. Anyone using OpenRC should have that in mind. In addition, I did not notice practically any difference between sysvinit and OpenRC (I mean loading and reloading speeds).
OS: Debian 9.4 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 623
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2018-09-05 16:59

None1975 wrote:It turns out that a system, which is not overloaded, uses 20 percent of cpu. I found out that the culprit is an OpenRC process named "yes". Ten minutes later, the system began to jerk, the reboot took about 10 minutes.

Did you test for this in a Debian system before posting?

Devuan != Debian

For the record, I had no problems with racing CPUs when booting stretch with OpenRC and ps_mem.py reported much lower overheads than with systemd (I can't comment on sysvint because I don't use that).

None1975 wrote:I did not notice practically any difference between sysvinit and OpenRC (I mean loading and reloading speeds).

Yes but how about the memory usage? OpenRC offers a significant advantage over systemd in that respect.

Also:

https://busybox.net/~vda/init_vs_runsv.html

:mrgreen:
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby None1975 » 2018-09-06 13:27

Head_on_a_Stick wrote:Did you test for this in a Debian system before posting?

Yes. I did. Yesterday.
Head_on_a_Stick wrote:For the record, I had no problems with racing CPUs when booting stretch with OpenRC

Sadly, but i have...
Head_on_a_Stick wrote:ps_mem.py reported much lower overheads than with systemd (I can't comment on sysvint because I don't use that).

The problem here is not the amount of memory used, but the system's abnormal loading.
Head_on_a_Stick wrote:Yes but how about the memory usage? OpenRC offers a significant advantage over systemd in that respect.

As far as I can remember, the difference is about 60-70 megabytes. If you have to choose, it is better to choose a time-tested solution-sysvinit.
OS: Debian 9.4 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 623
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2018-09-06 17:55

None1975 wrote:
Head_on_a_Stick wrote:Did you test for this in a Debian system before posting?

Yes. I did. Yesterday.

Did you use the systemd-shim or my posted scripts?

From where did you obtain the version of OpenRC that contains /sbin/openrc-init?

I haven't updated my package in a bit and Debian have corrected some problems upstream so perhaps an update would fix things but I'm not too keen tbh — I really do think systemd is a better option for Debian.

I never had any problems but I didn't run OpenRC for long and it was a while ago.

None1975 wrote:The problem here is not the amount of memory used, but the system's abnormal loading.

Yes, quite.

I can't test this right now because my Debian system is in hibernation on my backup drive but if you could reproduce this I would be very interested to see the output of
Code: Select all
pgrep -a yes

and perhaps even
Code: Select all
ps aux | grep yes


None1975 wrote:If you have to choose, it is better to choose a time-tested solution-sysvinit.

Isn't that an argument for systemd? More people are using that with modern hardware & software than any other init system :mrgreen:

Anyway the real advantage that OpenRC has over both systemd and sysvinit is the size of the code base and the advantage is massive.
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [HowTo] OpenRC as PID1 (init)

Postby None1975 » 2018-09-07 14:30

Head_on_a_Stick wrote:Did you use the systemd-shim or my posted scripts?

I use systemd-shim.
Head_on_a_Stick wrote:From where did you obtain the version of OpenRC that contains /sbin/openrc-init?

From here.
Head_on_a_Stick wrote:but if you could reproduce this I would be very interested to see the output

Excuse me, but this is not possible right now. I gave my test computer to my sister. Before that, I installed everything from the standard Debian with Fluxbox.
Head_on_a_Stick wrote:Isn't that an argument for systemd?

I meant Sysvinit. For example, Devuan (I know, I know, it's not Debian) uses it and works fine.
Head_on_a_Stick wrote:Anyway the real advantage that OpenRC has over both systemd and sysvinit is the size of the code base and the advantage is massive.

As I wrote, I did not notice any benefits. I do not know, maybe OpenRC might work better with Gentoo, but it's not my cup of tea. I'm not going to change the distribution.
OS: Debian 9.4 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 623
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: [HowTo] OpenRC as PID1 (init)

Postby Head_on_a_Stick » 2018-09-07 19:39

None1975 wrote:
Head_on_a_Stick wrote:From where did you obtain the version of OpenRC that contains /sbin/openrc-init?

From here.

Are you sure? :?

That package contains no /sbin/openrc-init and it is not possible to boot with OpenRC using that package version, that is why I backported the newer version.

If you used that package (and the systemd-shim) then sysvinit was being used as init with OpenRC providing the process supervision and this is *not* what my guide is suggesting (nor is it recommended by me, what a hideous Frankenstein's Monster such a creation would be).

None1975 wrote:I did not notice any benefits.

I was not speaking of perceptible benefits to the user experience but rather of the advantages inherent to a smaller code base: fewer lines of code = fewer bugs.

As a (very) rough comparison contrast init.c for sysvinit[1], which weighs in at 2656 sloc, with open-rc-init.c[2] at 195 lines of code (not a typo, check the link), quite a difference.

And that's before we mention the extensive use of bash in sysvinit, the parser in that is full of holes... :roll:

[1] https://github.com/slicer69/sysvinit/bl ... src/init.c
[2] https://github.com/OpenRC/openrc/blob/m ... nrc-init.c
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Next

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable