Nur Rony
Polyglot Programmer, DevOps and Forever Learner

Update VirtualBox Guest Additions in Vagrant Box

Update VirtualBox Guest Additions in Vagrant Box

Sometimes We need to upgrade the guest edition for our Vagrant box working properly with virtualbox provider. Without proper Virtualbox Guest Addition Vagrant sometimes does not provide shared file functionality and does problem with group and/or user permissions.

The Problem

Today when i run vagrant up --provision command on my shell. Vagrant gives me following errors

Failed to mount folders in Linux guest. This is usually because  
the "vboxsf" file system is not available. Please verify that  
the guest additions are properly installed in the guest and  
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant  
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

There may be another warning message where you also need to update Virtualbox Guest Additions

[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  
Guest Additions Version: 4.2.8  
VirtualBox Version: 5.0.12  

The Solution

I run the following command to update my vagrant box guest Addition.

nurrony@devmachine:vagrant-playbox$ vagrant up  
#Let it finish the initial tasks to boot up your vagrant box
nurrony@devmachine:vagrant-playbox$ vagrant ssh  
vagrant@vagrant-playbox:~$ sudo yum -y update  
vagrant@vagrant-playbox:~$ cd /opt  
vagrant@vagrant-playbox:~$ sudo wget -c -O VBoxGuestAdditions_5.0.12.iso  
vagrant@vagrant-playbox:~$ sudo mount VBoxGuestAdditions_5.0.12.iso -o loop /mnt  
vagrant@vagrant-playbox:~$ cd /mnt  
vagrant@vagrant-playbox:~$ sudo sh --nox11  
vagrant@vagrant-playbox:~$ cd /opt  
vagrant@vagrant-playbox:~$ sudo rm *.iso  
vagrant@vagrant-playbox:~$ sudo /etc/init.d/vboxadd setup  
vagrant@vagrant-playbox:~$ sudo chkconfig --add vboxadd  
vagrant@vagrant-playbox:~$ sudo chkconfig vboxadd on  
vagrant@vagrant-playbox:~$ exit

# Now check that the Guest Additions work
nurrony@devmachine:vagrant-playbox$ vagrant halt 

Now run the vagrant up command. The error/warning message should be gone.

That's all.. Enjoy!!