Installing Virtualbox Guest Additions On a Vagrant Lucid64 Box

I’ve been working through the new Deploying Rails book and found that the Ubuntu lucid64 image installed by Vagrant doesn’t come bundled with the latest version of the VirtualBox Guest Additions. I’ll walk through the steps necessary to install the latest version of the Guest Additions via the command line on your freshly built lucid64 box.

Here’s a summary of the commands to issue. A detailed explanation follows, but if you just want the quick-and-dirty then ssh into your new box (defaults to 127.0.0.1, port 2222, username: vagrant, password: vagrant) and issue these commands:

wget -c http://download.virtualbox.org/virtualbox/4.1.8/VBoxGuestAdditions_4.1.8.iso
sudo umount /mnt
sudo mount VBoxGuestAdditions_4.1.8.iso -o loop /mnt
sudo apt-get update
sudo apt-get install dkms
sudo apt-get install linux-headers-$(uname -r)
sudo sh /mnt/VBoxLinuxAdditions.run
sudo restart

Now the blow-by-blow explanation.

When you run vagrant up you’ll get an error message explaining that the guest additions don’t match the installed version of Virtualbox. Note that I’m running this from the command line on a Windows 7 machine.

> vagrant up
[default] Importing base box 'lucid64'...
[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: 4.1.0
VirtualBox Version: 4.1.8
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[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

The first thing to do is ssh into your new box. Normally this will be on 127.0.0.1 port 2222 (username: vagrant, password: vagrant) unless you’ve specified something else in your Vagrantfile. Once into the box issue the command:

wget -c http://download.virtualbox.org/virtualbox/4.1.8/VBoxGuestAdditions_4.1.8.iso

to download the guest additions (4.1.8 is the current version as of this writing — see the error message when you run vagrant up for the version installed on your host machine).

Next we try and mount the guest additions .iso image and run the installer:

sudo umount /mnt
sudo mount VBoxGuestAdditions_4.1.8.iso -o loop /mnt
sudo sh /mnt/VBoxLinuxAdditions.run

Verifying archive integrity... All good.
Uncompressing VirtualBox 4.1.8 Guest Additions for Linux..........
VirtualBox Guest Additions installer
Removing installed version 4.1.0 of VirtualBox Guest Additions...
tar: Record size = 8 blocks
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.

Building the main Guest Additions module ...fail!
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions ...done.
Installing the Window System drivers ...fail!
(Could not find the X.Org or XFree86 Window System.)

If you look in /var/log/vboxadd-install.log you’ll see the error message

/tmp/vbox.0/Makefile.include.header:94: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR= and run Make again. Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

Easy enough to fix. Run the following commands to install the linux kernel sources:

sudo apt-get update
sudo apt-get install dkms
sudo apt-get install linux-headers-$(uname -r)

Now that all the pieces are in place (if you miss one you’ll see another error in /var/log/vboxadd-install.log) you can install the guest additions:

sudo sh /mnt/VBoxLinuxAdditions.run

Verifying archive integrity... All good.
Uncompressing VirtualBox 4.1.8 Guest Additions for Linux..........
VirtualBox Guest Additions installer
Removing installed version 4.1.8 of VirtualBox Guest Additions...
tar: Record size = 8 blocks
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

Installing the Window System drivers ...fail!
(Could not find the X.Org or XFree86 Window System.)

You’re done! Since we’re running this server without a GUI you don’t have to worry about the “Could not find the X.Org or XFree86 Window System” error message. If you do have any more problems then refer to /var/log/vboxadd-install.log for the source of any errors.

Now just restart your box:

sudo restart

or run:

> vagrant halt
> vagrant up

from the host command line.

This entry was posted in Uncategorized. Bookmark the permalink.

11 Responses to Installing Virtualbox Guest Additions On a Vagrant Lucid64 Box

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WP Hashcash