OpenRC: Difference between revisions
Prabuanand (talk | contribs) (added links from Installation#Post-Installation section) |
Prabuanand (talk | contribs) (rephrased sentence, fixed heading names, added wikitags) |
||
Line 1: | Line 1: | ||
Alpine Linux uses [https://github.com/OpenRC/ openrc] for its init system. | Alpine Linux uses [https://github.com/OpenRC/ openrc] for its init system. The init system manages the services, startup and shutdown of your computer. Refer to the excellent guide [https://docs.alpinelinux.org/user-handbook/0.1a/Working/openrc.html working with OpenRC] from Alpine Linux documentation project to learn the basics quickly. | ||
Refer [[Writing Init Scripts]] and [[Multiple Instances of Services]] pages for more advanced information. | Refer [[Writing Init Scripts]] and [[Multiple Instances of Services|Multiple instances of services]] pages for more advanced information. | ||
== | == Quickstart == | ||
The following commands are available to manage the init system: | The following commands are available to manage the init system: | ||
* Basics: | * Basics:{{Cmd|<nowiki># rc-update add <service> <runlevel> | ||
# rc-update del <service> <runlevel> | |||
# rc-service <service> <start stop restart> # ⇔ /etc/init.d/service <start stop restart> </nowiki>}} | |||
* To check services and their set runlevels: | * To check services and their set runlevels:{{Cmd|rc-status}} | ||
* To change to a different runlevel: | * To change to a different runlevel: {{Cmd|# openrc <runlevel>}} | ||
* Reboot/Halt/Poweroff: (And their equivalent from traditional GNU/Linux systems) | * Reboot/Halt/Poweroff: (And their equivalent from traditional GNU/Linux systems):{{Cmd|<nowiki># reboot # ⇔ shutdown now -r | ||
# halt # ⇔ shutdown now -H | |||
# poweroff # ⇔ shutdown now -P</nowiki>}} | |||
== Available | == Available runlevels == | ||
The available runlevels are: | The available runlevels are: | ||
Line 36: | Line 32: | ||
* '''reboot''' - Changes to the shutdown runlevel and then reboots the host. | * '''reboot''' - Changes to the shutdown runlevel and then reboots the host. | ||
* '''shutdown''' - Changes to the shutdown runlevel and then halts the host. | * '''shutdown''' - Changes to the shutdown runlevel and then halts the host. | ||
=== Runlevel stacking === | |||
Runlevel "inheritance" is acheived through [https://docs.alpinelinux.org/user-handbook/0.1a/Working/openrc.html#_runlevel_stacking runlevel stacking]. For more detailed information, refer [https://wiki.gentoo.org/wiki/OpenRC/Stacked%20runlevel stacked runlevels]. | |||
== Preventing slow services from delaying boot == | == Preventing slow services from delaying boot == | ||
Line 41: | Line 41: | ||
Services that take a while to start will block the boot process until they complete. E.g.: <code>iwd</code> and <code>networking</code> might delay startup of an interactive system rather than start in the background. | Services that take a while to start will block the boot process until they complete. E.g.: <code>iwd</code> and <code>networking</code> might delay startup of an interactive system rather than start in the background. | ||
This can be remedied as per Patrycja's blog post titled [https://ptrcnull.me/posts/openrc-async-services/ OpenRC: Start services after login prompt]. This solution makes use of [ | This can be remedied as per Patrycja's blog post titled [https://ptrcnull.me/posts/openrc-async-services/ OpenRC: Start services after login prompt]. This solution makes use of [[#Runlevel stacking|stacked runlevel]]. | ||
{{Warning|If the file {{Path|'''/etc/inittab'''}} is edited wrongly, the system may not boot. Take backup and learn how to restore using rescue disk before proceeding.}} | |||
{{Warning| | * Create a custom runlevel (name is “async” here, but it doesn’t matter) {{Cmd|# mkdir /etc/runlevels/async}} | ||
* Create a custom runlevel (name is “async” here, but it doesn’t matter) | |||
{{Cmd|# mkdir /etc/runlevels/async}} | |||
* Add default as a stacked runlevel | * Add default as a stacked runlevel {{Cmd|# rc-update add -s default async}} | ||
{{Cmd|# rc-update add | * Remove slow services from default and add them to async {{Cmd|<nowiki># rc-update del chronyd | ||
# rc-update add chronyd async </nowiki>}} | |||
* Add changing of runlevel to async by adding the line '''::once:/sbin/openrc async''' to {{Path|/etc/inittab}} file as follows: {{Cat|/etc/inittab|<nowiki>... | |||
::wait:/sbin/openrc default | |||
::once:/sbin/openrc async -q | |||
* Add changing of runlevel to async by adding the line '''::once:/sbin/openrc async''' | |||
# Set up a couple of getty's | |||
tty1::respawn:/sbin/getty 38400 tty1 | |||
...</nowiki>}} | |||
After rebooting, services from async will start separately. This change does not affect other services that start from Default runlevel and they may still block agetty from running due to the wait label. | After rebooting, services from async will start separately. This change does not affect other services that start from Default runlevel and they may still block agetty from running due to the wait label. | ||
Line 67: | Line 65: | ||
You can enable hybrid cgroups v1 & v2 by editing <code>/etc/rc.conf</code> and setting <code>rc_cgroup_mode="hybrid"</code>. | You can enable hybrid cgroups v1 & v2 by editing <code>/etc/rc.conf</code> and setting <code>rc_cgroup_mode="hybrid"</code>. | ||
Then you should run | Then you should run {{Cmd|# rc-service cgroups start}} | ||
to take effect and {{Cmd|# rc-update add cgroups}} | |||
to take effect | to auto mount the cgroup filesystem on boot. | ||
and | |||
to auto mount the cgroup filesystem on boot | |||
== See also == | == See also == |
Revision as of 02:17, 15 February 2025
Alpine Linux uses openrc for its init system. The init system manages the services, startup and shutdown of your computer. Refer to the excellent guide working with OpenRC from Alpine Linux documentation project to learn the basics quickly.
Refer Writing Init Scripts and Multiple instances of services pages for more advanced information.
Quickstart
The following commands are available to manage the init system:
- Basics:
# rc-update add <service> <runlevel> # rc-update del <service> <runlevel> # rc-service <service> <start stop restart> # ⇔ /etc/init.d/service <start stop restart>
- To check services and their set runlevels:
rc-status
- To change to a different runlevel:
# openrc <runlevel>
- Reboot/Halt/Poweroff: (And their equivalent from traditional GNU/Linux systems):
# reboot # ⇔ shutdown now -r # halt # ⇔ shutdown now -H # poweroff # ⇔ shutdown now -P
Available runlevels
The available runlevels are:
- default - Used if no runlevel is specified. (This is generally the runlevel you want to add services to.)
- hotplugged
- manual
The special runlevels are:
- sysinit - Brings up system specific stuff such as
/dev
,/proc
and optionally/sys
for Linux based systems. It also mounts/lib/rc/init.d
as a ramdisk using tmpfs where available unless/
is mounted rw at boot.rc
uses/lib/rc/init.d
to hold state information about the services it runs. sysinit always runs when the host first starts and should not be run again. - boot - Generally the only services you should add to the boot runlevel are those which deal with the mounting of filesystems, set the initial state of attached peripherals and logging. Hotplugged services are added to the boot runlevel by the system. All services in the boot and sysinit runlevels are automatically included in all other runlevels except for those listed here.
- single - Stops all services except for those in the sysinit runlevel.
- reboot - Changes to the shutdown runlevel and then reboots the host.
- shutdown - Changes to the shutdown runlevel and then halts the host.
Runlevel stacking
Runlevel "inheritance" is acheived through runlevel stacking. For more detailed information, refer stacked runlevels.
Preventing slow services from delaying boot
Services that take a while to start will block the boot process until they complete. E.g.: iwd
and networking
might delay startup of an interactive system rather than start in the background.
This can be remedied as per Patrycja's blog post titled OpenRC: Start services after login prompt. This solution makes use of stacked runlevel.

- Create a custom runlevel (name is “async” here, but it doesn’t matter)
# mkdir /etc/runlevels/async
- Add default as a stacked runlevel
# rc-update add -s default async
- Remove slow services from default and add them to async
# rc-update del chronyd # rc-update add chronyd async
- Add changing of runlevel to async by adding the line ::once:/sbin/openrc async to /etc/inittab file as follows:
Contents of /etc/inittab
... ::wait:/sbin/openrc default ::once:/sbin/openrc async -q # Set up a couple of getty's tty1::respawn:/sbin/getty 38400 tty1 ...
After rebooting, services from async will start separately. This change does not affect other services that start from Default runlevel and they may still block agetty from running due to the wait label.
cgroups v2
Since openrc 0.51 cgroups v2, or "unified", is the default.
You can enable hybrid cgroups v1 & v2 by editing /etc/rc.conf
and setting rc_cgroup_mode="hybrid"
.
Then you should run
# rc-service cgroups start
to take effect and
# rc-update add cgroups
to auto mount the cgroup filesystem on boot.