In this simple example, we are going to backup up our vagrant box and then restore it.


Backup


Assume that your vagrant box path is /Users/inanzzz/Webserver/php7/ so it would look line mac:php7 inanzzz$ in terminal.


Exit


mac:php7 inanzzz$ vagrant halt
==> php7: Attempting graceful shutdown of VM...

Restore


mac:php7 inanzzz$ vagrant package
==> php7: Clearing any previously set forwarded ports...
==> php7: Exporting VM...
==> php7: Compressing package to: /Users/inanzzz/Webserver/php7/package.box

As you can see above, our box has been backed up as package.box.


Destroy


mac:php7 inanzzz$ vagrant destroy
php7: Are you sure you want to destroy the 'php7' VM? [y/N] y
==> php7: Destroying VM and associated drives...
==> php7: Pruning invalid NFS exports. Administrator privileges will be required...

Current content


mac:php7 inanzzz$ ls -l
-rw-r--r--@ 1 inanzzz staff 578 23 Jun 16:36 Vagrantfile
-rw-r--r-- 1 inanzzz staff 628388089 23 Jun 16:44 package.box

Restore - version 1 (prefered)


In this case, you must have xenial64 box in your system. If you don't have it then run vagrant box add ubuntu/xenial64 command to add it first.


$ ls -l ~/.vagrant.d/boxes
drwxr-xr-x 4 inanzzz staff 136 23 Jun 15:35 ubuntu-VAGRANTSLASH-xenial64

Vagrantfile


Assume that this is the original content.


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"

config.vm.define :php7 do |php7_config|
php7_config.vm.hostname = "php7"
php7_config.vm.network "private_network", ip: "192.168.50.30"
end

config.vm.provider :virtualbox do |virtualbox_config|
virtualbox_config.name = "Php7 - Ubuntu 16.04 - 50.30"
virtualbox_config.memory = 2048
virtualbox_config.cpus = 2
end

config.ssh.username = "ubuntu"

config.vm.synced_folder "", "/var/www/html", nfs: true, mount_options: ["actimeo=2"]
end

Change the content so that it contains changes below.


...
config.vm.box = "my-ubuntu-xenial64-box"
config.vm.box_url = "file:///Users/inanzzz/Webserver/php7/package.box"
...

Restore


mac:php7 inanzzz$ vagrant up

Box is added to your system as seen below.


$ ls -l ~/.vagrant.d/boxes
drwxr-xr-x 3 inanzzz staff 102 23 Jun 21:15 my-ubuntu-xenial64-box

Restore - version 2


In this case, you must not have xenial64 box in your system. If you have it then first run vagrant box remove ubuntu/xenial64 to remove it.


$ ls -l ~/.vagrant.d/boxes

Vagrantfile


Assume that this is the original content.


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"

config.vm.define :php7 do |php7_config|
php7_config.vm.hostname = "php7"
php7_config.vm.network "private_network", ip: "192.168.50.30"
end

config.vm.provider :virtualbox do |virtualbox_config|
virtualbox_config.name = "Php7 - Ubuntu 16.04 - 50.30"
virtualbox_config.memory = 2048
virtualbox_config.cpus = 2
end

config.ssh.username = "ubuntu"

config.vm.synced_folder "", "/var/www/html", nfs: true, mount_options: ["actimeo=2"]
end

Change the content so that it contains changes below.


...
config.vm.box_url = "file:///Users/inanzzz/Webserver/php7/package.box"
...

Restore


mac:php7 inanzzz$ vagrant up

Box is added to your system as seen below.


$ ls -l ~/.vagrant.d/boxes
drwxr-xr-x 4 inanzzz staff 136 23 Jun 15:35 ubuntu-VAGRANTSLASH-xenial64

Suggestion


I would suggest you to go with "version 1" just to prevent confusion later that it's a customised box, not the upstream box.