(: November 24, 2018)
This is a short tutorial on how to create a Vagrant machine from existing Virtualbox Virtual Machine. Vagrant tool gives you the best environment to manage and control your Virtual Machines. This works on any Linux Distribution
Installing Vagrant box from scratch may not be an efficient way if you already have a running Virtualbox Vm from same Base os as the vagrant box. Additionally, you’ll save bandwidth if you have updated pre-existing Vm and maybe installed additional packages that you’ll like to have on new Vagrant controlled Virtual Machine.
Create a directory for vagrant boxes
mkdir -p ~/vagrant cd ~/vagrant mkdir centos-server-7.1
In our example, we’ll use an existing Virtualbox CentOS 7.1 server. This Virtual Machine is updated and have Asterisk Pbx installed. To use this trick we’ll also need the following software installed.
- Vagrant
- Virtualbox
You can download centos 7.1 vagrant box from the Link Vagrant Centos 7.1.box
or use wget to download it.
wget https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.1/vagrant-centos-7.1.box
Once the download is finished, move it to ~./Vagrant/centos-server-7.1
mv vagrant-centos-7.1.box ~./vagrant/centos-server-7.1
If you don’t have Virtualbox installed, you can use our articles:
For Fedora: Read How to Install Virtualbox on Fedora 23
For Debian and Ubuntu: How to install Virtualbox Latest on Ubuntu and Kali Linux
If you Love what we do, support us by downloading this tutorial as pdf from the link below:
NOTE: Make sure your Virtualbox VM i.e in my case Centos-asterisk server have a username called “vagrant” with password “vagrant”. If not you can add it
using the script below.
vim adduser.sh
Paste the code below and save the file.
Make the script executable and run it.
chmod +x adduser.sh ./adduser.sh
Add user account before copying .vmdk file then do the following:
1. Change to directory containing CentOS vagrant box you downloaded.
cd ~/vagrant/centos-server-7.1
2. Generate Vagrantfile
vagrant init
3.Edit the name of the box inside Vagrantfile to be “centos-server-7.1”
vim Vagrantfile
Your line 15, should be similar to one below
config.vm.box = "centos-server-7.1"
4. Add the vagrant box to your Environment with the name of a box we specified on Vagrantfile
vagrant box add centos-7.1-x86_64.box --name centos-server-7.1
5. Bring the added vm up
vagrant up

cd ~/VirtualBox VMs/ ls
Mine is under centos-asterisk folder. With the name of vmdk as centos-asterisk-disk1.vmdk.We need to copy this file to the directory containing vagrant vm we added “centos-server-7.1”.
6. Now rename your added VM on Virtualbox Gui. Before you can rename you have to turn it off.
cd ~/vagrant/centos-server-7.1 vagrant halt
To rename go to Virtual Machine > General > Basic > Name.See screenshots below.
7. Next thing to do is copy centos-asterisk-disk1.vmdk to box-disk1.vmdk. Make sure the Virtual Machine is off, if not turn it off.
cp ~/VirtualBox VMs/centos-asterisk/centos-asterisk-disk1.vmdk ~/VirtualBox VMs/centos-server-7.1/box-disk1.vmdk
8. Now start vagrant box
cd ~/vagrant/centos-server-7.1 vagrant up vagrant ssh
9. Install Virtualbox Guest Addtions on the guest OS.
From Host computer, copy to VBoxGuestAdditions.iso ~/vagrant/centos-server-7.1. Then on Guest OS run
mount -o loop /vagrant/VBoxGuestAdditions.iso /mnt sh /mnt/VBoxLinuxAdditions.run umount /mnt
If you Love what we do, support us by downloading this tutorial as pdf from the link below:
Enjoy your Vagrant environment.
How to add, install and run CentOS 7 Vagrant box to Virtualbox using Vagrant