OpenBSD Workstation

Posted on June 14, 2019

Here is the configuration I performed on my OpenBSD desktop workstation. I wanted:

  1. a simple desktop (awesome) with graphical login (xenodm (1))
  2. some network (wired and wireless)
  3. fonts with ligatures for development (Konsole + vim)
  4. to play audio, and to watch some video (I work most of the time, I promise)
  5. the Crystal language compiler (it’s now part of my work)

Graphical interface (Xenodm and Awesome)

Xenodm is used to launch the X server, a graphical login prompt then the window manager.

rcctl enable xenodm
rcctl start xenodm

I use daily the awesome window manager, and I want it on my OpenBSD (I want some tiling!). Xenodm uses the file ~/.xsession to know what program we want for the X session. The simplest way to tell xenodm to launch awesome is:

echo exec awesome >> ~/.xsession

OpenBSD ships an example of the user’s rc configuration file in /usr/local/share/examples/awesome/rc.lua, and I use it almost as is. The only thing I want to change are the title bars on top of each window. I do not want them. There’re useless as fuck. The whole point of having a tiling window manager is to never have to manually change a window size, so this title bar takes space on my screen for no reason! Here is the quick change I made to the configuration example:

-- In the file `~/.config/awesome/rc.lua`, copied from `/usr/local/share/examples/awesome/rc.lua`
...
-- Add titlebars to normal clients and dialogs
{ rule_any = {type = { "normal", "dialog" }
}, properties = { titlebars_enabled = true } -- CHANGE TO "false" to remove useless bars!
},
...

Network configuration

For testing, you can manually configure your the wireless card:

ifconfig iwn0 nwid YOUR_SSID wpakey "YOUR_PASSPHRASE"
dhclient iwn0

When you move, you want to connect automatically to the nearest WiFi hotspot you know.

# In the file `/etc/hostname.if` (in my case: `/etc/hostname.iwm0`)
join "SSID" wpakey "KEY"
# join "another SSID" wpakey "another KEY"
# join "again" wpakey "some more KEY"
dhcp
up powersave

For the installation, I also used a wired connection and I need static configuration for my virtual machines. Here is an example:

# In the file `/etc/hostname.em0`
inet 192.168.42.2 255.255.255.0

This line can be replaced by “dhcp”. We can add “up” in the file if we want this device to be started on system boot.

Once we put a network interface up, a script can be started:

!/path/to/my/script

As an example, I use this on another installation to start a VPN connection to my ISP:

# In the file `/etc/hostname.tun0`
description "OpenVPN client to ARN server"
!/usr/local/sbin/openvpn --daemon --config /etc/openvpn/openvpn.conf --dev $if & false
up

Fonts with ligatures

I really like Fira Code fonts, and want them for development.

# Fira Code fonts installation
mkdir ~/.local/share/fonts ; cd ~/.local/share/fonts
git clone https://github.com/tonsky/FiraCode ; fc-cache -vf

The terminal I’m currently using is Konsole, but I’m not quite satisfied at the moment. Yes, it behaves smoothly with ligatured fonts, but it is kinda heavy. I would prefer something way simpler and faster to boot, such as Kitty or Alacrity (which are either not supported on OpenBSD or do not support ligatures).

On Konsole, I currently use the Breeze theme, with Fira Code Medium, font size 12, 10.000 lines of backlog (but without the scrolling bar, since it takes space for nothing), with the UTF-8 encoding (I need french accents!). A shortcut I use: CTRL + SHIFT + M (removes the navigation bar).

The Crystal language

There are two ways to get the Crystal language working on my OpenBSD laptop:

  1. by running virtual machines (either Linux or FreeBSD)
  2. by cross-compiling the language from a Linux box, then to link it on OpenBSD with LLVM 6.1 (which is to compile too, since OpenBSD comes with the 7.0 version, 8.0 in the next release)

These two points deserve an article on their own.

Misc configuration

Intel tearing

The default modesetting driver doesn’t use vsync, so you’ll get a lot of tearing when scrolling webpages or watching videos. If you have an Intel-based video chipset, you can switch to the intel driver to get smooth video. – Callum Smith on his blog

Since I have an Intel graphic card, I do need some more configuration for the X server. First, mkdir /etc/X11/xorg.conf.d/, then:

# In the file `/etc/X11/xorg.conf.d/intel.conf`
Section "Device"
	Identifier "drm"
	Driver "intel"
	Option "TearFree" "true"
EndSection

more resources for the user

OpenBSD ships with drastic restrictions for the user, I want to alleviate this so we can use poorly designed software and protocols (yes, I talk about the web: web protocols, web browsers and so).

# In the file `/etc/sysctl.conf`

# to allow the openbsd box to perform router's tasks
net.inet.ip.forwarding=1

# shared memory limits (chrome needs a ton)
kern.shminfo.shmall=3145728
kern.shminfo.shmmax=2147483647
kern.shminfo.shmmni=1024

# semaphores
kern.shminfo.shmseg=1024
kern.seminfo.semmns=4096
kern.seminfo.semmni=1024

kern.maxproc=32768
kern.maxfiles=65535
kern.bufcachepercent=90
kern.maxvnodes=262144
kern.somaxconn=2048

I put my user in the staff login class with usermod -L staff karchnu, then I changed the default configuration to allow more resources.

# In the file `/etc/login.conf`
# Staff have fewer restrictions and can login even when nologins are set.

staff:\
	:datasize-cur=7000M:\
	:datasize-max=infinity:\
	:maxproc-max=512:\
	:maxproc-cur=256:\
	:ignorenologin:\
	:requirehome@:\
	:tc=default:

doas (sudo replacement, for greater good)

I want my user to be able to halt and reboot the laptop. I also want to control the virtual machines without entering any password, for vmctl or qemu.

permit nopass karchnu as root cmd vmctl
permit nopass karchnu as root cmd halt
permit nopass karchnu as root cmd reboot
permit nopass karchnu as root cmd /usr/local/bin/qemu-system-x86_64

faster disk operations

To have greater disk performances, we can allow [soft updates][softupdates] (softdep option) and the noatime option on our partitions.

# In the file `/etc/fstab`
MYUUID.b none swap sw
MYUUID.a / ffs rw,softdep,noatime, 1 1
MYUUID.k /home ffs rw,softdep,noatime,nodev,nosuid 1 2
MYUUID.d /tmp ffs rw,softdep,noatime,nodev,nosuid 1 2
MYUUID.f /usr ffs rw,softdep,noatime,nodev 1 2
MYUUID.g /usr/X11R6 ffs rw,softdep,noatime,nodev 1 2
MYUUID.h /usr/local ffs rw,wxallowed,softdep,noatime,nodev 1 2
MYUUID.j /usr/obj ffs rw,nodev,softdep,noatime,nosuid 1 2
MYUUID.i /usr/src ffs rw,nodev,softdep,noatime,nosuid 1 2
MYUUID.e /var ffs rw,nodev,softdep,noatime,nosuid 1 2

suspend the laptop when closed

mkdir /etc/apm/

There are two lines to put in the file /etc/apm/suspend:

#!/bin/sh
pkill -USR1 xidle

disable console on login

sed -i 's/xconsole/#xconsole/' /etc/X11/xenodm/Xsetup_0
echo 'xset b off' >> /etc/X11/xenodm/Xsetup_0

disable the annoying bell

# In the file `/etc/wsconsctl.conf`
keyboard.bell.volume=0

software I use

pkg_add vim moc gnuwatch firefox chromium mplayer konsole qemu
# unfortunately `moc` cannot change audio settings on its own, we have to use `mixerctl`
# which is not a deal-breaker

useful commands from a Linux user perspective

  • alsamixer (+ pulseaudio and other stuff) => mixerctl + audioctl
    • They behave as other commands, such as sysctl or wsconsctl, providing a great feeling of consistency
  • acpi => apm -l
  • systemctl => rcctl (same functionalities but without the bloat)
  • journalctl => /var/log (all we ever needed, for fuck’s sake)

Conclusion

The good part. I got most of what I wanted working without any trouble. The desktop installation was smooth, so were the audio and the network. Nothing to say, it was just working out-of-the-box, even better than expected!

The documentation is near perfect. A good part of this article is documented in the OpenBSD FAQ, which helps you get most of the things working. Also, there are tons of examples, such as complete configuration files in /etc/examples or /usr/local/share/examples/, which are very useful when you want things done quick. You have some documentation in /usr/local/share/doc/ for third party software, and there are often examples in manuals. It’s so great that I read documentation for fun.

The system is clean: directories have a well-defined purpose, and it’s easy to find the right one. Here some examples of useful directories to know:

  • package readmes /usr/local/share/doc/pkg-readmes/
  • libraries are on /usr/lib or /usr/local/lib and that’s it, no bloat
  • very specific tooling for ports /usr/ports/infrastructure/bin/

Also, there is a real consistency in the directories usage. For anyone used to Debian absurdities, that’s a blessing.

The tooling on this system is also very interesting and complete, you rarely need anything more than what’s already provided to work on the system. By pure random chance, I read the proot(1 manual. This program allows you to create chroot environments based solely on file hard links of your host system. In other words, you can create living systems in chroot environments without using anymore space on your disk (just some more inodes), with a simple command, and without requiring shiny file systems nor fancy virtual machines. This is useful for building or packaging applications without installing anything on your host. This tool is so simple that I might develop something similar on Linux (I need something like this for a future project, stay on). No wonder all OpenBSD developers do not rush to get virtual machines working, there is simply no need, really.

The less good part. I got some problems installing an Alpine virtual machine, and I will describe this in another article. Just a word on this issue: Alpine virtual machines can randomly crash using vmm, but most of the work is done. OpenBSD virtual machines work smoothly. Qemu under OpenBSD seems slow, but it is stable (I got Alpine working perfectly).

I would like to have a terminal emulator such as Kitty running on OpenBSD, to remove all the GUI bloat from Konsole, but it’s not yet possible. However, it’s not a problem related by OpenBSD itself, just the lack of support for very recent projects.

Finally, I think that I had a great experience. Some things will be even better in a near future with the efforts put on vmm. I do hope that someone will port the Crystal compiler on OpenBSD soon, I’ll do it myself otherwise.

Resources

I was inspired by some articles and documentations.