OpenBSD in LXD

  1. Creating the VM instance
  2. Installing OpenBSD
  3. Running OpenBSD
  4. Optional Setup
  5. Sources

Creating the VM instance

First, we need to create a LXD instance for our OpenBSD virtual machine. There currently aren't any prebuilt cloud images so we start with an empty instance and install OpenBSD from the official USB installer image.

$ lxc init openbsd --empty --vm -c limits.cpu=4 -c limits.memory=4GiB -c migration.stateful=true -c security.secureboot=false

LXD uses a default root disk size of 10 GiB. If necessary, we can change the disk size using lxc-config(1).

$ lxc config device override openbsd root size=20GiB size.state=4GiB

Next we need to make the OpenBSD installer disk available to the VM. Because there are no pre-built images we download the official OpenBSD installer from a public ftp mirror. A full list of mirrors is available at [3]. We can use wget(1) to fetch the OpenBSD 7.3 installer image for the x86_64 CPU architecture:

$ wget

Next we need to instruct LXD to mount the installer image as a disk in our virtual machine. Setting the boot priority to 10 makes sure that the installer is selected as the boot device on first boot.

$ lxc config device add openbsd install disk source=/home/user/install73.img boot.priority=10

Installing OpenBSD

OpenBSD uses a text based installer, so a text console should be sufficient for the next steps. Alternatively --console=vga attaches a graphical console.

$ lxc start openbsd --console

Before booting into the actual installer we are greeted with the OpenBSD bootloader command line boot(8).

We need to manually configure the correct serial output device, otherwise the OS won't print any output to our attached text console. The boot command resumes booting the default entry.

>> OpenBSD/amd64 BOOTX64 3.64
boot> set tty com0
boot> boot

Next we see the kernel boot log and finally we are dropped into the installer shell. To start a clean installation press I and answer the questions presented by the installer.

Welcome to the OpenBSD/amd64 7.3 installation program.
(I)nstall, (U)pgrade, (A)utoinstall or (S)hell?

Most answers will depend on your personal preference such as username, password initial X server setup, partitioning etc. If you aren't sure what to choose the default is usually a good choice. Make sure to change the default console to com0 and pick a reasonable baud rate.

Change the default console to com0? [yes]
Available speeds are: 9600 19200 38400 57600 115200.
Which speed should com0 use? (or 'done') [9600] 115200

Once the installer is done you get the option to drop into a shell, halt or reboot the machine. Instead of rebooting, shut down the machine with H.

CONGRATULATIONS! Your OpenBSD install has been successfully completed!

When you login to your new system the first time, please read your mail
using the 'mail' command.

Exit to (S)hell, (H)alt or (R)eboot? [reboot] H

Once the machine is offline we need to detach the installer disk. After this the machine should be ready to boot into our newly installed system.

$ lxc config device remove openbsd install

Running OpenBSD

We can now start the new VM with lxc start.
lxc start openbsd

OpenBSD currently does not support lxc-agent so we can't use the lxc-execute(1) command. Instead, you can either use a console or ssh to connect to your machine.

If you have set up ssh access in the installer dialog you can find your machine's IP with lxc-info(1) and then connect via ssh(1):

$ lxc info openbsd | grep inet
        inet: (global)
$ ssh user@

If ssh is not available you can attach a console to a running machine using lxc-console(1):

$ lxc console openbsd
To detach from the console, press: +a q

OpenBSD/amd64 (foo.lxd) (tty00)


Optional Setup

If you are planning to use ssh you might want to setup a mdns daemon on your VM to use the machine's hostname instead of the IP address when connecting via ssh. A popular OpenBSD compatible implementation is openmdns which is available as a binary package.

# pkg_add openmdns

Once the package is installed, you can find more information at /usr/local/share/doc/pkg-readmes/openmdns. For a simple configuration run:

# echo "mdnsd_flags=vio0\nmulticast=YES" >> /etc/rc.conf.local
# rcctl enable mdnsd
# rcctl start mdnsd

The machine should now be reachable from the LXD host via its hostname.

$ ssh openbsd.local


[1] Youtube: BSD in a LXD VM
[2] Discourse: Install any OS via ISO in a Virtual machine
[3] OpenBSD: Mirrors