Difference between revisions of "OpenRC"

From ArchWiki
Jump to: navigation, search
m (Network: netcfg redirects to netctl which works only with systemd)
m (Usage: change order of rc-service)
 
(348 intermediate revisions by 20 users not shown)
Line 1: Line 1:
[[Category:Boot process]]
+
[[Category:Init]]
{{Note|Arch uses [[systemd]] by default. If you use OpenRC, please mention so while asking for help.}}
+
[[ja:OpenRC]]
 +
[[ru:OpenRC]]
 +
{{Related articles start}}
 +
{{Related|init}}
 +
{{Related articles end}}
 +
{{Warning|Arch Linux only has official support for [[systemd]]. When using OpenRC, please mention so in support requests.}}
  
OpenRC is an alternate init system developed by Gentoo developers. OpenRC is a dependency based init system that works with the system provided init program, normally sysvinit. It is not a replacement for sysvinit.
+
[https://wiki.gentoo.org/wiki/OpenRC OpenRC] is a service manager maintained by the Gentoo developers. OpenRC is dependency based and works with the system provided init program, normally [[SysVinit]].
  
 
== Installation ==
 
== Installation ==
  
OpenRC is available in the [[AUR]]. You can choose to install either {{AUR|openrc}} or {{AUR|openrc-git}} package. You will also need to install {{AUR|openrc-arch-services-git}} (provides service files for use with openrc on arch) and {{AUR|openrc-sysvinit}} (a slightly patched version of traditional sysvinit). For the sake of compatibility with initscripts,  {{AUR|openrc-sysvinit}} installs the sysvinit init binary as {{ic|/sbin/init-openrc}}.
+
{{Accuracy|{{AUR|openrc-sysvinit}} removes {{Pkg|systemd-sysvcompat}}}}
  
The packages will be installed under {{Ic|/etc/openrc}} instead of the default location of {{Ic|/etc}}, so that users can switch to [[initscripts]] or [[systemd]] when desired.
+
OpenRC and accompanying packages are available in the [[AUR]]. For details on init components, see [[Init]].
 +
 
 +
Install either the {{AUR|openrc}} or {{AUR|openrc-git}} package. From version 0.25 onward, OpenRC provides its own init at {{ic|/usr/bin/openrc-init}}.
 +
Optionally, you can use other inits from, e.g., {{Pkg|busybox}} or {{AUR|openrc-sysvinit}}. Note that when {{ic|openrc-init}} is used, it must be paired with {{ic|openrc-shutdown}}, and ''not'' the {{ic|shutdown}} or {{ic|reboot}} commands from other packages, otherwise you will encounter errors.
 +
 
 +
A basic set of service files are available from the {{AUR|openrc-arch-services-git}} package.
 +
Other packages may have service files provided outside this package; a search on the AUR is recommended.
 +
 
 +
To maintain compatibility with {{AUR|initscripts-fork}}, configuration files are installed to {{ic|/etc/openrc/}}.
 +
 
 +
=== Booting ===
 +
 
 +
For booting with OpenRC add your chosen init to the [[kernel parameters]]. OpenRC's built-in init is {{ic|/usr/bin/openrc-init}}, and the one provided by {{AUR|openrc-sysvinit}} is {{ic|/usr/bin/init-openrc}}.
  
 
== Configuration ==
 
== Configuration ==
  
For booting with OpenRC add {{Ic|1=init=/sbin/init-openrc}} to the kernel line in your bootloader configuration. If you want to switch back to systemd, change it to {{ic|1=init=/usr/lib/systemd/systemd}}.
+
The {{Ic|1=/etc/openrc/conf.d}} directory, and the {{Ic|1=/etc/openrc/rc.d}} file is used for configuration.
  
For detailed instructions on configuring OpenRC, read the [http://www.calculate-linux.org/main/en/openrc_manuals man pages], visit the [http://www.gentoo.org/doc/en/openrc-migration.xml gentoo guide] and the [http://wiki.gentoo.org/wiki/OpenRC gentoo wiki].
+
For general information on configuring OpenRC, see:
  
It is worth noting that the udev service is not enabled by default. In order to enable it, do:
+
* [http://www.calculate-linux.org/main/en/openrc_manuals OpenRC manuals]
 +
* [http://www.gentoo.org/doc/en/openrc-migration.xml OpenRC migration]
 +
* [http://wiki.gentoo.org/wiki/OpenRC gentoo wiki].
  
# rc-update add udev sysinit
+
For instructions when migrating from [[systemd]], see [[Init#Configuration]].
 +
 
 +
=== Services ===
 +
 
 +
OpenRC services are enabled by issuing {{ic|rc-update add ''service_name'' ''runlevel''}} as root. It is recommended to at least enable the following services:
 +
{| class="wikitable"
 +
! Service name
 +
! [https://wiki.gentoo.org/wiki/OpenRC#Named_runlevels Runlevel]
 +
! Description
 +
|-
 +
| udev
 +
| sysinit
 +
| Device hot-plugging
 +
|-
 +
| alsa
 +
| default
 +
| [[ALSA]] state
 +
|-
 +
| acpid
 +
| default
 +
| ACPI events
 +
|-
 +
| dbus
 +
| default
 +
| Messaging bus
 +
|-
 +
| dcron
 +
| default
 +
| Scheduling
 +
|-
 +
| syslog-ng
 +
| default
 +
| System logs
 +
|}
 +
 
 +
See also [https://wiki.gentoo.org/wiki/Systemd#Native_services Native services] and [[Daemons]].
  
 
=== Network ===
 
=== Network ===
  
There are multiple ways to get a network up and running. One way is by configuring the {{ic|/etc/openrc/conf.d/network}} file. Both the {{ic|ip}} ({{Pkg|iproute2}}) and the {{ic|ifconfig}} ({{Pkg|net-tools}}) commands are supported.  
+
The network is configured through {{ic|newnet}}. [https://github.com/funtoo/openrc/blob/master/README.newnet] Modify the {{ic|/etc/openrc/conf.d/network}} file; both the {{ic|ip}} ({{Pkg|iproute2}}) and the {{ic|ifconfig}} ({{Pkg|net-tools}}) commands are supported. Below is an example configuration using {{ic|ip}}.
 
 
Below is an example configuration using {{ic|ip}}.
 
  
 
{{bc|
 
{{bc|
 
<nowiki>ip_eth0="192.168.1.2/24"
 
<nowiki>ip_eth0="192.168.1.2/24"
 
defaultiproute="via 192.168.1.1"
 
defaultiproute="via 192.168.1.1"
ifup_eth0="ip link set \$int mtu 1500"</nowiki>}}
+
ifup_eth0="ip link set \$int mtu 1500"
 +
</nowiki>}}
 +
 
 +
The network service is added to the boot runlevel by default, so no further action is required. See [[Network configuration]] for general networking information.
 +
 
 +
{{Note|1=You may also use [[NetworkManager]], [[dhcpcd]] or {{AUR|netcfg}} by enabling the respective services. ''netcfg'' mimics the [[netctl]] behaviour (see [https://bbs.archlinux.org/viewtopic.php?pid=1489283#p1489283] if you want to enable profiles connection on booting - requires {{ic|wpa_actiond}}). See [https://www.archlinux.org/netcfg/features.html netcfg features].}}
  
The network service is added to the boot runlevel by default, so no further action is required.
+
=== Boot logs ===
  
You can also use [[NetworkManager]], [[Dhcpcd]] or {{AUR|netcfg}} by enabling the respective services.
+
To enable boot logging, uncomment the {{ic|1=rc_logger="YES"}} line in {{ic|/etc/openrc/rc.conf}}. When enabled, boot logs are stored in {{ic|/var/log/rc.log}}.
  
Take a look at [[Network Configuration]] for a detailed look at networking in general.
+
=== Hostname ===
  
=== Logging ===
+
OpenRC sets the hostname from {{ic|/etc/openrc/conf.d/hostname}}. The file looks as follows:
  
====syslog-ng====
+
{{bc|# Set to the hostname of this machine
If you use syslog-ng, comment out the following line in {{ic|/etc/syslog-ng/syslog-ng.conf}}:
+
hostname<nowiki>=</nowiki>"myhostname"}}
{{bc|unix-dgram("/run/systemd/journal/syslog")}}
 
and add this line instead: {{bc|unix-dgram("/dev/log");}}
 
{{Note|Without making this change syslog-ng will fail to run and as a result nothing will be logged!}}
 
  
====Boot logging====
+
=== Kernel modules ===
OpenRC's boot logging is disabled by default. To enable it, uncomment the following line in {{ic|/etc/openrc/rc.conf}}:
 
{{bc|<nowiki>#rc_logger="YES"</nowiki>}}
 
  
=== Hostname ===
+
OpenRC uses {{ic|/etc/openrc/conf.d/modules}} instead of {{ic|/etc/modules-load.d}}. For example:
OpenRC sets the hostname from {{ic|/etc/openrc/conf.d/hostname}}.
+
 
 +
{{hc|/etc/openrc/conf.d/modules|2=
 +
# You should consult your kernel documentation and configuration
 +
# for a list of modules and their options.
  
Here is an example file:
+
modules="vboxdrv acpi_cpufreq"
{{hc|/etc/openrc/conf.d/hostname|
 
<nowiki>hostname="myhostname"</nowiki>
 
 
}}
 
}}
  
=== Module autoloading ===
+
=== Locale ===
OpenRC doesn't use /etc/modules-load.d/ folder, instead it uses {{ic|/etc/openrc/conf.d/modules}}.
+
 
 +
Keyboard layout can be configured via {{ic|/etc/openrc/conf.d/keymaps}} and {{ic|/etc/openrc/conf.d/consolefont}}. You can also configure the settings through the {{ic|/etc/locale.conf}} file, which is sourced via {{ic|/etc/profile.d/locale.sh}}.
 +
 
 +
See [http://wiki.gentoo.org/wiki/Localization/HOWTO#Keyboard_layout_for_the_console] and [[Locale]] for details.
 +
 
 +
== Usage ==
 +
 
 +
This section draws a parallel between [[systemd]] and other [[init]] systems.
 +
 
 +
You can omit the {{ic|.service}} and {{ic|.target}} extensions, especially if temporarily editing the [[kernel parameters]].
  
add a line like this to that file :
+
{| class="wikitable" width="100%"
{{bc|<nowiki>modules=acpi_cpufreq</nowiki>}}
+
! systemd !! SysVinit !! OpenRC !! Description
 +
|-
 +
| {{ic|systemctl list-units}} || {{ic|rc.d list}} || {{ic|rc-status}} || List running services status
 +
|-
 +
| {{ic|systemctl --failed}} || || {{ic|rc-status --crashed}} || Check failed services
 +
|-
 +
| {{ic|systemctl --all}} || || {{ic|rc-update -v show}} || Display all available services.
 +
|-
 +
| {{ic|systemctl (start, stop, restart, status) daemon.service}} || {{ic|rc.d (start, stop, restart) daemon}} || {{ic|rc-service daemon (start, stop, restart, status)}} || Change service state.
 +
|-
 +
| {{ic|systemctl (enable, disable) daemon.service}} || {{ic|chkconfig daemon (on, off)}} || {{ic|rc-update (add, del) daemon}} || Turn service on or off.
 +
|-
 +
| {{ic|systemctl daemon-reload}} || {{ic|chkconfig daemon --add}} || || Create or modify configuration.
 +
|}
  
=== Locale ===
+
== Tips and tricks ==
  
There is no built-in support for configuring locales in OpenRC. Though, you can configure the settings through the {{ic|/etc/locale.conf}} file, which is sourced via {{ic|/etc/profile.d/locale.sh}}.
+
=== Quiet booting ===
  
For details on configuring the locale, take a look [[Locale | here]].
+
To hide boot messages from OpenRC, you can edit {{ic|/etc/inittab}} and add {{ic|--quiet}} to every openrc command. For further information check with {{ic|$ openrc -h}}.
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 78: Line 153:
 
* in use but fuser finds nothing [ !! ]}}
 
* in use but fuser finds nothing [ !! ]}}
  
This can be fixed by adding  
+
This can be fixed by adding
 +
 
 
  no_umounts="/tmp"
 
  no_umounts="/tmp"
  
Line 85: Line 161:
 
{{Note|This problem occurs only if your tmp is mounted as a tmpfs.}}
 
{{Note|This problem occurs only if your tmp is mounted as a tmpfs.}}
  
=== Disabling IPv6 doesn't work ===
+
=== Disabling IPv6 does not work ===
  
If you have OpenRC installed under the {{Ic|/etc/openrc}} sysconf directory, and disabling IPv6 through {{Ic|/etc/sysctl.conf}} doesn't work.
+
One option is to add:
  
One fix for this is to put
 
 
  # Disable ipv6
 
  # Disable ipv6
 
  net.ipv6.conf.all.disable_ipv6 = 1
 
  net.ipv6.conf.all.disable_ipv6 = 1
in a file (with a .conf extension) under {{Ic|/etc/openrc/sysctl.d}}
 
  
== External Links ==
+
in a file with a {{ic|.conf}} extension under {{ic|/etc/openrc/sysctl.d}}
 +
 
 +
=== During shutdown remounting root as read-only fails ===
 +
 
 +
If the above happens, edit the {{ic|/etc/openrc/init.d/mount-ro}} file and put:
 +
 
 +
telinit u
 +
 
 +
after the following line:
 +
 
 +
# Flush all pending disk writes now
 +
sync; sync
 +
 
 +
=== /etc/sysctl.conf not found ===
 +
 
 +
By default, {{ic|sysctl --system}} is called to load the sysctl configuration. [https://github.com/OpenRC/openrc/blob/master/init.d/sysctl.Linux.in#L17] This includes the {{ic|/etc/sysctl.conf}} file, which was removed from Arch. [https://www.archlinux.org/news/deprecation-of-etcsysctlconf/]
 +
 
 +
To prevent a missing file error, create the file:
 +
 
 +
# touch /etc/sysctl.conf
 +
 
 +
=== opentmpfiles-setup failed to start ===
 +
 
 +
On booting openrc you may see lines like these :
 +
 
 +
* Setting up tmpfiles.d entries ...
 +
chattr: Operation not supported while setting flags on /var/log/journal
 +
chattr: No such file or directory while trying to stat /var/log/journal/%m
 +
chattr: Operation not supported while setting flags on /var/log/journal/remote
 +
[ !! ]
 +
ERROR: opentmpfiles-setup failed to start
 +
 
 +
This is caused by {{ic|/usr/lib/tmpfiles.d/journal-nocow.conf}} using options that are only valid if journal is on a btrfs filesystem.
 +
 
 +
See https://github.com/OpenRC/opentmpfiles/issues/2 for details
 +
 
 +
A workaround is to create an empty /etc/tmpfiles.d/journal-nocow.conf to override the settings.
 +
 
 +
== Using OpenRC with a desktop environment ==
 +
 
 +
If using ''OpenRC'' with a [[desktop environment]], ConsoleKit may help. Install the [https://gist.github.com/ad73f9087f39d7cadd8e service] to {{ic|/etc/openrc/init.d}}, and enable it:
 +
 
 +
# rc-update add consolekit default
 +
 
 +
See [[ConsoleKit]] for more information.
 +
 
 +
Begin with OpenRC 0.28 SysVinit is replaced with openrc-init, shutdown is replaced with openrc-shutdown, by using consolekit the system may hang up when shuting down from desktop session. So use {{AUR|elogind-openrc}}{{Broken package link|package not found}} instead. Enable it with:
 +
 
 +
# rc-update add elogind default
 +
 
 +
Also you need to replace polkit-consolekit with {{AUR|polkit-elogind}}, or the system will alarm "not authorized to perform operation" when mounting usb device, and can't reboot or shutdown from the desktop session.
 +
 
 +
== Reverting to systemd ==
 +
 
 +
Reverting to systemd should be straightforward in most cases. It is essentially the reversal of migrating to OpenRC, with care placed on the following:
 +
 
 +
* Removal of, or otherwise editing, the {{ic|1=init=}} parameter on the kernel command line
 +
* Replacement of any OpenRC-tailored or no-systemd packages with their stock equivalents (e.g. replacement of {{AUR|dbus-nosystemd}} with {{pkg|dbus}})
 +
 
 +
== See also ==
 +
 
 
* [[Wikipedia:OpenRC]]
 
* [[Wikipedia:OpenRC]]
 +
* [https://wiki.gentoo.org/wiki/OpenRC Gentoo wiki]
 
* [https://bbs.archlinux.org/viewtopic.php?id=152606 Forum thread about OpenRC in Arch]
 
* [https://bbs.archlinux.org/viewtopic.php?id=152606 Forum thread about OpenRC in Arch]
 +
* [http://blog.notfoss.com/posts/openrc-on-arch-linux/ Blog: OpenRC on Arch Linux]
 +
* [https://wiki.manjaro.org/index.php?title=OpenRC,_an_alternative_to_systemd Manjaro wiki]

Latest revision as of 10:20, 5 November 2017

Warning: Arch Linux only has official support for systemd. When using OpenRC, please mention so in support requests.

OpenRC is a service manager maintained by the Gentoo developers. OpenRC is dependency based and works with the system provided init program, normally SysVinit.

Installation

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: openrc-sysvinitAUR removes systemd-sysvcompat (Discuss in Talk:OpenRC#)

OpenRC and accompanying packages are available in the AUR. For details on init components, see Init.

Install either the openrcAUR or openrc-gitAUR package. From version 0.25 onward, OpenRC provides its own init at /usr/bin/openrc-init. Optionally, you can use other inits from, e.g., busybox or openrc-sysvinitAUR. Note that when openrc-init is used, it must be paired with openrc-shutdown, and not the shutdown or reboot commands from other packages, otherwise you will encounter errors.

A basic set of service files are available from the openrc-arch-services-gitAUR package. Other packages may have service files provided outside this package; a search on the AUR is recommended.

To maintain compatibility with initscripts-forkAUR, configuration files are installed to /etc/openrc/.

Booting

For booting with OpenRC add your chosen init to the kernel parameters. OpenRC's built-in init is /usr/bin/openrc-init, and the one provided by openrc-sysvinitAUR is /usr/bin/init-openrc.

Configuration

The /etc/openrc/conf.d directory, and the /etc/openrc/rc.d file is used for configuration.

For general information on configuring OpenRC, see:

For instructions when migrating from systemd, see Init#Configuration.

Services

OpenRC services are enabled by issuing rc-update add service_name runlevel as root. It is recommended to at least enable the following services:

Service name Runlevel Description
udev sysinit Device hot-plugging
alsa default ALSA state
acpid default ACPI events
dbus default Messaging bus
dcron default Scheduling
syslog-ng default System logs

See also Native services and Daemons.

Network

The network is configured through newnet. [1] Modify the /etc/openrc/conf.d/network file; both the ip (iproute2) and the ifconfig (net-tools) commands are supported. Below is an example configuration using ip.

ip_eth0="192.168.1.2/24"
defaultiproute="via 192.168.1.1"
ifup_eth0="ip link set \$int mtu 1500"

The network service is added to the boot runlevel by default, so no further action is required. See Network configuration for general networking information.

Note: You may also use NetworkManager, dhcpcd or netcfgAUR by enabling the respective services. netcfg mimics the netctl behaviour (see [2] if you want to enable profiles connection on booting - requires wpa_actiond). See netcfg features.

Boot logs

To enable boot logging, uncomment the rc_logger="YES" line in /etc/openrc/rc.conf. When enabled, boot logs are stored in /var/log/rc.log.

Hostname

OpenRC sets the hostname from /etc/openrc/conf.d/hostname. The file looks as follows:

# Set to the hostname of this machine
hostname="myhostname"

Kernel modules

OpenRC uses /etc/openrc/conf.d/modules instead of /etc/modules-load.d. For example:

/etc/openrc/conf.d/modules
# You should consult your kernel documentation and configuration
# for a list of modules and their options.

modules="vboxdrv acpi_cpufreq"

Locale

Keyboard layout can be configured via /etc/openrc/conf.d/keymaps and /etc/openrc/conf.d/consolefont. You can also configure the settings through the /etc/locale.conf file, which is sourced via /etc/profile.d/locale.sh.

See [3] and Locale for details.

Usage

This section draws a parallel between systemd and other init systems.

You can omit the .service and .target extensions, especially if temporarily editing the kernel parameters.

systemd SysVinit OpenRC Description
systemctl list-units rc.d list rc-status List running services status
systemctl --failed rc-status --crashed Check failed services
systemctl --all rc-update -v show Display all available services.
systemctl (start, stop, restart, status) daemon.service rc.d (start, stop, restart) daemon rc-service daemon (start, stop, restart, status) Change service state.
systemctl (enable, disable) daemon.service chkconfig daemon (on, off) rc-update (add, del) daemon Turn service on or off.
systemctl daemon-reload chkconfig daemon --add Create or modify configuration.

Tips and tricks

Quiet booting

To hide boot messages from OpenRC, you can edit /etc/inittab and add --quiet to every openrc command. For further information check with $ openrc -h.

Troubleshooting

Error while unmounting /tmp

When shutting the system down, you might get an error message such as

* Unmounting /tmp ... 
* in use but fuser finds nothing [ !! ]

This can be fixed by adding

no_umounts="/tmp"

to /etc/openrc/conf.d/localmount

Note: This problem occurs only if your tmp is mounted as a tmpfs.

Disabling IPv6 does not work

One option is to add:

# Disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1

in a file with a .conf extension under /etc/openrc/sysctl.d

During shutdown remounting root as read-only fails

If the above happens, edit the /etc/openrc/init.d/mount-ro file and put:

telinit u

after the following line:

# Flush all pending disk writes now
sync; sync

/etc/sysctl.conf not found

By default, sysctl --system is called to load the sysctl configuration. [4] This includes the /etc/sysctl.conf file, which was removed from Arch. [5]

To prevent a missing file error, create the file:

# touch /etc/sysctl.conf

opentmpfiles-setup failed to start

On booting openrc you may see lines like these :

* Setting up tmpfiles.d entries ...
chattr: Operation not supported while setting flags on /var/log/journal
chattr: No such file or directory while trying to stat /var/log/journal/%m
chattr: Operation not supported while setting flags on /var/log/journal/remote
[ !! ]
ERROR: opentmpfiles-setup failed to start

This is caused by /usr/lib/tmpfiles.d/journal-nocow.conf using options that are only valid if journal is on a btrfs filesystem.

See https://github.com/OpenRC/opentmpfiles/issues/2 for details

A workaround is to create an empty /etc/tmpfiles.d/journal-nocow.conf to override the settings.

Using OpenRC with a desktop environment

If using OpenRC with a desktop environment, ConsoleKit may help. Install the service to /etc/openrc/init.d, and enable it:

# rc-update add consolekit default

See ConsoleKit for more information.

Begin with OpenRC 0.28 SysVinit is replaced with openrc-init, shutdown is replaced with openrc-shutdown, by using consolekit the system may hang up when shuting down from desktop session. So use elogind-openrcAUR[broken link: package not found] instead. Enable it with:

# rc-update add elogind default

Also you need to replace polkit-consolekit with polkit-elogindAUR, or the system will alarm "not authorized to perform operation" when mounting usb device, and can't reboot or shutdown from the desktop session.

Reverting to systemd

Reverting to systemd should be straightforward in most cases. It is essentially the reversal of migrating to OpenRC, with care placed on the following:

  • Removal of, or otherwise editing, the init= parameter on the kernel command line
  • Replacement of any OpenRC-tailored or no-systemd packages with their stock equivalents (e.g. replacement of dbus-nosystemdAUR with dbus)

See also