VirtualBox Guest Additions and vagrant
If you followed my blog, you probably know about chef and vagrant.
So the other day I managed to upgrade to VirtualBox 4.0. The upgrade just happened by accident, so to speak. I noticed that Virtualbox 4.0 had moved from nonfree to contrib on Oracle's repository which is why I had previously missed it. With 4.0, I am now able to run the latest and greatest Vagrant — and with Vagrant being pre-1.0 it's safe to assume that newer is indeed better.
Anyway — the VirtualBox update fubar'd all of my boxes. They didn't outright refuse to start, but provisioning failed nine out of ten times and other random issues seemed to pile up.
I noticed this warning about the Guest Additions inside the box and how they are different from the VirtualBox installed on the host:
[default] The guest additions on this VM do not match the install version of VirtualBox! This may cause things such as forwarded ports, shared folders, and more to not work properly. If any of those things fail on this machine, please update the guest additions and repackage the box. Guest Additions Version: 3.y.z VirtualBox Version: 4.0.8
To cut to the chase — once I updated them and the box itself, they all continued to work.
So here's how!
Boot a blank VM
So first off, you take the image of your choice and boot a blank virtual machine. Blank because no chef-recipes should be configured, etc.. This VM should literally boot in a minute or so.
Now enter the VM and update the Guest Additions, and while we're at it, feel free to update the OS etc. as well.
Update the base
On my Ubuntu Karmic box, this is what I did (inside the VM) first:
vagrantup:~$ sudo aptitude update ... vagrantup:~$ sudo aptitude upgrade ... vagrantup:~$ sudo gem update --no-rdoc --no-test --no-ri ... vagrantup:~$ sudo aptitude install portmap nfs-common ...
Pro-tip: The last step is necessary in case you run into the various issues with VirtualBox shared folders. The official website lists performance as the #1 one reason to use NFS shares instead of the VirtualBox shares, my #1 reason was issue #351.
Update Guest Additions
It took me a lot of Google, to actually find the download — regardless this is what seems to work. I extracted these steps from the blog post I found. For this to work, you are still inside the VM:
vagrantup:~$ wget -c \ http://download.virtualbox.org/virtualbox/4.0.8/VBoxGuestAdditions_4.0.8.iso \ -O VBoxGuestAdditions_4.0.8.iso ... vagrantup:~$ sudo mount VBoxGuestAdditions_4.0.8.iso -o loop /mnt vagrantup:~$ sudo sh /mnt/VBoxLinuxAdditions.run --nox11 ... vagrantup:~$ rm *.iso
There's an error about something failing to install (Windows-related), but I ignored it since I don't run the GUI anyway.
Pro-tip: Installing the latest vagrant along with Virtualbox 4.0.8 made the GUI mode fail consistently. Not that I really mind, but I feel compelled to share.
Repackage
Once these steps are completed, exit the VM (ctrl+d), halt the VM and up to test. If the VM starts up and no warnings show up, you got yourself a winner.
To repackage the VM, do the following:
~/karmic-test$ vagrant package
This creates a package.box
file — I renamed mine to karmic-nfs.box
. Import the box with:
~/karmic-test$ vagrant box add karmic-nfs karmic-nfs.box [vagrant] Downloading with Vagrant::Downloaders::File... [vagrant] Copying box to temporary location... [vagrant] Extracting box... [vagrant] Verifying box... [vagrant] Cleaning up downloaded box...
Done!
Fin
That's all, in summary the biggest obstacles are as follows:
- VirtualBox on the host and VirtualBox Guest Additions inside the box need to match (closely).
- The box needs to be kept up to date — more or less recent software inside the box makes bootstrapping and provisioning easier and faster.