banner

rinsmiles´ Guide to the Void

Version 2021.02



System Components and Management


Before advancing with this section it can be useful to take another look at runit’s man pages and its official documentation through void-docs to brush up on its functions, components and associated commands.
# void-docs -r services/index

Common actions include enabling services by sym-linking a service’s directory in /etc/sv/ into /var/service/, managing monitored services with the sv command, and automatically executing commands on system startup by adding them to /etc/rc.local.

Also, don't forget you can check the system logs with the dmesg command.


Network

Do any necessary configuration to connect to the internet and persist it across boots. If not using static IPs you will minimally need to set up a DHCP client, and a wireless daemon if using Wi-Fi:

For DHCP with dhcpcd or ndhc, you can simply copy and rename the service folder suffixing your network interface’s name, edit the run file to use such interface, and then enable the service.

For wireless connections, enable the (potentially interface specific) wpa_supplicant or iwd services and use wpa_cli or iwctl respectively to easily set up a new connection. Note that iwd can also be used as a DHCP client, and that it requires dbus to be running.

For Domain Name Resolution (DNS), you may use a separate application that provides security features and/or caching, like stubby or unbound, or use the nameservers already set up by your DHCP client, or simply add your preferred nameservers manually to /etc/resolv.conf. Note that also, firefox has built-in resolution capabilities using DNS-over-HTTPS and name caching.


Firewall

You can manage the kernel firewall with iptables. For quick setup for IPv4 connections, apply the simple_firewall.rules present in /etc/iptables/ with the iptables-restore ❬rules❭ command. This can be done automatically on system startup by adding such command to /etc/rc.local. See the Void docs for more details:
# void-docs -r firewall
Tip: If using iptables, you should follow the “Simple stateful firewall” guide in the ArchWiki to generate a more elaborate rule set, and which has a description of what each rule does.

Users

a) Privilege elevation: Once the system is fully set up, it is crucial to log in as a regular user for normal operation. To grant such regular users per-command privilege elevation you can use the tool doas, provided by the opendoas package. Simply install the package and set it up to allow users of the group wheel to execute commands as root when issued with it:
# echo 'permit :wheel as root' > /etc/doas.conf
A very common, yet more internally complex alternative is using sudo for this purpose.
b) User defaults: Default user creation parameters are set in /etc/default/useradd. Modify the file, and those in /etc/skel/, to provide the desired initial environment for new users.
c) Adding users: Add the aforementioned regular user (plus any others you may need) and then set their password. In addition to the wheel group, this user should be part of the audio, input and video groups to access audio and input devices and video hardware acceleration, among others:
# useradd -m -G audio,video,input,wheel ❬user_name❭
# passwd ❬user_name❭

Audio

To set up audio, install the alsa-utils package and use the alsamixer tool to unmute channels and set the volume. If you see that your desired sound card is not set as default, find the card’s index number in /proc/asound/cards and set it as the default in /etc/asound.conf:

/etc/asound.conf
# Set default sound card
defaults.ctl.card ❬card_index❭
defaults.pcm.card ❬card_index❭
defaults.hwdep.card ❬card_index❭
defaults.timer.card ❬card_index❭
Notes:

Display server

This section focuses on installing and configuring the Xorg display server with a window manager. You can follow the installation below and simply add or replace any drivers and components you need—for information on installing proprietary or vendor specific graphics drivers, access Void’s documentation with the void-docs command, e.g:
  # void-docs -r nvidia

Installation

Select the packages needed for a graphical session, including the X server, startup scripts, input and graphics drivers and the message bus system:
# PACKS='xorg-minimal mesa-dri dbus-x11
… add bitmap and outline fonts (potentially some with extensive unicode support):
> font-misc-misc dejavu-fonts-ttf (font-unifont-bdf noto-fonts-ttf)
… and your preferred window manager, a tool to launch applications (which may be included with the former) and a terminal emulator—for example:
> spectrwm dmenu st'
Install the selected packages, making sure the repository index is synchronized and that the system is up-to-date:
# xbps-install -Su $PACKS

Configuration

Keyboard layout: To set the default keyboard layout(s) for Xorg, add an X configuration file that defines an input class setting the "XkbLayout" option to them:

/etc/X11/xorg.conf.d/91-keyboard-user.conf
# Set keyboard layout
Section "InputClass"
	Identifier		"default keyboard layout"
	MatchDriver 		"libinput"
	MatchIsKeyboard		"on"
	# Either set one layout:
	Option "XkbLayout"	"❬layout❭"
	# Or define more layouts to switch between, e.g.
	# by pressing both Ctrl keys simultaneously:
	#Option "XkbLayout"	"❬layout❭,❬layout_alt❭"
	#Option "XkbOptions"	"grp:ctrls_toggle"
EndSection
To temporarily set other keyboard layouts on Xorg use the setxkbmap command, provided by the homonymous package.

Touchpad tapping: To enable tapping on touchpad devices, add an X configuration file that defines an input class setting the "Tapping" option to them:

/etc/X11/xorg.conf.d/91-touchpad-user.conf
# Enable tapping
Section "InputClass"
	Identifier		"enable touchpad tapping"
	MatchDriver 		"libinput"
	MatchIsTouchpad 	"on"
	Option "Tapping"	"on"
EndSection

Graphics driver: To specify the driver to use with a graphics device and its configuration, first find the BusID of the device with lspci (the first column) and format it accordingly—usually just prefixing it with "PCI:" and replacing the dot with a colon—then use it in an X configuration file specifying the desired driver along with any options, in the following format:

/etc/X11/xorg.conf.d/91-integrated-graphics.conf
# DDX Intel Graphics driver configuration (from xf86-video-intel package)
Section "Device"
	# Some identifier
	Identifier	"integrated graphics device"
	# Driver to use with the device
	Driver	        "intel"
	# BusID of the device in our PC
	BusID		"PCI:00:02:0"
	# Driver settings (optional)
	# This one is driver specific, to prevent tearing without compositing
	Option	"TearFree" "on"
EndSection

Session timeouts: To set the screen locker and DPMS timeouts, set the BlankTime and OffTime options respectively in a server flags X configuration file:

/etc/X11/xorg.conf.d/91-server-flags.conf
# Xorg server configuration
Section "ServerFlags"
	Option "BlankTime"	"❬minutes_blank❭"
	Option "StandbyTime"	"0"
	Option "SuspendTime"	"0"
	Option "OffTime"	"❬minutes_off❭"
EndSection
Notes:

Starting the X server

X is commonly started using the startx script, provided by the xinit package, which handles the more complex aspects of setting up the server. To configure it, modify the xinitrc script in /etc/X11/xinit/ to launch your desired application (like a window manager) when X starts, after doing any necessary setup - for example:

/etc/X11/xinit/xinitrc
#!/bin/sh
# start some nice programs - some applications put scripts there
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
    for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
        [ -x "$f" ] && . "$f"
    done
    unset f
fi
# apply per-user wallpaper - this uses ImageMagick
display -background gray12 -backdrop -window root $HOME/Pictures/.wallpaper.*g
# start screen locker daemon
xss-lock slock &
# start session
dbus-launch --exit-with-x11 spectrwm
The last line above sets up a session message bus and launches the window manager spectrwm. When the window manager quits, X will in turn exit which will cause the dbus daemon to notify clients of this (which ideally would clean up and quit in response) and then exit itself.

To start X automatically when logging in from a login shell, execute startx in /etc/profile, which is read and executed by the login shell at such point, conditioning such execution on any parameters you require:

/etc/profile
(...)
# startx automatically when logging in on tty1 as a regular user
if [ ! $DISPLAY ] && [ "$(tty)" = '/dev/tty1' ] && [ $(id -u) -ne 0 ]; then
  exec startx
fi
Once you have tested your configuration to work, consider modifying the Xwrapper.config file in /etc/X11/ to allow for auto-detection of required privileges to run the server, so that X itself may be run as a regular user rather than root (see Xorg.wrap(1)). This is a security improvement, but its availability depends on the graphics devices and drivers you use.

Note: The "exec" command above is desirable, as when the X server exits, the user will be logged out. This denies the ability of killing (or crashing) the X server to bypass locking or authentication mechanisms, and it does not prevent running Xorg root-less.


Input and ACPI events

To manage input and ACPI events use acpid, a daemon which links such events to an action. It can be used to set volume and backlight levels on key presses, to react to power or battery related events, and much more. Generically, to trigger an action in response to an event:

i) Use the tool acpi_listen to identify the event by triggering it.

ii) Add an entry for the event to a file in /etc/acpi/events/, and its associated handler script (if such is required) in /etc/acpi/handlers/.

iii) Restart the acpid service.

The script /etc/acpi/handler.sh has preset actions for some ACPI events. Since its dynamic power management functionality will have to be implemented differently for one’s machine, and to maximize the modularity of the configuration, it is advisable to limit such script to handling system power states and then manage others with dedicated files:

/etc/acpi/events/anything
# anything, that is one of these
event=button/(power|sleep|lid)
action=/etc/acpi/handler.sh %e

Reboot, shutdown and suspend

To reboot, simply log out and hit Ctrl+Alt+Del on the login shell, which is set to send the appropriate signal to the OS.

To shutdown or suspend the system, use acpid and zzz. Simply enable the acpid service if you have not yet done so, and the following will already be configured for you:

Hibernation

After setting up an environment that allows for hibernation (with an appropriately sized swap partition and the corresponding kernel parameter), you can trigger it by issuing the “zzz -Z” command as a response to an event of your choosing through acpid.

Volume and backlight

Files to manage volume and backlight related input events through acpid are provided in the Appendix.

Power and battery

Battery: Some laptops send the appropriate signals the OS as a battery discharges, which you can handle with acpid. For others, you can query battery status and load with the acpi command, provided by the homonymous package, whenever another event occurs or on a timer (see next section).

Power: See the “Power profiles” subsection of the “Power saving and performance” section further below, and the relevant files in the Appendix.


Scheduled actions

To schedule the execution of commands you can use snooze, which has services already set up to run commands on an hourly, daily, weekly and monthly basis that you can enable. You can also use snooze to run a command at a particular time and date, or on different periods.

The simplest way to use it is to enable a service for a particular run frequency, and drop executable scripts in its corresponding folder with the name ”chron.❬frequency❭“ in /etc/ (which may have to be created).

Among other things, scheduling can be used to automate system maintenance, updating backups, querying for information over the web, send notifications, etc. Common periodic actions most users will require are described below.


Notes:

Network Time Synchronization

There are many ways to synchronize the system’s clock with that of a time server. A simple and effective one is using the SNTP Perl script from the site kloth.net:

 i) Install perl if you have not already. Apart from being handy, Perl is a dependency of a large amount of packages so it would likely be pulled as such at some point.

 ii) Copy the script on the website to a file, commenting out the invocation of the “output_ntp_data” function (as suggested) near the bottom, to make it less verbose.

 iii) Set is as executable, and drop it in /usr/local/bin/.

 iv) Add an entry in chron.weekly so that snooze may trigger its execution regularly:

/etc/chron.weekly/sntp-update
#!/bin/sh
/usr/bin/perl /usr/local/bin/sntp -u pool.ntp.org
Notes:

Filesystem TRIM

Filesystems on SSD drives should be subject to trimming periodically to maintain drive performance and health. For this, use the tool fstrim provided by the util-linux package, itself a dependency of the base-minimal meta-package.

To trim all supported filesystems listed in fstab weekly, use the following:

/etc/chron.weekly/fstrim-fstab
#!/bin/sh
/usr/bin/fstrim -A
Tip: That above is periodic trim. Do not use continuous trim -the “discard” mount option or flag- unless you have a solid understanding of its purpose and how it would affect your drive.