How to match VirtualBox VMs to Vagrant VMs? - vagrant

I use Vagrant with Oracle VirtualBox and I'm trying to clear up space on my laptop. I've noticed that I have a number of directories in my ~/VirtualBox VMs directory that are taking up a lot of room. The names of these directories don't match up with anything in my Vagrantfiles. What I also don't quite understand is that I have two VMs that I am able to start up but if I run the "vagrant global-status" command, it tells me "There are no active Vagrant environments on this computer!"
How do I determine which of the VirtualBox VM directories I'm still using and which ones can be deleted using the Oracle VirtualBox Manager? Should I just delete everything and start over?
Thanks!

This appears to be one way to do it:
Go into each directory, run "vagrant status", halt the machine (if it's running), and then destroy it. This will delete the associated directory in ~/VirtualBox VMs.
After you've done this for all know Vagrantfile directories, run the Oracle VirtualBox application and Remove each remaining machine.

Related

Can you perform a vagrant provision from inside the VM?

Usually you have to run vagrant provision from outside your VM to create the VM to begin with. I then do a vagrant ssh to inspect the resultant VM.
If I wish to make small tweaks to the VM (using chef zero recipes in my case), I have to either switch to an other tab that is on my physical host, or exit the SSH session. it would be nice if you could do this run-and-inspect inside the previously created VM.
Why I'm asking: I have too many terminal tabs open for development and am looking for ways to prune, and avoid mental context switching (not to mention trying to figure out which tab is which).
No, you can not run a vagrant provision from inside the same vagrant machine.
Vagrant is running on your host and provisioning the VM according to the specified vagrantfile. Any changes that you want to have applied during the provisioning must somehow come from the vagrantfile.
What you can do is modify a running vagrant machine in any way you want from inside the vagrant machine, and then export the VM using vagrant package to a new vagrant box which then can be used as base for new vagrant VMs.
PS: Not sure how you're dev environment looks like, but I suggest you look into terminal multiplexers like GNU screen or tmux, that might be able to help you with your "tab issues".

Forgetting a VM in Vagrant

I've started a VM on Google Compute Engine using Vagrant with the vagrant-google provider. I no longer wish to control the VM using Vagrant, but I would like it to keep running without me interrupting it.
What's the proper way to have Vagrant "forget" about this machine?
so the instance has been installed on GCE and you can control directly from there.
Locally you can delete the .vagrant folder that vagrant created in the folder when you launch it
After this to remove references you can run vagrant global-status --prune which will remove invalid entries and clean vagrant conf file from this machine

Running vagrant on two macs

I have Vagrant installed on my iMac but I would also like to install and run it on my MacBook. Is it possible to run the same Vagrant box across two Macs?
I have done a Vagrant up command within a shared Dropbox folder - so i'm guessing that all I need to do is install vagrant on the second mac and then navigate to the Dropbox shared folder and do vagrant up.
Would this work?
Known solution:
ssh to the host machine
user#MacBook: ssh user#imac
then vagrant up; vagrant ssh.
user#imac: vagrant up; vagrant ssh
vagrant#vagrantvm:
This would be the most straight forward way I can think of.
Another option:
RDP to imac and run vagrant up;vagrant ssh as normal
Yet another option:
If your vagrant file is complete enough you should be able to vagrant up on any host to give you the same vagrant env. This relies on your use case but is how I use vagrant.
Vagrant stores the state of the machine and machine id inside the .vagrant folder. The running machine (vm) itself is handled by virtualbox/vmware or any provider your using. Lets say the virtualbox box is stored somewhere else on your system and referenced by Vagrant.
If you access the folder from two systems your basically remote controlling two different machine on two different systems. Not a good solution. Furthermore, you will run into problems if the states are different, e.g. its "up" on system one but "destroyed" on system two.
Additionally to the above solutions I propose the following:
Vagrant Share! Enable Vagrant http-/ssh-Share between your systems.
Vagrant machines should be repeatable and destroyable. Therefore, put your Vagrantfile under version control and checkout on the two systems.
Configure your provider to store the box itself on the dropbox.

Can't get vagrant destroy to work

I just deleted a large directory that I no longer needed. Unfortunately, it had a number of vagrant instances that I neglected to halt and destroy first within it and I'm having trouble getting them to go away now.
If I run "vagrant global-status", I receive four results, all have the name "default", three use hyperv and one uses virtualbox (not sure why I have a virtualbox instance at all), all but the virtualbox is running, and all in directories that no longer exist.
I just opened up the hyper-v manager and none of these instances actually exist.
If I attempt to use "vagrant destroy" against any of the ids in the global-status output, I get the following error:
There are errors in the configuration of this machine. Please fix the following errors and try again:
vm:
* A box must be specified
If I look in the "vagrant box list" command, it yields a single named box, but I don't appear to be able to do anything with it as I'll get the same error as above when I attempt to remove it.
What can I do to 1) get rid of the last of the directories that wouldn't delete since vagrant appears to be using the files and 2) clear out these entries that shouldn't be here anymore from the vagrant global-status command?
Thanks!
To clean Vagrant's global status, use the --prune flag.
I'm not sure why you don't see the Hyper-V machines in your Hyper-V manager though.
I wound up uninstalling Vagrant and deleting the directories Vagrant was using. Then I re-installed and there were no more ghost Vagrant instances.
I managed to remove the vagrant VM entry from global-status using vagrant destroy <id> after I manually deleted the VM from "Oracle VM VirtualBox". VM was ubuntu 14.04, host was windows 10.

Where is Vagrant saving changes to the VM?

I am just starting with Vagrant and I am having a little trouble understanding a few details. I have read through the docs but still am missing a basic concept. When I want to start a Vagrant box I run:
vagrant up
This will "build the VM based on the box" I understand that the boxes are stored at ~/.vagrant.d and in fact I have packaged up my own box from a base Ubuntu box. However, when I run vagrant up and start to add files to the vm, where is the virtual hard drive for the vm stored? For example, when I run apt-get install apache2 and the root system is modified, where is this modified?
When I do a du on my current directory I do not see any changes. I also do not see any changes in the ~/.vagrant.d directory. However, I can do vagrant halt, restart my local machine and then run vagrant up again and the changes are persisted somewhere.
vagrant up also reports
[default] VM already created. Booting if its not already running...
Can someone tell me where the VM is created and where the changes are made?
Vagrant imports the base box which is located at ~/.vagrant.d/boxes/, like you said.
This is where the base boxes are kept. It uses it to start a VM from the clean state. When importing a VM, the responsibility of where to store data files and VM state is up to VirtualBox itself. This is a configurable location but typically defaults to ~/VirtualBox\ VMS for Mac OS X and Linux. In Windows the boxes are kept in %userprofile%\.vagrant.d\boxes
It is easy to find the place where they are getting created, regardless of what platform you happen to be using.
1. Start VirtualBox.
2. Go to the VM that shows as running instance.
3. Check out the Settings ->Storage.
4. You can find the path to location where VMs are created and stored in your file system.
I always change the directory that Virtualbox uses by default for VMs. Normally it is in your profile folder in Windows.
I change it to something like "D:\VHDs\VBox\" and there I found my vagrant test vm: "test01_1347456065". It was called test01, so I guess vagrant adds the numbers to keep things unique.

Resources