My notes from when I had this problem are a bit spotty, so there might be gaps in my information, but I think the solution I ended up using is pretty clear.
One of the things Vagrant does is syncs everything in your project folder to /vagrant
on the VM. For some reason this was not working for me when using the ubuntu/xenial64
image. My final solution ended up not needing this, but at this point I did need it and either way it was weird that it wasn't working.
I was also getting this error during the start of my vagrant up
:
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims: 5.0.18
VBoxService inside the vm claims: 5.1.2
Going on, assuming VBoxService is correct...
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims: 5.0.18
VBoxService inside the vm claims: 5.1.2
Going on, assuming VBoxService is correct...
==> dev: Checking for guest additions in VM...
dev: The guest additions on this VM do not match the installed version of
dev: VirtualBox! In most cases this is fine, but in rare cases it can
dev: prevent things such as shared folders from working properly. If you see
dev: shared folder errors, please make sure the guest additions within the
dev: virtual machine match the version of VirtualBox you have installed on
dev: your host and reload your VM.
dev:
dev: Guest Additions Version: 5.0.18_Ubuntu r106667
dev: VirtualBox Version: 5.1
I didn't write down how I came to this conclusion but I apparently found that my VM had the wrong version of VirtualBox Guest Additions installed. I installed vagrant-vbguest to fix this:
vagrant plugin install vagrant-vbguest
I ran vagrant up
and got the version mismatch error again, and the /vagrant
folder still was not mounted.
I found instructions on how to install VirtualBox Guest Additions manually here https://gist.github.com/fernandoaleman/5083680 so I made a new Vagrant setup with a blank Xenial64 image and tried this:
cd /opt
sudo wget -c
http://download.virtualbox.org/virtualbox/5.1.2/VBoxGuestAdditions_5.1.2.iso
-O VBoxGuestAdditions_5.1.2.iso
sudo mount VBoxGuestAdditions_5.1.2.iso -o loop /mnt
cd /mnt
sudo apt-get install -y build-essential linux-headers-$(uname -r)
sudo sh VBoxLinuxAdditions.run --nox11
This also did not give me a /vagrant
folder.
I then switched from ubuntu/xenial64
to gbarbieru/xenial and that finally fixed the problem.
I wasn't quite happy with this solution though as I would have to use a vanilla Xenial image on Digital Ocean and wanted my local environment to be as similar to that as possible.
ubuntu/xenial64
and vagrant-vbguest
I changed my Vagrant image back to ubuntu/xenial64
and tried to solve the problem manually. I shelled into my vagrant box and ran the following to install VBGuestAdditions:
sudo apt-get update
sudo apt-get install linux-headers-$(uname -r) build-essential dkms
cd /opt
sudo wget http://download.virtualbox.org/virtualbox/5.1.2/VBoxGuestAdditions_5.1.2.iso
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_5.1.2.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
sudo rm VBoxGuestAdditions_5.1.2.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions
I had hoped to package this into a reusable image using vagrant package --base helm108/xenial64
but my notes at the time claim that:
I think I thought that provisioning scripts were put on the box through the /vagrant
folder and so I had no way of scripting the box. That isn't actually the case, the provisioners add their code via their own ssh connections, but I did not know that yet!
I went back to the vagrant-vbguest
plugin and read the documentation a bit more carefully. I saw that I could specify a URL for the exact ISO image that it should download and use:
config.vbguest.iso_path = "http://download.virtualbox.org/virtualbox/5.1.2/VBoxGuestAdditions_5.1.2.iso"
Which worked perfectly. I was still getting a version mismatch error during vagrant up
but everything was working.
A bit more reading lead me to this:
config.vbguest.iso_path = "http://download.virtualbox.org/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"
The version
variable is version of the VirtualBox host. This solution means that it should continue to work perfectly as I change host versions without requiring manual updating of the version number.
I was still getting the initial version mismatch error, but my /vagrant
folder existed so job done.