/etc/runlevels/

This wiki page is about a path or a file in the Linux file system. Be bold and improve it! Describe its purpose and its use, which program created it and uses it, which configuration settings it might be dependent on, and which Linux distributions typically have this file by default while others might not.

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Runlevels

Each subdirectory is a given run levels and provides symlinks to scripts in /etc/init.d/ to be run at a particular stage.

See:
http://linux.overshoot.tv/etc/init.d
http://linux.overshoot.tv/wiki/openrc

Beware: differentiate between the runlevels defined by init and configured in /etc/inittab (man inittab):
http://linux.overshoot.tv/etc/inittab
from the runlevels defined here by OpenRC.
Init comes first. It implements its own runlevels, and then calls the OpenRC runlevels at the appropriate times, delegating to it most of the work (which exact services to start, etc.).

To select a specific runlevel at boot and to configure runlevels, see also:
https://wiki.gentoo.org/wiki/OpenRC#Selecting_a_specific_runlevel_at_boo...

boot

The boot runlevel starts all system-necessary services which all other runlevels use.
This runlevel is automatically called by init and does not need to be included in other runlevels.
You shouldn't modify anything in this runlevel.
You should not call this runlevel yourself. Instead you should use init(8) and shutdown(8) and let them call this special runlevel.

default

The default runlevel is used for day-to-day operations.

nonetwork

The nonetwork runlevel is used in case no network connectivity is required

shutdown

The shutdown runlevel is automatically called when powering off or rebooting the computer.
You shouldn't modify anything in this runlevel.
You should not call this runlevel yourself. Instead you should use init(8) and shutdown(8) and let them call this special runlevel.

single

The single runlevel is used when the system needs to be fixed.
See man openrc and /etc/inittab:
openrc single stops all services except for those in the sysinit runlevel.
This runlevel does not actually exist within /etc/runlevels and does not need to be created.
You should not call this runlevel yourself. Instead you should use init(8) and shutdown(8) and let them call this special runlevel.

Adding 'single' to the kernel boot option will run init 1 (single mode) and then init 3 (openRC default runlevel).

sysinit

This sysinit is automatically called by init and does not need to be included in other runlevels.
You shouldn't modify anything in this runlevel.
You should not call this runlevel yourself. Instead you should use init(8) and shutdown(8) and let them call this special runlevel.

Runlevel inheritance

A default Gentoo installation does not use any runlevel inheritance.

The --stack option of rc-update allows a runlevel to inherit from another runlevel.

man rc-update:
If the -s, --stack option is given then we either add or remove the runlevel from the runlevel. This allows inheritance of runlevels.

E.g.:

rc-update --stack add default myrunlevel

Thus myrunlevel will include all the services already included in default.

Understanding the current configuration

Before doing anything with OpenRC, it helps to understand which runlevels already exist and the current setup:

# rc-status --list
sysinit
shutdown
boot
default
nonetwork

# rc-update -v show

Tutorial: designing a new runlevel

To create a new runlevel, it is enough to create a new directory under /etc/runlevels/ :

# mkdir /etc/runlevels/myrunlevel

Now, if you want to add services to all those already present in the default runlevel, simply stack myrunlevel on top of default:

rc-update --stack add default myrunlevel

After you have added a few services, you may switch to this new runlevel by issuing the command:

openrc myrunlevel

If on the other hand, you want to add a few, remove a few, you may add each service individually or copy all the services already present in default, and then remove those you don't want:

# cd /etc/runlevels/default
# for service in *; do rc-update add $service myrunlevel; done
# rc-update del service.to.remove myrunlevel
# rc-update show myrunlevel

Add the services you do want, e.g.

# rc-update add sshd myrunlevel

Check what you have so far:

#  rc-update show myrunlevel
sshd | myrunlevel

and compare to the default runlevel:
# rc-update show myrunlevel default
                 sshd | myrunlevel default
                  xdm |            default
...

Then, edit the bootloader configuration and add a new entry for the myrunlevel. In that entry, add softlevel=myrunlevel as a boot parameter.