Want to share: A "dummy" way to create a .box file from existing Vagrant's files

1,668 views
Skip to first unread message

Bayu Widyasanyata

unread,
Dec 15, 2013, 1:06:40 PM12/15/13
to vagra...@googlegroups.com
Hi All,

I'm a new on Vagrant, less than a week playing with it :)
I want to share what I just recently did create a .box (base box) from Vagrant base box (extracted) files.
I'm not sure if this topic has already posted in this forum, just want to share and hear if it's an uncommon or "wrong" way :)

OK, let's start.

I ran my Vagrant 1.3.5 on my Windows 7 Professional system and I already have a "precise64" base box inside.
The story began when I want to uninstall/deleted my Vagrant installation, then reinstall a fresh Vagrant BUT didn't want to download base box remotely instead of using from previous downloaded (extracted) base box files.
Hence I prevent to execute vagrant add box remotely/Internet (e.g."vagrant box add precise64 http://files.vagrantup.com/precise64.box").

I already has tested the new base box file and setup new project successfully.

OK, here are the steps:

[0] Backup Vagrant's box file
Vagrant save and extract a .box files into ~users_path\.vagrant.d\boxes\precise64\virtualbox.
In my system: C:\Users\billydekid\.vagrant.d\boxes\precise64\virtualbox
That folder contains following files:
  • box.ovf
  • box-disk1.vmdk
  • metadata.json
  • Vagrantfile
I backup those files to a folder (e.g. E:\temp\precise64_sources)

[1] Uninstall Vagrant from Control Panel uninstall tool.


[2] Create a base box (.box) file with common archiving tools (Winzip, 7zip, etc.)
- I use 7zip.

- Go to E:\temp\precise64_sources folder
- Select all files, right click and select: 7-Zip > Add to archive...
- On "Add to archive" window, fill the file name "precise64.box" on Archive field and select "tar" on Archive format field.
- Click "OK" button to start creating "precise64.box" file
- Finish: a precise64.box will be created inside the folder of Vagrant's "4 files" at step [0] above.

[3] Install a fresh Vagrant app. (again) -- Vagrant_1.3.5.msi file.

[4] Installing a new precise64 base box from local file path.

- To simplify and since Vagrant always complaint with "Windows' path format" (I don't know why?), I moved precise64.box into the root one of my drive (e.g. E:\precise64.box)
>> Vagrant had always failed when I put complete file path (with Drive's location), as shown below:

C:\Users\billydekid>vagrant box add precise64 e:\precise64.box
Downloading or copying the box...
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

Couldn't open file /precise64.box

- Go to "E:\" drive where I put precise64.box
- Execute vagrant add box command without drive location:

E:\>vagrant box add precise64 precise64.box
Downloading or copying the box...
Extracting box...ate: 45.7M/s, Estimated time remaining: --:--:--)
The "metadata.json" file for the box 'precise64' was not found.
Boxes require this file in order for Vagrant to determine the
provider it was made for. If you made the box, please add a
"metadata.json" file to it. If someone else made the box, please
notify the box creator that the box is corrupt. Documentation for
box file format can be found at the URL below:

- Test of vagrant list boxes:

E:\>vagrant box list
precise64 (virtualbox)

[5] Test the result by create a new project.

5.1. Create a new project directory and start project setup.

E:\>mkdir testvagrant

E:\>cd testvagrant

E:\testvagrant>vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
>>> Vagrant add box step is success.

5.2. Change config.vm.box value from "base" to "precise64".
- Edit file E:\testvagrant\Vagrantfile, and change the value:

config.vm.box = "base"

to

config.vm.box = "precise64"

[6] Startup Vagrant

- Go to E:\testvagrant folder and do "vagrant up" command.

E:\testvagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise64'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant

[7] FINISH :-)

I hope it helps for anyone who want to create a "base box" from existing Vagrant's files :)

Thank you!

[bayu]

Rich Burroughs

unread,
Dec 16, 2013, 12:18:33 PM12/16/13
to vagra...@googlegroups.com
Hi :)

If I understand you correctly, you could just do "vagrant box repackage" in that scenario. That command allows you to create a .box file from an installed box.

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bayu Widyasanyata

unread,
Dec 17, 2013, 6:14:50 AM12/17/13
to vagra...@googlegroups.com
Yap, you're correct! :)
I haven't completed yet for section "Getting Started" :)

It's my "fault" not read that section yet ;-)

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.

Rich Burroughs

unread,
Dec 17, 2013, 11:38:17 AM12/17/13
to vagra...@googlegroups.com
Hah :) It's ok, I didn't know about that command at first either. I read Mitchell's book over the weekend.

Rich

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages