Creating an OpenBSD Box for Vagrant: A Personal Guide

· 832 words · 4 minute read

As someone who enjoys exploring different operating systems, I often find myself setting up environments in OpenBSD. It’s an elegant and minimalist OS with a strong emphasis on security, which makes it ideal for a variety of use cases. Recently, I worked on creating an OpenBSD box for Vagrant, and I thought I’d share the step-by-step process I followed, along with a few quirks and tips I discovered along the way.

Below is my personal take on setting up OpenBSD 7.5 for Vagrant using VirtualBox.

VirtualBox Configuration 🔗

First off, let’s dive into the VirtualBox configuration. These settings are crucial to ensure that the installation process runs smoothly and that Vagrant works efficiently with your OpenBSD box.

  • Disk size: Set this to 16GB. This is a modest size that balances storage space without over-allocating resources.
  • Chipset: Use ICH9. Through trial and error, I discovered this chipset is essential for a seamless OpenBSD installation. Without it, you might face unpredictable behaviors.
  • Hardware clock in UTC: Set this to True. OpenBSD prefers the hardware clock to be in UTC, and this helps avoid potential time-sync issues.
  • Disable audio and USB: Since OpenBSD doesn’t need audio or USB in this configuration, it’s better to turn them off for a leaner virtual machine.

Base Installation Process 🔗

Now that we have the virtual machine set up, it’s time to install OpenBSD. Here’s where things get a little tedious but totally worth it. You’ll need to customize the disk layout to suit Vagrant’s requirements. Here’s the breakdown:

  1. /: Set this to 250MB for the root partition.
  2. swap: Allocate 80MB for swap. OpenBSD is lightweight, so this amount works fine for a Vagrant box.
  3. /tmp: Assign 512MB for temporary files.
  4. /usr: Set 2GB for user-related binaries and libraries.
  5. /usr/X11R6: Although we won’t be installing X Windows, allocate 256MB here just in case you need it later.
  6. /usr/local: This will house local software installations. I’ve given it 2GB.
  7. /home: I set this to 1GB for home directories.
  8. /vagrant: Assign 1GB specifically for the Vagrant synced folder.
  9. /var: Use whatever remains for /var, where logs and other dynamic data will live.

Custom Choices 🔗

  • No X Windows: Since this is a server setup, we won’t be installing X Windows. It saves space and resources.
  • vagrant user: Vagrant requires a user named vagrant, so create this user during the setup. This step will ensure that Vagrant can SSH into the box and run provisioning scripts smoothly.

Installing Additional Software 🔗

Once OpenBSD is installed and running, the next step is to install some essential software packages that will make the Vagrant box usable.

First, give OpenBSD some time to relink its kernel. You can monitor the process using:

# less /usr/share/relink/kernel/GENERIC.MP/relink.log

Once it’s done, you’ll see:

Kernel has been relinked and is active on next reboot.

Now, install the necessary packages using the following commands:

# syspatch
# pkg_add sudo bash rsync

Here’s why these are important:

  • sudo: OpenBSD doesn’t come with sudo by default, but it’s needed for Vagrant provisioning.
  • bash: Vagrant typically expects bash as the default shell, so you’ll need to install it. OpenBSD defaults to ksh, but you can switch this by installing bash.
  • rsync: Required for efficient file syncing between your host and the VM.

Configuring sudo for Vagrant 🔗

Next, you’ll need to give the vagrant user passwordless sudo privileges. Edit the sudoers file:

# visudo

Add the following line:

vagrant ALL=(ALL) NOPASSWD: ALL

This allows Vagrant to run commands as root without requiring a password, which is crucial for smooth operation.

Setting Up SSH and NoDNS 🔗

Vagrant uses SSH to communicate with the virtual machine. You’ll need to ensure that SSH is properly configured and secure. Edit the sshd_config file to disable DNS lookups for faster SSH connections:

/etc/ssh/sshd_config

Add or modify this line:

UseDNS no

Additionally, make sure to add Vagrant’s insecure public key to the authorized keys file:

$ vi .ssh/authorized_keys

This allows Vagrant to SSH into the VM without a password.

Packaging the OpenBSD Box for Vagrant 🔗

Once everything is set up and working, it’s time to package your OpenBSD VM into a Vagrant box. This is done using the vagrant package command:

$ vagrant package --base minibsd

This will create a .box file that you can distribute or reuse with Vagrant.

Bringing the Box to Life with Vagrant 🔗

To start using your new OpenBSD box, you’ll need to initialize it in Vagrant. Start by creating a Vagrantfile:

$ vagrant init minibsd ../box/openbsd75-mini.box

Then, configure the synced folder to use rsync for file sharing:

    config.vm.synced_folder ".", "/vagrant", type: "rsync"

That’s it! Now you can run vagrant up to bring your OpenBSD environment to life.


I hope this guide helps you set up your own OpenBSD Vagrant box. I’m a huge fan of exploring different operating systems, and OpenBSD continues to be a rewarding experience for me. If you enjoy minimalism and security, I encourage you to give this a try. Let me know if you run into any quirks—after all, that’s part of the fun!