Add resolutions in OpenBSD VM (libvirt/qemu)

Wanted to test OpenBSD as a desktop, I spun up a VM using virt-manager (libvirt) and walked through the install process. After getting all setup, I found I could only set a few different resolutions, none of which where all that high. This is due to the fact that by default (unless you passed through a GPU into the VM) you’ll be using the vesa driver. This is fine for what I’m doing, I just want to expose more resolution options.

To fix this, you need to manually configure Xorg with the snippet below.

First, create the xorg.conf directory. Note, these commands need to be done as the root user

mkdir /etc/X11/xorg.conf.d

Then copy/paste the below into your terminal.

cat > /etc/X11/xorg.conf.d/10-virtual.conf <<EOF
Section "Device"
  Identifier   "Virtual-Card"
  Driver       "vesa"
  VendorName   "InnoTek"
  BoardName    "Virtual Graphics Adapter"
Section "Monitor"
  Identifier   "Virtual-Monitor"
  VendorName   "InnoTek"
  ModelName    "Virtual Screen"
  HorizSync    1.0 - 1000.0
  VertRefresh  1.0 - 1000.0
Section "Screen"
  Identifier   "Virtual-Screen"
  Device       "Virtual-Card"
  Monitor      "Virtual-Monitor"
  DefaultDepth 24
  SubSection "Display"
    Viewport   0 0
    Depth      24
    Modes "1600x900" "1368x768" "1360x768" "1280x800"

Finally, just restart xenodm

rcctl restart xenodm

Finding Idle Cloud Desktops (Linux)

Suppose you’re hosting remote Linux desktops in your cloud environment and want to discover which ones could be able to shutdown to save on valuable resources like money, RAM, or CPU.

Most Linux remote desktop protocols still utilize Xorg (as opposed to Wayland) for their display server. Prime examples would be tigervnc, tightvnc, or X2go. Because of this, the utility xprintidle is still useful for determining how long an X session has been idle, as its name suggests. With it, we can automate the discovery process with a simple script, querying each desktop to see when it was last used. This assumes you have permissions on the host to run commands as the user actually running the X server (or have access to their .Xauthority file).

Depending on your infrastructure you might choose to run something like the below script via SSH, Ansible, Salt Stack, Puppet, or something else.

This is a rough example and assumes the username is the same on all hosts. You’ll likely have different usernames on each host so you’d need to adjust the script to filter out the users and corresponding display number.

#!/usr/bin/env bash
# A contrived example of checking for idle X sesssions on remote systems.

HOSTS="host1 host2 host3"
USER=shaner  # the user running the X session
DISPLAY=:1  # typical/default display for most VNC servers
XPIPATH=./xprintidle  # path to 'xprintidle' binary.

for h in ${HOSTS}; do
  echo "put ${XPIPATH} /usr/local/bin/" | sftp -b- root@$h >/dev/null
  IDLE=$(ssh root@$h sudo -u ${USER} DISPLAY=${DISPLAY} /usr/local/bin/xprintidle)
  IDLE=$(echo $IDLE/1000/60 | bc)
  printf "[*] ${USER}@${h}:${DISPLAY} idle for ${IDLE} minutes\n"

Here’s what it looks like in practice. From the output, we could probably shutdown host1 for the time being.

$ ./
[*] shaner@host1:1 idle for 18564 minutes
[*] shaner@host2:1 idle for 20 minutes
[*] shaner@host3:1 idle for 108 minutes