Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save clasense4/2c8522b876f9a01ca177809526dc36e3 to your computer and use it in GitHub Desktop.
Save clasense4/2c8522b876f9a01ca177809526dc36e3 to your computer and use it in GitHub Desktop.
Vagrant: Create local box

Create box

This is how to install something in a VM and export it as a Vagrant box and use it locally.

First copy the Vagrantfile from below and change the box to the box you want as a base.

Run vagrant up to create the Virtual Machine and vagrant ssh to login.
On Windows you might have to put ssh.exe to your %PATH%. If you have installed git, you can use C:\Program Files\Git\usr\bin You can also login via Putty on host: "localhost", Port "2222", login: "vagrant", password: "vagrant".

Now install your software if not already defined in you Vagrantfile.

Exit the VM and run vagrant package --base my-new-box-name --output my-new-box-name.box. Vagrant will export the actual VM in a file.

Run vagrant box add my-new-box-name file:///c:/path/to/my-new-box-name.box (relative path does also work: file://my-new-box-name.box) to import your new box.
vagrant box list will list your new box.
The box-file can be deleted.
Now you can use the box in new Vagrantfiles.

See also Custom Vagrant Cloud Versioned Box Host.

Authentication error

If Vagrant has problems logging in and fails with "Warning: Authentication failure. Retrying..." take a look at Vagrant box authentication failure after packaging box or set the loginmethod to password by adding config.ssh.password = "vagrant" to your Vagrantfile. See SSH settings for more information.

Vagrant.configure(2) do |config|
#Choose your base-boxT. Here it is Ubuntu 14.04 (Trusty Tahr) 64 Bit
config.vm.box = "ubuntu/trusty64"
#Wait max 10 minutes (600 seconds) to start VM without provisioning
config.vm.boot_timeout = 600
config.vm.provider :virtualbox do |p|
#Name your box
p.name = 'my-new-box-name'
p.cpus = 1
p.memory = 1024
opts = ['modifyvm', :id, '--natdnshostresolver1', 'on']
p.customize opts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment