13

I have Vagrant set up on one of my computers. I would like to change the location of its virtual hard drive, which is currently in the default location. How can I do this without breaking Vagrant?

I have Vagrant set up with VirtualBox 4.2.

EDIT: I mean that I want to move the location of the VirtualBox machine folder, which is currently at C:\Users\Kevin\VirtualBox VMs\my_vm\box-disk1.vmdk.

Kevin
  • 14,655
  • 24
  • 74
  • 124
  • I’m voting to close this question because GENERAL VAGRANT SUPPORT IS OFF-TOPIC. Support questions may be asked on https://superuser.com. – Rob Jul 01 '21 at 12:33
  • @Rob I originally asked this question 8 years ago. In addition, the Help Center says that questions about "software tools commonly used by programmers" are on-topic. https://stackoverflow.com/help/on-topic This question would also be on-topic on SuperUser, but that doesn't mean it's off-topic here. – Kevin Jul 01 '21 at 22:44
  • What I posted is from the tag used for the question. Hover over it to see that. – Rob Jul 01 '21 at 22:49

3 Answers3

24

Not sure if you want to change the ~/.vagrant.d or VirtualBox default machine folder.

If you want to move ~/.vagrant.d to somewhere else. You can set environment variable VAGRANT_HOME, see this https://stackoverflow.com/a/14804694/1801697

Update:

To change VirtualBox's Default Machine Folder, either do it in GUI => Prefs - General - Default Machine Folder or manually edit the ~/.VirtualBox/VirtualBox.xml

<SystemProperties defaultMachineFolder="/path/to/VirtualBox/VMs" defaultHardDiskFormat="VDI" VRDEAuthLibrary="VBoxAuth" webServiceAuthLibrary="VBoxAuth" LogHistoryCount="3"/>
Community
  • 1
  • 1
Terry Wang
  • 13,840
  • 3
  • 50
  • 43
  • I want to move the VirtualBox default machine folder. I'm sorry I wasn't more clear about that. – Kevin Jul 17 '13 at 15:25
  • 1
    I can't find the `~/.VirtualBox/VirtualBox.xml` folder. I'm using OS X. – Harry Lee Sep 02 '14 at 04:12
  • And the `GUI => Prefs - General - Default Machine Folder` approach dosen't change the folder where stores my existing vm. – Harry Lee Sep 02 '14 at 04:14
  • 1
    Update: If you use OS X, you can find this `~/Library/VirtualBox/VirtualBox.xml`, more helps http://emptysqua.re/blog/moving-virtualbox-and-vagrant-to-an-external-drive/ – Harry Lee Sep 02 '14 at 04:26
  • Can it be changed per-machine? I was trying to ask it [here](http://stackoverflow.com/questions/26142919), but with no valid answer. The use case is, having the machine data inside the vagrant project folder, so the user has everything in one place. – mighq Jan 03 '15 at 00:01
  • 1
    One thing which might help other people - on Windows I found that changing the default location in the VirtualBox GUI had no effect on where Vagrant VMs were stored (they were never stored in what the GUI thought was the default anyway!) Editing `.VirtualBox\VirtualBox.xml` sorted it, but it was very confusing. – Matthew Walton Jan 15 '15 at 10:19
  • 3
    On Ubuntu 14.04, `VirtualBox.xml` is in `~/.config/VirtualBox/VirtualBox.xml`. To relocate existing boxes you have to change all references to the old path: `sed -i 's|OLD_PATH|NEW_PATH|g' ~/.config/VirtualBox/VirtualBox.xml`. I think it's annoying as hell that the default folder used by virtualbox--"VirtualBox VMs"--has a space; it's the only folder on my entire system with a space in its name! – ostrokach Aug 27 '15 at 17:37
5

you can use the command :

VBoxManage setproperty machinefolder

here the doc for more information : https://www.virtualbox.org/manual/ch08.html#vboxmanage-setproperty

  • It is a better way than changing `VirtualBox.xml`. But for existing VM, you still have to edit the file. – fkpwolf Dec 20 '16 at 04:49
1

You have to change your ~/.VirtualBox/VirtualBox.xml defaultMachineFolder "SystemProperty"(see other answer). As the name already suggests this seems to be a system property / environment variable.

If you then run vagrant from an already running windows console the old value is used and even your edited VirtualBox.xml is overwritten!

So make sure to close and open a new CMD-Window. after the change.

icyerasor
  • 4,973
  • 1
  • 43
  • 52