7
votes

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.

2
This is a bump for my question. I still have the same issue, Anyone have any ideas?Wairowe

2 Answers

2
votes

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.

0
votes

i have quite similar problem on Win 7 Professional with same programs versions without Vagrant OS: laravel/Homestead flavor (I do not know what it is).

But i have correct id in files .vagrant/machines/xxx/virtualbox/id. When i use any vagrant command, all files from folder .vagrant/machines/xxx/virtualbox/ are removed. But for me just turn on the virtual machines in VirtualBox and use vagrant suspend and vagrant up.

Here is my Vagranfile:

Vagrant.require_version '>= 1.6.0'
SSH_PORT                = 22
www, services, upload   = {}, {}, {}

# WWW SERVER
www[:memory]            = 768 # MB
www[:cpu]               = 1   # num. cpu cores
www[:cpuTimeCap]        = 100 # 1-100 %
www[:alias]             = 'www'
www[:ip]                = '10.11.5.35'
www[:sshPort]           = 58501               
www[:vboxName]          = 'WWW-name' 
www[:syncedFolder]      = './master-install'
www[:box]               = 'freebsd9.2'
www[:boxUrl]            = 'file:///E:/Virtuals/freebsd-9.2-amd64-wunki.box'
www[:provisions]        = []
www[:provisions]        << 'common/install.sh'
www[:provisions]        << 'master-install/install.sh'
www[:provisions]        << 'master-install/name-install.sh'

services[:memory]...etc.

machines = [www, services, upload]

Vagrant.configure('2') do |config|
  machines.each do |machine|
    config.vm.define "#{machine[:alias]}" do |node|
      node.vm.box = machine[:box]
      node.vm.box_url = machine[:boxUrl]
      node.vm.hostname = machine[:alias]
      node.vm.network :private_network, :ip => machine[:ip]
      node.vm.network :forwarded_port, :guest => SSH_PORT, :host => machine[:sshPort], :id => 'ssh', :auto_correct => true
      node.vm.synced_folder machine[:syncedFolder], "/vagrant", type: "rsync", rsync__exclude: ".git/"
      node.vm.provider :virtualbox do |vbconf|
        vbconf.customize ["modifyvm", :id, "--name", machine[:vboxName]]
        vbconf.customize ["modifyvm", :id, "--memory", machine[:memory]]
        vbconf.customize ["modifyvm", :id, "--cpus", machine[:cpu]]
        vbconf.customize ["modifyvm", :id, "--cpuexecutioncap", machine[:cpuTimeCap]]
        vbconf.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
        vbconf.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
        vbconf.customize ["modifyvm", :id, "--ioapic", "on"]
        vbconf.customize ["modifyvm", :id, "--chipset", "ich9"]
        vbconf.customize ["modifyvm", :id, "--usb", "off"]
        vbconf.customize ["modifyvm", :id, "--audio", "none"]
        vbconf.customize ["modifyvm", :id, "--nictype1", "virtio"]
        vbconf.customize ["modifyvm", :id, "--nictype2", "virtio"]
        vbconf.customize ["modifyvm", :id, "--pae", "on"]
        vbconf.customize ["modifyvm", :id, "--acpi", "on"]
        vbconf.customize ["modifyvm", :id, "--firmware", "bios"]
      end

      machine[:provisions].each do |provision|
        node.vm.provision "shell", path: provision
      end
    end
  end
end

ps: this is not the answer but rather add more information to the problem :)