This will guide you on packaging existing environments to use with Vagrant, replacing the shared disk with a new box file. These box files can make managing virtual machines and different versions of these virtual machines vastly simpler, especially, if you don’t want to build environments from base boxes every time.

Last time I talked about How to add, install and run CentOS 7 Vagrant box to Virtualbox using Vagrant and How to set Default Vagrant Provider to Virtualbox on Linux; Fedora,Debian,Ubuntu

In this example, I’ll use an existing Virtual  Machine Environment build with Oracle Virtualbox where I’ll choose an existing environment based on the CentOS 7 operating system that has been created as a VirtualBox machine, the name of the Virtual Machine is openstack-controller shown in the screenshot below.

vagrant 1

There is a user account present on the machine that we want to reuse. The
credentials are:

Username: vagrant
Password: vagrant

NOTE: My Existing virtual machine has ssh installed and configured. Before packaging your Virtual Machine, make sure you have an installed ssh.
Now navigate to the folder containing Virtualbox’s Virtual Machines; mine is /home/josepy/VirtualBox VMs/

cd /home/josepy/VirtualBox VMs/

Check the presence of the Virtual Machine you want to package with ls command.


Now package and export the Virtual machine.

 vagrant package --base=openstack-controller

–output=” The name you want to give to packaged box”
After the box has been packaged successfully, we should create a folder to house vagrant environment.

mkdir -p ~/vagrant
cp ~/vagrant
cd ~/vagrant

Then import the box into your environment.

vagrant box add --name=openstack-asterisk
vagrant add

This command will copy the box to your local Vagrant cache, so you are now ready to directly use the box.
Edit the box name in Vagrantfile to match  one added above. Mine is openstack-asterisk.

vagrant init
vi Vagrantfile

Then Edit on line 15.See screenshot below.

vagrant box name

Start added box by running vagrant up

vagrant up
vagrant up

You should now be able to ssh into it.

vagrant ssh
vagrant ssh

If your username and password was not
username: vagrant
password: vagrant

vim  Vagrantfile
Set username and password:
config.ssh.username = "username" config.ssh.password = " password"

vagrant ssh username

In case you encounter problem trying to ssh like “retrying…”. Do

vagrant up

Then after a persisting retrying to login problem start, hit CTL+C to cancel. This will keep Vagrant Virtual Machine running on background. Now, generate ssh keys and note its storage location.

 vagrant  ssh-config

You’ll get output similar to one below.

vagrant ssh generation

My ssh key is located in “/home/josepy/vagrant/centos-asterisk/.vagrant/machines/default/virtualbox/private_key” 
Add the location given above to the Vagrant file

vim  Vagrantfile

Start with the line
config.ssh.private_key_path=”Path given by ssh-config command”
My full line is:

config.ssh.private_key_path="/home/josepy/vagrant/centos-asterisk/.vagrant/machines/default/virtua    lbox/private_key"
config private key

Replace the path with yours.Next thing we’ll do is update VirtualBox Guest additions on the guest.
On virtualbox menu go to File > Virtual Media Manager > Optical Disks. You should see VBoxGuestAdditions iso file. If it doesn’t exixt, download it first.
For my case, its location is /home/josepy/.config/VirtualBox/VBoxGuestAdditions_5.0.12.iso

virtual media manager
I will copy above iso to the guest os. Follow steps below to achieve it.
1) Make sure the Guest OS is running and SSH server is installed and running as well.
2) If you’re not on local network, do port forwarding under networking option on VirtualBox Guest OS settings menu.
VirtualBox > centos-asterisk > Settings > Network > Adapter 1 > Port Forwarding.
Add rule if it doesn’t exist by clicking on + sign with following specifications.

Name: ssh
Protocol: TCP
Host IP:
Host port: 2222
Guest port: 22

Click on OK to save changes.


3) From your Host OS, copy VBoxGuestAdditions.iso file to Guest using scp

scp -P 2222 /home/josepy/.config/VirtualBox/VBoxGuestAdditions_version.iso [email protected]:~

Replace vagrant with your username of Guest OS.When asked
Are you sure you want to continue connecting (yes/no)? . Answer yes     

copy virtualbox guest additions to guest

4) On the Guest OS, mount the VBoxGuestAdditions_version.iso to /mnt

sudo su -
cd /home/vagrant
mount -o loop VBoxGuestAdditions_5.0.12.iso /mnt/
cd /mnt/


install guest additions

5) Logout and reload your VM by hitting CTL+D key twice, then

vagrant reload

You should now have a working Vagrant environment. That’s all, thanks for reading.
Hope this article was of help to you. If you encounter any problem/error, let me know by dropping it on Comments section.

How to add Vagrant box using Existing VirtualBox Virtual Machine
Vagrant VirtualBox Virtual Machine creation
Using Existing Virtual Machines with Vagrant
Vagrant quick Virtual Machone environment creation.

There is an alternative Method here

Easiest way to create Vagrant Box from existing Virtualbox VM 

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here