back Creating an OpenBSD Vagrant box for libvirt

publication: outubro 24 2021 18:04
last update: outubro 24 2021 21:27


Create disk image:

$ qemu-img create -f qcow2 openbsd70.qcow2 128G
Formatting 'openbsd70.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=137438953472 lazy_refcounts=off refcount_bits=16

Proceed with your prefered install options using QEMU. As the default QEMU console was repeating keystrokes, I changed to the serial console during OpenBSD boot

>> OpenBSD/amd64 CDBOOT 3.53
boot> set tty com0
switching console to com0

and changed the view on View->Consoles->Serial 1 menu on QEMU.

After the install process we need to do some post install configuration.

post install config

Download Vagrant ssh key and add to the authorized_keys file:

$ ftp
$ cat vagrant-ssh-key >> /mnt/home/vagrant/.ssh/authorized_keys

The file content is:

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key

This is an insecure public key which will be used by Vagrant on the first access and replaced later.

Create hostname.if depending on the network interface:

$ echo "autoconf" > /mnt/etc/hostname.vio0
$ echo "autoconf" > /mnt/etc/hostname.em0
$ echo "autoconf" > /mnt/etc/hostname.run0
$ echo "autoconf" > /mnt/etc/hostname.hvn0

We are good to shutdown now.

creating the box

I used the from the vagrant-libvirt repository.

Create the Vagrantfile with at least these two lines and any other config you wish:

Vagrant.configure("2") do |config| = "ksh"
    config.vm.synced_folder ".", "/vagrant", disabled: true

Creating the box:

$ openbsd70.qcow2 Vagrantfile
==> Creating box, tarring and gzipping
Total de bytes escritos: 3185121280 (3,0GiB, 189MiB/s)
==> created
==> You can now add the box:
==>   'vagrant box add --name openbsd70'

Adding the box to Vagrant:

$ vagrant box add --name openbsd70

running the new machine

$ vagrant init openbsd70
$ vagrant up

get in touch