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 . We can use wget(1) to fetch the OpenBSD 7.3 installer image for the x86_64 CPU architecture:
$ wget https://ftp.openbsd.org/pub/OpenBSD/7.3/amd64/install73.img
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
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')  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
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: 10.46.11.244/24 (global) $ ssh email@example.com
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) login:
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