Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active October 17, 2023 12:02
Show Gist options
  • Save fernandoaleman/5083680 to your computer and use it in GitHub Desktop.
Save fernandoaleman/5083680 to your computer and use it in GitHub Desktop.
How to update VirtualBox Guest Additions with vagrant
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a 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.
#
# Guest Additions Version: 4.1.18
# VirtualBox Version: 4.2.8
$ vagrant ssh
vagrantup:~$ sudo yum -y update
vagrantup:~$ cd /opt
vagrantup:~$ sudo wget -c http://download.virtualbox.org/virtualbox/4.2.8/VBoxGuestAdditions_4.2.8.iso \
-O VBoxGuestAdditions_4.2.8.iso
vagrantup:~$ sudo mount VBoxGuestAdditions_4.2.8.iso -o loop /mnt
vagrantup:~$ cd /mnt
vagrantup:~$ sudo sh VBoxLinuxAdditions.run --nox11
vagrantup:~$ cd /opt
vagrantup:~$ sudo rm *.iso
vagrantup:~$ sudo /etc/init.d/vboxadd setup
vagrantup:~$ sudo chkconfig --add vboxadd
vagrantup:~$ sudo chkconfig vboxadd on
vagrantup:~$ exit
# Now check that the Guest Additions work
$ vagrant halt
$ vagrant up
# Package the new VM
$ vagrant halt
$ vagrant package
$ mv package.box centos-6.3.box
@Theaxiom
Copy link

Theaxiom commented Sep 5, 2015

Make sure you do this before you shut down: echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > .ssh/authorized_keys

@Dinakaran-Ulaganathan
Copy link

Perfect :)

@krutcha
Copy link

krutcha commented Feb 5, 2016

This does not seem to work for me, perhaps I am doing it wrong. I used a basebox (precise32), then uninstalled the guest additions, installed the kernel headers, dkms, etc, and latest guest additions (5.0.10). I then ran the guest additions. After exiting and halting, I did a vagrant package. When I deploy this new .box (vagrant box add, vagrant init, vagrant up).. it has the OLD guest additions it seems every time. Is there something special needed to make the modified additions stick in a 'package'?

@shovon
Copy link

shovon commented Feb 11, 2016

@krutcha this guide is for CentOS, not Ubuntu.

@surendba
Copy link

Thanks for that tip.It worked like charm!
Saved me many hours of investigation.

@mtd3sign
Copy link

Hi guys, I'm sorry I'm pretty late to this party.

I have two apparent issues with Vagrant: the guest additions not matching and the NFS mount error. When I run Vagrant Up/Reload I get this...

Mathews-MacBook-Pro:ansible mathewthomas$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Removing hosts
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> default: have version '20160323.0.0'. The latest is version '20160509.1.0'. Run
==> default: `vagrant box update` to update.
==> default: VirtualBox VM is already running.
Mathews-MacBook-Pro:ansible mathewthomas$ vagrant reload
==> default: Removing hosts
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> default: have version '20160323.0.0'. The latest is version '20160509.1.0'. Run
==> default: `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    **default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.3.36
    default: VirtualBox Version: 5.0**
==> default: Checking for host entries
==> default: Skipping adding host entries (config.vm.network hostsupdater: "skip" is set)
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Exporting NFS shared folders...
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
**The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o 'vers=3,udp' 192.168.50.1:'/Users/mathewthomas/Sites/eightloop/site' /vagrant-nfs-eightloop.io
Stdout from the command:

Stderr from the command:

mount.nfs: requested NFS version or transport protocol is not supported**

I have been having trouble for a few days. Do you think these isses could be related?

Thanks.

@mtd3sign
Copy link

Sorted.

I just ran 'vagrant ssh', 'apt-get update', and 'apt-get install nfs-common nfs-kernel-server'.

Ran like a dream.

Sorry to bother you, cheers.

@axd1967
Copy link

axd1967 commented Sep 8, 2017

"sudo /etc/init.d/vboxadd setup" : "command not found".

edit added: this gist requires some extra one-time preparatory steps ...

@neverkas
Copy link

neverkas commented Apr 9, 2021

Can you help me? It can't find that path

sudo: /etc/init.d/vboxadd: command not found```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment