kusnier/vagrant-persistent-storage

vagrant destroy leaves stale vbox media behind

dimara opened this issue · 4 comments

Assuming that we have a running VM, upon vagrant destroy, the extra disk gets detached from the machine without closing the corresponding virtualbox medium. If we delete the underlying storage (VDI file), the next vagrant up fails with:

==> default: Running 'pre-boot' VM customizations...
==> default: ** Creating persistent storage **
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["createhd", "--filename", "D:/minikf/minikf-user-data.vdi", "--size", "512000", "--variant", "Standard"]

Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...
Progress state: E_INVALIDARG
VBoxManage.exe: error: Failed to create medium
VBoxManage.exe: error: Cannot register the hard disk 'D:\minikf\minikf-user-data.vdi' {442cb814-09ad-4a90-a73a-6939ab18ef18} because a hard disk 'D:\minikf\minikf-user-data.vdi' with UUID {686ea848-cbd4-4db3-9c39-62cef3524a4e} already exists
VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component VirtualBoxWrap, interface IVirtualBox
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreateMedium(struct HandlerArg *)" at line 462 of file VBoxManageDisk.cpp

The reason is that the plugin tries to create a disk that already exists. Shouldn't the
the plugin, upon vagrant destroy, remove the medium without actually deleting the underlying VDI (e.g., via vboxmanage closemedium disk UUID)? Upon vagrant up the medium will be
created implicitly by virtualbox via the vboxmanage storageattach command.

The strange thing is that if the machine is halted first, and then destroyed, it works as expected; the medium gets removed and the VDI remains intact.

This seems to be related with #69 which has been closed.

The above can be reproduced on the following platforms:

  • Linux Debian jessie with virtualbox 5.1.8_Debianr111374
  • Windows 10 with virtualbox 6.0
  • Arch Linux with virtualbox 6.0.8

Thank you for the report. Actually i have no time to investigate it.

The statement of my initial comment below does not seem to hold:

The strange thing is that if the machine is halted first, and then destroyed, it works as expected; the medium gets removed and the VDI remains intact.

If one wants to remove the stale media, one has to do it via Virtual Media Manager. I'll try to submit
a PR that fixes this issue ASAP.

Shouldn't we close this now that PR #102 is merged (and included in v0.0.47)?

@dimara : Yes. You are right. I forgot this. Thanks!