Skip to main content

OpenRC init

Overview

Alpine linux uses Busybox' init as process 1, which in turn runs OpenRC as a service manager.

OpenRC features its own process 1 implementation - openrc-init - which suits container startup perfectly well.

We can reduce (minimally) startup and administration dependencies by replacing /sbin/init with /sbin/openrc-init.

Follow this steps to switch to OpenRC init:

  • Assure terminal configuration on openrc startup
  • Configure OpenRC
  • Configure the container to start openrc-init.

Terminal Configuration

See Busybox getty

After setting up the busybox start script, enable the service for at least the console and tty1. We add tty2 also.

sudo true
CONSOLES="console tty1 tty2"
cd /etc/conf.d
for t in $CONSOLES; do sudo ln -s bgetty bgetty.$t; done
cd /etc/init.d
for t in $CONSOLES; do sudo ln -s bgetty bgetty.$t; done
for t in $CONSOLES; do sudo rc-update add bgetty.$t; done

This does not yet run the gettys. If you want to test one use e.g.: rc-service bgetty.tty2 start.

Note: The console is switched around during startup.  Including it as a bgetty terminal service seems to print out console startup messages on tty1 and then start the login shell there.

Autologin a User

getty runs a login command, which can be replaced with the -l commandline option, however it is not possible to specify options.  So we need to write a login script which is then called by getty:

sudo true
sudo tee /usr/local/bin/login.$USER <<EOF
#!/bin/sh
exec login -p -f $USER
EOF
chmod +x /usr/local/bin/login.$USER

The /usr/local/bin/login.USER script logs in USER without prompt and without authentication.

Add a corresponding options line to the bgetty configuration file:

sudo true
sudo tee -a /etc/conf.d/bgetty <<EOF
bgetty_options="-n -l /usr/local/bin/login.$USER"
EOF

After starting the respective terminal the users login shell is run immediately. If the user exits the shell she is logged in immediately again.

Configure OpenRC

The following settings in /etc/rc.conf are optional

rc_parallel="YES"
rc_env_allow="*"
rc_sys="lxc"
rc_tty_number=4
  • rc_parallel: start up independent services in parallel. gives confusing output on start, but allows almost immediate interaction
  • rc_env: pass all environment variables through to the shell.
  • rc_sys: only important setting
  • rc_tty_number: normally 12 tty's are allocated, we reduce them because we probably don't ever need 'em.

Container Shutdown with OpenRC init

Use openrc-shutdown to shut down the container. Standard init commands like reboot and shutdown won't work.

Configure the LXC Container

Add this to the container config:

lxc.tty.max = 4
lxc.init.cmd = /sbin/openrc-init