9.5. OpenRC Usage and Configuration

9.5.1. How Does OpenRC Work?

This version of LFS uses a special booting facility named OpenRC, which starts services according to a series of run levels. These runlevels are slightly different from init systems like SysVinit. While these runlevels exist, there is much less complexity involved with OpenRC services. The process doesn't require bootscripts.

There is an alternative boot procedure called systemd. We will not discuss that boot process any further here. For a detailed description visit https://www.linux.com/training-tutorials/understanding-and-using-systemd/.

OpenRC's run level scheme has five run levels that are the most important, with the ability to add more. Each one of the five corresponds to certain modes the computer is in, like if it's booting, shutting down, or has no networking. Here are the descriptions of the different run levels as they are implemented in LFS:

  • sysinit: brings up and mounts kernel virtual filesystems

  • boot: starts up important services like setting the time and checks the filesystem

  • nonetwork: default without networking

  • default: where most services should be, like setting up audio services

  • shutdown: kills all processes and remounts / in read-only mode

Each service has dependency information, so a service on a given run level will be started at the correct time if it has correct dependency information.

9.5.2. Configuring OpenRC

Whenever a system is started, agetty is ran for a number of tty devices. OpenRC provides an agetty service but doesn't start it for each tty that's needed. Create and enable those services:

for i in $(seq 1 6); do
  ln -sfv agetty /etc/init.d/agetty.tty$i
  rc-update add agetty.tty$i default
done

These tty services are started on the default run level.

9.5.3. Creating the Udevd Service

OpenRC doesn't ship a service for udevd, leading to kernel modules not being loaded. Create and enable it now:

cat > /etc/init.d/udevd << "EOF"
#!/sbin/openrc-run
# Starts the udevd daemon and adds device nods via udevadm.
# Authors: Zeckma - zeckma.tech@gmail.com
# Version: LFS 12.5

description="starts the udevd daemon"

depend()
{
  after localnet
  before modules
}

start()
{
  ebegin "Starting the udevd daemon"

# Start the udev daemon to continually watch for, and act on,
# uevents
  SYSTEMD_LOG_TARGET=kmsg /sbin/udevd --daemon

# Now traverse /sys in order to "coldplug" devices that have
# already been discovered
  /bin/udevadm trigger --action=add    --type=subsystems
  /bin/udevadm trigger --action=add    --type=devices
  /bin/udevadm trigger --action=change --type=devices

# Now wait for udevd to process the uevents we triggered
  /bin/udevadm settle

# If any LVM based partitions are on the system, ensure they
# are activated so they can be used.
  if [ -x /sbin/vgchange ]; then /sbin/vgchange -a y >/dev/null; fi

}
EOF

chmod +x /etc/init.d/udevd
rc-update add udevd boot

This service should load most if not all modules automatically. If you need to load a given module but it isn't being loaded, pass the module name to the /etc/conf.d/modules configuration file.

9.5.4. Configuring the System Clock

OpenRC provides a hwclock service which reads from the hardware clock. It then sets the time. This time is obtained from either applying timezone data from /etc/localtime, or it simply doesn't do anything and displays the time as-is. In order to know what to do with the hardware time, it needs to decide whether the time is UTC or local. It has no way to do this on its own, so a configuration file is needed. OpenRC provides one already, and should be edited.

If you cannot remember whether or not the hardware clock is set to UTC, find out by running the hwclock --localtime --show command. This will display what the current time is according to the hardware clock. If this time matches whatever your watch says, then the hardware clock is set to local time. If the output from hwclock is not local time, chances are it is set to UTC time. Verify this by adding or subtracting the proper amount of hours for the timezone to the time shown by hwclock. For example, if you are currently in the MST timezone, which is also known as GMT -0700, add seven hours to the local time.

Once you know the hardware time uses, edit /etc/conf.d/hwclock as necessary. There are plenty of comments explaining what to edit.

9.5.5. Configuring the Linux Console

This section discusses how to configure the consolefont and keymap services that set up the console font and keyboard map. If non-ASCII characters (e.g., the copyright sign, the British pound sign, and the Euro symbol) will not be used and the keyboard is a U.S. one, much of this section can be skipped. Without the configuration files, the consolefont and keymap services will use the defaults.

The consolefont service reads the /etc/conf.d/consolefont file for configuration information. Decide which screen font will be used. Search /usr/share/consolefonts for valid fonts.

The keymaps service reads the /etc/conf.d/keymaps file for configuration information. Decide which keymap will be used. Various language-specific HOWTOs can also help with this; see https://tldp.org/HOWTO/HOWTO-INDEX/other-lang.html. If still in doubt, look in the /usr/share/keymaps directory for valid keymaps.

For both consolefont and keymaps, configuration files exist for both and have comments that give good information about what to provide to each parameter.

[Note]

Note

The configuration files for the console only control the Linux text console localization. It has nothing to do with setting the proper keyboard layout and terminal fonts in the X Window System, with ssh sessions, or with a serial console.

9.5.6. The rc.conf File

The /etc/rc.conf file contains settings that control how OpenRC starts and operates. For example, you can tell OpenRC to start services in parallel, or you can specify what run level you want the system to run at. In most cases, you won't need to edit this file.

9.5.7. Other OpenRC Configuration Files

Many other services have configuration files in /etc/conf.d and should match the service name found in /etc/init.d. If a service gives you any trouble, there may be a configuration file for it already, and should have comments provided.