Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant resets the .vagrant directory each time I use vagrant up

My Environment:

  • OS: win8.1
  • Vagrant: 1.6.3
  • Virtual Box: 4.3.12r93733
  • Vagrant OS: laravel/Homestead flavor

The situation: I have noticed that after a "vagrant suspend" and computer restart(The next day's work) when I run "vagrant up" all the files in the .vagrant directory get deleted during the "up" process and a new VBox instance is created. This means that I lose all my previous config such as DB, npm installs and mounts. Yes the lost config is mostly all available through saved scripts, but this is a real pain to do every time!

My current Fix: Currently each time this occurs I need to run "VBoxManage list vms" to retrieve the correct ID. I then "vagrant suspend" the new unwanted instance, delete it from the Oracle VM VirtualBox Manage, paste the old ID into the "id" file within ".vagrant" and run "vagrant up" again. This time it works!

I have checked the id file each time before running "vagrant up" and the correct id is in there. I have also tried "vagrant resume" but that has made no difference.

The Vagrantfile and config file are almost standard what comes with the Homestead package. The only change I have made is within the Vagrantfile to allow symlinks (this is a work around for an entirely separate issue with NODE, npm and windows limits to 260 char directory paths). Here is the extra bit I added for this dir length issue.

config.vm.provider "virtualbox" do |vb|
 # SEE https://github.com/fideloper/Vaprobash/issues/183
 vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
end

What am I doing wrong? Why is Vagrant creating a new VM instance every time?

UPDATE:

I have discovered that the issue is something to do with running the CLI (I generally use cygwin) and Oracles VBox manager with administrator privileges. I have also discovered that some of my VM's are saved under C:\cygwin64\home... I can use those when running the cygwin terminal as admin. And I can see them in Oracle VirtualBox Manager if I run that as admin also. Other VM's are stored in C:\Users.... and I can see those when running oracle VBox manager as my normal user (who has admin privileges).

I am still a little confused how this has all happened.

like image 260
Wairowe Avatar asked Jul 10 '14 03:07

Wairowe


1 Answers

I found the answer to my problem, hopefully it will help others.

The issue was some VM's sitting in my C:/cygwin64/home directory, and they belonged to administrator, they could also only be seen on Oracles VirtualBox Manager if i opened it "as administrator". Other VM's were in C:/Users/[user name]/VirtualBox VMs, they were owned by my user account and could only be seen if I opened the apps normally.

I was opening my Cygwin normally and therefore not being able to properly bring the VM back up (Still a little confused why reseting the ID each time seemed to work).

My solution: with help from this answer by thomthom

Within Oracles VirtualBox Mangager I changed the Default Machine Folder (File->Preferences->General) to C:/Users/[user name]/VirtualBox VMs. I then cloned each of the VM's so they ended up in the new directory. I then totally removed the old VM's (right click -> Remove) that were sitting in the cygwin folder. I then closed Cygwin and VirtualBox Manager and reopened as a normal users (VirtualBox Manager was not showing anything!)

Finally I went in the the new directory and double clicked each VM so it was added back into VirtualBox manager, then, fom the command line I ran VBoxManage list vms to get the new ID of the clones, copied that ID into the id file within my project (it will be something like PROJECT\.vagrant\machines\default\virtualbox\id

Now I can run vagrants "vagrant up" command with cygwin as a normal user and everything works great.

The lesson: Be very aware of what user you run the initial VM creations as, also be very aware of where VirtualBox manager is storing your VMs.

like image 112
Wairowe Avatar answered Oct 09 '22 10:10

Wairowe