Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[HowTo] OpenRC as PID1 (init)

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

[HowTo] OpenRC as PID1 (init)

#1 Post by Head_on_a_Stick »

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/repositor ... ebian_8.0/

https://download.opensuse.org/repositor ... ebian_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.
deadbang

User avatar
oswaldkelso
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1490
Joined: 2005-07-26 23:20
Location: UK
Has thanked: 1 time
Been thanked: 58 times

Re: [HowTo] OpenRC as PID1 (init)

#2 Post by oswaldkelso »

Damn you HOAS, now I'll have to reply to your other post before I post on this one! :mrgreen:
Free Software Matters
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
My oldest used PC: 1999 imac 333Mhz 256MB PPC abandoned by Debian

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#3 Post by Head_on_a_Stick »

^ :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
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#4 Post by Head_on_a_Stick »

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.
deadbang

User avatar
oswaldkelso
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1490
Joined: 2005-07-26 23:20
Location: UK
Has thanked: 1 time
Been thanked: 58 times

Re: [HowTo] OpenRC as PID1 (init)

#5 Post by oswaldkelso »

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/
Free Software Matters
Ash init durbatulûk, ash init gimbatul,
Ash init thrakatulûk agh burzum-ishi krimpatul.
My oldest used PC: 1999 imac 333Mhz 256MB PPC abandoned by Debian

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#6 Post by Head_on_a_Stick »

oswaldkelso wrote:http://b0llix.net/perp/
Fascinating — thanks!
deadbang

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#7 Post by Head_on_a_Stick »

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.
deadbang

User avatar
praka123
Posts: 195
Joined: 2007-06-23 08:11
Location: Muvattupuzha,India
Has thanked: 2 times

Re: [HowTo] OpenRC as PID1 (init)

#8 Post by praka123 »

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
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#9 Post by Head_on_a_Stick »

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.
deadbang

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1388
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 65 times

Re: [HowTo] OpenRC as PID1 (init)

#10 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#11 Post by Head_on_a_Stick »

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:
deadbang

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1388
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 65 times

Re: [HowTo] OpenRC as PID1 (init)

#12 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#13 Post by Head_on_a_Stick »

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.
deadbang

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1388
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 65 times

Re: [HowTo] OpenRC as PID1 (init)

#14 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [HowTo] OpenRC as PID1 (init)

#15 Post by Head_on_a_Stick »

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
deadbang

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1388
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 65 times

Re: [HowTo] OpenRC as PID1 (init)

#16 Post by None1975 »

Head_on_a_Stick wrote: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).
After hell It's my fault. Forgive me for lying. Apparently, the reason for my failure was that I walked on a lighter path and did not use the instructions you provided. When I have the opportunity, I will do everything according to the instructions given by you. I will post the results and observations in near future here.
Head_on_a_Stick wrote: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.
Now i understood. Sorry for misunderstanding.
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Scorpion
Posts: 389
Joined: 2018-10-17 11:38
Has thanked: 5 times

Re: [HowTo] OpenRC as PID1 (init)

#17 Post by Scorpion »

Is this guide still fine now (Debian 11)?

Bulkley
Posts: 6383
Joined: 2006-02-11 18:35
Has thanked: 2 times
Been thanked: 39 times

Re: [HowTo] OpenRC as PID1 (init)

#18 Post by Bulkley »

Scorpion wrote: 2022-02-10 20:49 Is this guide still fine now (Debian 11)?
I suggest you try it in a VM. I've done it but do not want to risk it on my daily driver.

Also, you might try Antix and MX Linux to see how they did it.

Post Reply