Skip to content

Instantly share code, notes, and snippets.

@fmasuhr
Last active June 27, 2022 03:25
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fmasuhr/4fd661b884f157590613 to your computer and use it in GitHub Desktop.
Save fmasuhr/4fd661b884f157590613 to your computer and use it in GitHub Desktop.
Associate a Vagrant project directory with an existing VirtualBox VM
  1. Run the following command and copy the ID of your VM
VBoxManage list vms
=> "virtualMachine" {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
  1. Go to the Vagrant project configuration folder
cd .vagrant/machines/default/virtualbox
  1. Create a file called id without a newline but the ID of your VM xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
echo -n 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' > id
  1. In the directory where your Vagrantfile of the associated VM is located, run Vagrant with new config
vagrant up
@davidballester
Copy link

Really useful. Thanks!

@navono
Copy link

navono commented Apr 13, 2019

how to config ssh after associate vm?

@adeoke
Copy link

adeoke commented Jan 25, 2020

how to config ssh after associate vm?

In the Vagrantfile put the username and password (only required once), like so:

config.ssh.username = 'vagrant'
config.ssh.password = 'vagrant'

@augustojaba
Copy link

augustojaba commented Mar 31, 2020

How can I export my box as-is with the HD and everything and restore in another machine? I´ve tried doing this with vagrant package, however, when I do vagrant add box and vagrant up my VM starts from the scratch. What can I be doing wrong?

@carlos-ht
Copy link

thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment