paritybit.ca

OpenBSD on the Desktop

Tips and tricks related to running OpenBSD as a desktop system.

GUI Program Scaling

When using a window manager instead of a full-blown desktop environment, you might need to set scaling factors so programs will scale properly on your display. For example, on a 1920x1080 13.3” display, 1.5x scaling can be preferable so text isn’t too small.

In the .Xresources file, set an appropriate font size and Xcursor size.

In the .xsession file, add the following lines:

export QT_SCALE_FACTOR=1.5
export GDK_SCALE=1
export GDK_DPI_SCALE=1.5

If the DPI is automatically being set to fit your screen, this will make some programs too large. You can set the DPI explicitly to the “standard” using:

xrandr --dpi 96

Syncthing

Syncthing tends to run into open file limits, especially upon first sync, so the above maxfiles change is needed in /etc/sysctl.conf, and the following is needed in /etc/login.conf (followed by running cap_mkdb /etc/login.conf), also making sure my user is in the staff group:

staff:\
    ...
    :openfiles-max=32768:\
    :openfiles-cur=32768:\
    ...

Then, to run syncthing as my user, in my user’s crontab I put:

@reboot tmux new-session -d '/usr/local/bin/syncthing'

Sysctl Tuning

A few sysctl.conf tweaks to increase resource limits for a workstation system. There are other configurations I’ve seen, but I don’t really know if they improve performance or not so I stick with the defaults unless I know that changing a setting will actually do something positive.

# Increase maximum number of open files allowed (for syncthing)
kern.maxfiles=32768
# Increase the max percent of memory the buffer cache can use
kern.bufcachepercent=90
# Enable CTRL+ALT+DEL on console to reset the system
machdep.kbdreset=1
# Enable simultaneous multi-threading (hyperthreading)
hw.smt=1

Colour Emoji in GTK Applications

FreeType in xenocara is not built with libpng support, so it can’t display compressed colour emoji. Adding this to the main build in OpenBSD is tricky because libpng is in ports and building base components can’t depend on that, so libpng would need adding to xenocara in some way, which would be a lot of work to handle in ports, it would also make it more difficult to get libpng updated, and might not be accepted in the first place.

– _sthen on r/OpenBSD

You can still get colour emoji, you just have to re-compile the freetype submodule of xenocara yourself:

  1. Checkout the xenocara tree (see https://www.openbsd.org/faq/faq5.html)
  2. cd /usr/xenocara/lib/freetype
  3. In ./include/freetype/config/ftoption.h, uncomment #define FT_CONFIG_OPTION_USE_PNG
  4. Edit ./Makefile and add -L/usr/local/lib -lpng to LDADD, and -I/usr/local/include to CPPFLAGS)

Just keep in mind that you’ll need to rebuild after every sysupgrade or if a syspatch touches xenocara (so this is easier to maintain if you run -stable instead of -current, or if you normally update your system from source).

Multimedia

Ensure camera and microphone access are enabled in the OS, run:

# sysctl kern.audio.record=1
# sysctl kern.video.record=1

Multiple audio devices

This is a minor pain point with daily OpenBSD use. Audio device management is not as straightforward as it is with most other OSes, even if the audio system is way simpler. It can take a few commands to get things in order, and it’s friendliest on laptops where you are less likely to have several peripherals plugged in.

Scan dmesg for audioN strings to figure out which audio device is mapped to which number. Then, to use, for example, audio1 when present but fall back to audio0 when not, use:

# rcctl set sndiod flags -f rsnd/0 -F rsnd/1
# rcctl restart sndiod

audio1 can be a USB DAC or other non-default audio interface, for example.

You can also tell sndiod to use a specific device with the following command:

$ sndioctl server.device=1

Where 1 is the number of the sound device you want to use (corresponding to the same numbers as in rsnd/0, rsnd/1 or /dev/audio0 /dev/audio1, etc.)

Use hotplugd to reload sndiod audio devices

When you unplug an additional audio device, sndiod won’t know about it unless you tell it to reload its configuration.

# cat > /etc/hotplug/attach
#!/bin/sh

case $2 in
uaudio*)
    pkill -HUP sndiod
    ;;
esac
^D
# chmod +x /etc/hotplug/attach
# rcctl enable hotplugd
# rcctl start hotplugd

Volume Management

sndioctl is the program used to change audio device volume. It can be run as a non-privileged user:

$ sndioctl input.mute=1

will mute the microphone, for example.

$ sndioctl output.level=+0.1

will increase output volume by 10%, for example.

Environment Variables

Passing the AUDIOPLAYDEVICE and AUDIORECDEVICE environment variables to a program will tell it to use the defined devices for playing or recording audio. This is useful if you have sndio set to play audio through one device, but your microphone is a different device.

$ AUDIOPLAYDEVICE=snd/1 AUDIORECDEVICE=snd/2 mumble

will tell this invocation of mumble to play audio through the audio1 device but record through audio2.

Video

The user must have permission to use the /dev/video0 device, enable with:

# chown $USER /dev/video0

Open Ports and Associated Processes

To list all ports that are listening for connections, use netstat -l. Add the flags -f inet to look at IPv4 only, -f inet6 to look at IPv6 only, -p tcp to look at all ports listening for TCP connections, -p udp for UDP connections, and -n to show network addresses and ports as numbers instead of trying to interpret them (e.g. 127.0.0.1.80 instead of localhost.http). Only one -f or -p flag may be used at a time. For example:

$ netstat -ptcp -ln
Active Internet connections (only servers)
Proto   Recv-Q Send-Q  Local Address          Foreign Address        TCP-State
tcp          0      0  127.0.0.1.25           *.*                    LISTEN
tcp          0      0  *.22                   *.*                    LISTEN
tcp          0      0  127.0.0.1.631          *.*                    LISTEN

Find out the process listening on a particular port with the command fstat | grep :<port>. For example:

$ fstat | grep :631
root     cupsd       7212    4* internet6 stream tcp 0x0 [::1]:631
root     cupsd       7212    6* internet stream tcp 0x0 127.0.0.1:631

Articles and Other Interesting Things