Opened 10 years ago
Closed 8 years ago
#13326 closed defect (obsolete)
unregistervm --delete fails with multiple snapshots
| Reported by: | jcbsft | Owned by: | |
|---|---|---|---|
| Component: | VM control | Version: | VirtualBox 4.3.14 |
| Keywords: | Cc: | ||
| Guest type: | Linux | Host type: | Windows |
Description
VirtualBox v4.3.14 (and v.4.3.12) on Windows 64-bit
Using VirtualBox in what we try to be a fully automated deployment where the GUI is not to be used. Instrumenting VirtualBox with VBoxManage.
Use-case:
- We have a baked OVA file that contains a custom installation of CentOS
- VBoxManage createvm --name XSP.trunk --ostype Linux_64 --basefolder ../VM --register
- VBoxManage import ../VM/CentOS.ova --vsys 0 --vmname XSP.trunk --unit 11 --disk "{defaultdirectory}/XSP.trunk-disk/XSP.trunk.vmdk"
- (multiple modifyvm instructions to configure the network)
- VBoxManage modifyvm XSP.trunk --snapshotfolder "{defaultdirectory}/XSP.trunk-disk" (same folder as main disk)
- VBoxManage startvm --type headless
- (we do network configuration by SSH'ing into the guest)
- VBoxManage snapshot XSP.trunk take VM_Bare -desc "VM configured, ready to install"
- (download and installation of our custom software)
- VBoxManage snapshot XSP.trunk take VM_Prod -desc "Server running, original files"
Note: we encourage our developers to take snapshots, so there is no way to know in advance how many snapshots there are, nor their structure.
Fortunately, the unregistervm --delete documentation promises to take care of the attached disks, including the snapshots (https://www.virtualbox.org/manual/ch08.html#vboxmanage-registervm). It looks like the one-stop shop to nuke everything related to a VM, but it fails.
FIRST ISSUE: running unregistervm --delete when storage is attached.
When unregistervm --delete is called while storage is attached, I get:
C:\Program Files\Oracle\VirtualBox>vboxmanage unregistervm XSP.trunk --delete
0%...10%...20%...
Progress state: VBOX_E_INVALID_OBJECT_STATE
VBoxManage.exe: error: Machine delete failed
VBoxManage.exe: error: Medium 'C:\Users\jcollin\VirtualBox VMs\XSP.trunk-disk\{2
e8449ee-27d0-4f8f-b9cd-35a811c92dcf}.vmdk' is locked for reading by another task
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), c
omponent Medium, interface IMedium
VBoxManage.exe: error: Context: "int __cdecl handleUnregisterVM(struct HandlerAr
g *)" at line 166 of file VBoxManageMisc.cpp
VBoxSVC.log part of interest:
00:32:44.056438 MachineDelete ERROR [COM]: aRC=VBOX_E_INVALID_OBJECT_STATE (0x80bb0007) aIID={05f2bbb6-a3a6-4fb9-9b49-6d0dda7142ac} aComponent={Medium} aText={Medium 'C:\Users\jcollin\VirtualBox VMs\XSP.trunk-disk\{2e8449ee-27d0-4f8f-b9cd-35a811c92dcf}.vmdk' is locked for reading by another task}, preserve=false
00:32:44.057438 MachineDelete ERROR [COM]: aRC=VBOX_E_INVALID_OBJECT_STATE (0x80bb0007) aIID={05f2bbb6-a3a6-4fb9-9b49-6d0dda7142ac} aComponent={Medium} aText={Medium 'C:\Users\jcollin\VirtualBox VMs\XSP.trunk-disk\{2e8449ee-27d0-4f8f-b9cd-35a811c92dcf}.vmdk' is locked for reading by another task}, preserve=false
The only process reading this VMDK is VirtualBox (the VM is powered off). As per the documentation unregistervm --delete should remove them.
SECOND ISSUE: running unregistervm --delete when storage is no longer attached To address my first issue, I called storageattach --medium none on my VM. Then I called unregistervm --delete again:
C:\Program Files\Oracle\VirtualBox>vboxmanage unregistervm XSP.trunk --delete
0%...10%...
Progress state: VBOX_E_OBJECT_IN_USE
VBoxManage.exe: error: Machine delete failed
VBoxManage.exe: error: Cannot close medium 'C:\Users\jcollin\VirtualBox VMs\XSP.
trunk-disk\{6e221dec-91ee-4866-9671-c50f672ddd8b}.vmdk' because it has 1 child m
edia
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_IN_USE (0x80bb000c), componen
t Medium, interface IMedium
VBoxManage.exe: error: Context: "int __cdecl handleUnregisterVM(struct HandlerAr
g *)" at line 166 of file VBoxManageMisc.cpp
VBoxSVC.log part of interest:
01:13:08.500971 MachineDelete ERROR [COM]: aRC=VBOX_E_OBJECT_IN_USE (0x80bb000c) aIID={05f2bbb6-a3a6-4fb9-9b49-6d0dda7142ac} aComponent={Medium} aText={Cannot close medium 'C:\Users\jcollin\VirtualBox VMs\XSP.trunk-disk\{6e221dec-91ee-4866-9671-c50f672ddd8b}.vmdk' because it has 1 child media}, preserve=false
01:13:08.501471 MachineDelete ERROR [COM]: aRC=VBOX_E_INVALID_OBJECT_STATE (0x80bb0007) aIID={05f2bbb6-a3a6-4fb9-9b49-6d0dda7142ac} aComponent={Medium} aText={Storage for the medium 'C:\Users\jcollin\VirtualBox VMs\XSP.trunk-disk\{6e221dec-91ee-4866-9671-c50f672ddd8b}.vmdk' is already created}, preserve=false
This is the MediaRegistry block of my .vbox file:
<MediaRegistry>
<HardDisks>
<HardDisk uuid="{574b36b4-ed44-41d4-bde4-e3f76ff99fba}" location="C:/.../VirtualBox VMs/XSP.trunk-disk/XSP.trunk.vmdk" format="VMDK" type="Normal">
<HardDisk uuid="{6e221dec-91ee-4866-9671-c50f672ddd8b}" location="C:/.../VirtualBox VMs/XSP.trunk-disk/{6e221dec-91ee-4866-9671-c50f672ddd8b}.vmdk" format="VMDK">
<HardDisk uuid="{a02ec242-956b-4985-b806-4d237cfefabd}" location="C:/.../VirtualBox VMs/XSP.trunk-disk/{a02ec242-956b-4985-b806-4d237cfefabd}.vmdk" format="VMDK"/>
</HardDisk>
</HardDisk>
</HardDisks>
<DVDImages/>
<FloppyImages/>
</MediaRegistry>
It seems that VirtualBox is attempting to call closemedium on {6e221dec-91ee-4866-9671-c50f672ddd8b} when there is a child snapshot. I expect VirtualBox to close all mediums related to a VM since it knows the snapshot tree.
This leads to a 'leak' of HDDs that are not deleted on disk, but foremost in the 'vboxmanage list hdds', which requires manual intervention.


Please reopen if still relevant with a recent VirtualBox release.