103

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?

Tree
  • 1,248
  • 2
  • 11
  • 9

2 Answers2

114

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.
Community
  • 1
  • 1
pyfunc
  • 65,343
  • 15
  • 148
  • 136
  • Thank you for your answer. You have nicely explained how it is working. – Tree Dec 15 '11 at 18:37
  • 13
    It's `~/VirtualBox VMS` on Windows too. – Jason R. Coombs Apr 11 '12 at 17:22
  • I was wondering if @pyfunc and other users here could help me with using vagrant on an existing VM that is not created using `vagrant up` in the first place. http://stackoverflow.com/q/14503932/80353 – Kim Stacks Jan 24 '13 at 14:50
  • @kimsia: It is possible to export your VM after certain preparation as box file that can be used with vagrant. See my blog note if it can help: http://pyfunc.blogspot.com/2011/11/creating-base-box-from-scratch-for.html – pyfunc Jan 24 '13 at 22:36
  • @pyfunc, thank you for your reply. Your blogpost gave me some clues. I have more follow up questions to ask. Would it be okay if I copy your comment and paste as an answer on my question and take the conversation there? Or you prefer to put it as an answer at my question yourself? This is my question http://stackoverflow.com/q/14503932/80353 – Kim Stacks Jan 25 '13 at 01:47
  • @pyfunc It appears your blogpost assumes Linux as the host OS. I am using Mac OS X as host OS. Can I start from the section Easing working on VM since I have already setup my virtualbox nicely with ubuntu as a guest OS? – Kim Stacks Jan 25 '13 at 07:00
  • @kimsia: It's absolutely fine. I can answer it there :) – pyfunc Jan 25 '13 at 17:35
  • Does `vagrant destroy` destroy the cached box inside `vagrant.d/boxes`? I realised that when I destroyed it, and then upped a new one, it kept launching the old one. – CMCDragonkai May 28 '14 at 03:06
4

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.

Marijn
  • 10,367
  • 5
  • 59
  • 80