[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.
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6782
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: 1079
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
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6782
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.
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6782
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: 1079
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!
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6782
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.
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6782
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable