The following describes how to set up bhyve with Vagrant using the vagrant-bhyve plugin.
You will need
- FreeBSD >= 11.0
- A bhyve [capable CPU] 1
- For this tutorial a clean /etc/pf.conf (XXX check if that's really needed)
- A working internet connection to download the vagrant boxes
To use bhyve you first need to load the vmm.ko kernel module:
# kldload vmm
If you want to load this module at boot time, add it to the list of modules in /etc/rc.conf:
# sysrc kld_list+="vmm"
Install a couple of needed packages:
# pkg install sudo dnsmasq linuxfdisk qemu-utils vagrant rubygem-vagrant-mutate rubygem-vagrant-bhyve grub2-bhyve coreutils linuxfdisk
I do not know if these steps are correct (we already installed the vagrant-bhyve and vagrant-mutate packages in the last step) but without installing the plugins the bhyve provider cannot be found.
$ vagrant plugin install vagrant-bhyve
$ vagrant plugin install vagrant-mutate
Now it's time to download a vagrant box, for example a Ubuntu 14.04 (Trusty Tahr) box:
$ vagrant box add ubuntu/trusty64 --provider virtualbox
We only have a Virtualbox box, so we need to convert (mutate) the box into the bhyve format and remove the Virtualbox one:
$ vagrant mutate ubuntu/trusty64 bhyve
$ vagrant box remove ubuntu/trusty64 --provider virtualbox
We now start the first vagrant-bhyve box!
$ mkdir -p ~/vagrant/trusty64
$ cd ~/vagrant/trusty64
$ vagrant init ubuntu/trusty64
$ vagrant up --provider bhyve
You should see some output that the box is being started. Depending on your sudo(1) configuration you are prompted for your user password, because some tasks (starting pf, dnsmasq and bhyve) need root credentials.
The last step is to ssh in to the freshly created and started box:
$ vagrant ssh
And voilà , you should be greeted by the Ubuntu VM.
To get it to work I had to use vagrant version 2.3.6 and ruby 3.2.3.
This will help
https://developer.hashicorp.com/vagrant/docs/installation/source