Upgrade VirtualBox Guest Additions in a Vargrant Base Ubuntu Box

[update:03-01-2011] Add OSE caveat [update:03-10-2011] Removed install virtualbox-ose-guest-dkms

This describes how to update Vagrant’s lucid64.box base box to the latest Guest Additions for VirtualBox 4.0.4. The only wrinkle was that the base box did not have the ppa:debfx/virtualbox repository configured.

Start The Old Vagrant VM

Make a backup and extract to a temporary folder:

$ mkdir tmp
$ cp lucid64.box tmp/lucid64.box
$ vagrant box add lucid64_4.0.4 lucid64.box
$ cd tmp
$ vagrant init lucid64_4.0.4
$ vagrant up

You should see message like:

[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.

It is this we aim to eliminate….

Update VirtualBox’s Guest Additions

$ vagrant ssh
vagrantup:~$ sudo apt-get update
vagrantup:~$ sudo apt-get install python-software-properties
vagrantup:~$ sudo add-apt-repository ppa:debfx/virtualbox
vagrantup:~$ cd /opt
vagrantup:~$ sudo wget -c http://download.virtualbox.org/virtualbox/4.0.4/VBoxGuestAdditions_4.0.4.iso \
                       -O VBoxGuestAdditions_4.0.4.iso
vagrantup:~$ sudo mount VBoxGuestAdditions_4.0.4.iso -o loop /mnt
vagrantup:~$ cd /mnt
vagrantup:~$ sudo sh VBoxLinuxAdditions.run --nox11
vagrantup:~$ cd /opt
vagrantup:~$ sudo rm *.iso
vagrantup:~$ exit

According to Brett Alton you can ignore the last error about the windows system driver’s failure to install, it should be harmless in non-GUI contexts.

Now check the Guest additions ‘just work’:

$ vagrant halt
$ vagrant up
[default] VM already created. Booting if its not already running...
[default] Running any VM customizations...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] Cleaning previously set shared folders...
[default] Creating shared folders metadata...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant

Excellent. No more warniings.

Package The New VM

$ vagrant halt
$ vagrant package
$ mv package.box lucid64_4.0.4.box

Done.

Caveats

An OSE version of guest additions seems to be only available via a Ubuntu package (virtualbox-ose-guest-x11) that has an X11 dependency. As of The Ruby gem virtualbox-0.8.3: Running a non-OSE Guest on a OSE Host (both VitualBox v4.0.4), with non-OSE Guest Additions installed, leads to this issue