hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.28k stars 4.43k forks source link

Vagrant up renames virtual machine directory #1817

Closed clebio closed 11 years ago

clebio commented 11 years ago

In Windows (8 64-bit), using 'vagrant up' sometimes causes the VirtualBox VM to get renamed, including the directory the VM resides in. This is different from the normal behavior of VirtualBox GUI and VBoxManage.

Steps to reproduce: vagrant init vagrant up vagrant halt

Open Windows file explorer and identify the folder for this vagrant box (the VirtualBox VM). From VirtualBox GUI, you can right-click the instance and select 'Show in Explorer').

Using the following, identify the correct vm_id for the current vagrant box: "\Program Files\Oracle\VirtualBox\VBoxManage.exe" list vms

Use VBoxManage to control the vagrant box: \Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm <vm_id> \Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm <vm_id> poweroff

At this point, the VM has not changed names, nor has the VM folder name changed.

vagrant up This will either issue an error (for instance, if File Explorer has the folder open): _There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. Command: ["modifyvm", "d471d855-b779-4f9f-8efd-3d6e5a829fa5", "--name", ""] Stderr: VBoxManage.exe: error: Could not rename the directory 'C:\Users\user\VirtualBox VMs' to 'C:\Users\user\VirtualBox VMs' to save the settings file (VERR _ACCESSDENIED)

Or, this will rename the VM and host folder.

It may be that anything else that is using that folder (Windows file explorer, for example), will inhibit renaming. But it's noteworthy that VBoxManage does not rename the VM instance.

clebio commented 11 years ago

https://github.com/mitchellh/vagrant/issues/1809

clebio commented 11 years ago

A few comments, in case these steps don't reproduce it for you. I've encountered this before when trying to move an existing Vagrant box to a new computer (there's no notes in the Vagrant documentation about that, but it's a fairly common scenario -- changing laptops, re-imaging OS, etc.).

Also, my current host machine has two partitions, one for the Windows OS and one for data files. I have installed some program files on the data partition (that of itself is not a problem, the programs run fine). But it might be significant that Vagrant is installed on the data partition whereas VirtualBox is installed on the OS partition, and the VM is created on the OS partition. I'm not sure the particular arrangement matters, but perhaps it's possible that Vagrant isn't accounting for different partitions (drive letters), and so isn't calling VBoxManage with the correct path.

sergioabreu commented 11 years ago

Hi, I have solved it by running the repair option of my vagrant.msi installer, after doing a full reboot too.

xofer commented 11 years ago

I noticed on each up, Vagrant is "Setting the name of the VM..."

This is setting name to nil:

https://github.com/mitchellh/vagrant/blob/a53d569656a75776bac3081e50d22f5c9e018941/plugins/providers/virtualbox/action/set_name.rb#L13

Explicitly setting the the name in the Vagrantfile solves it:

  config.vm.provider :virtualbox do |vb|
      vb.name = "something"
  end
clebio commented 11 years ago

@xofer's comment makes sense to me. That is potentially the correct fix, not just a work-around. Can it be set to whatever it currently is, then, before launching each time? I haven't dug into the code myself, but can try at some point.

clebio commented 11 years ago

More steps to reproduce:

  1. Download Microsoft VPC for IE testing (not direct download link: http://www.modern.ie/en-us/virtualization-tools#downloads).
  2. import VPC into VirtualBox, boot first time.
  3. Use Ubuntu live CD to re-partition the VPC hard drive. Shrink single partition (say, 20gb) and add a second ntfs partition. Reboot virtual machine.
  4. install Vagrant and VirtualBox inside the virtual machine
  5. Open Command prompt, switch to new partition (d: or e:, depending on existing CD drive I guess)
  6. run vagrant init precise32 http://files.vagrantup.com/precise32.box. Open widows File Explorer, find the virtual machine directory (on c: drive: something like C:\Documents and Settings\IEUser\VirtualBox VMs\_default_1234567890). Navigate out of the VM directory (just up to C:\Documents and Settings\IEUser\VirtualBox VMs\, probably)
  7. vagrant halt
  8. vagrant up. Look at the VM directory.

In my case, this produces, for steps 6 and 8 respectively, the folders: _default_1375651092 and _default_1375651676.

That is, vagrant changed the VM directory name just with a 'up, halt, up' sequence.

mitchellh commented 11 years ago

Fixed. The default name will only be set on first up. Of course, if you change the vm.name setting in VirtualBox settings in the Vagrantfile, it will be set on the next reload.

dogmatic69 commented 11 years ago

I got this problem (using 1.3.3) after moving vagrant files within my project. I opened up virtualbox and noticed it made a new instance with a random name. deleted both the old (before moving the files around) and the new. Now seems to boot fine again.

The error:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] -- 80 => 8080 (adapter 1)
[default] -- 9090 => 9090 (adapter 1)
[default] Running 'pre-boot' VM customizations...
A customization command failed:

["modifyvm", "81a6eca6-4fff-4f54-ace8-b86edd56b349", "--name", "Infinitas"]

The following error was experienced:

VBoxManage: error: Could not rename the directory '/home/dogmatic69/VirtualBox VMs/vagrant_default_1380708640' to '/home/dogmatic69/VirtualBox VMs/Infinitas' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "SaveSettings()" at line 2527 of file VBoxManageModifyVM.cpp

Please fix this customization and try again.
naumoff commented 5 years ago

5 years passed and still problem exists

chrisroberts commented 5 years ago

@naumoff I do not see this behavior exhibited in the current version of Vagrant. If you are currently experiencing this problem with the latest version of Vagrant, please create a new issue and provide the details requested.

Cheers!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.