Tuesday, December 18, 2012

VirtualBox: Multi-attach disk vanishes

So, you have created multi-attached disks and started using them for new VMs. Great! Then suddenly your disk vanishes from VirtualBox altogether.

The background.


With version 4 of VirtualBox, the method of registering media files changed. This includes disk files. Before version 4, there was a single location for disk image files, and also a central database that included all media files. From version 4, they decided to relocate the disk image files to reside in a folder for each VM, together with the rest of the files for that VM. Also, the central database went away, and new disk images was only registered in the xml file (.vbox) that describes every VM. The change is explained in chapter 10 of the Virtualbox manual.

Obviously, there where a lot of good arguments for the change that was made, but there seem to be a few unintended consequences as well, that to this date has not been addressed.

Unintended consequences


When I create a new VM with a disk intended for multi-attach, I have to remember to change the location of that disk so that it does not reside in the VM's folder. After all, this disk will be used for several VMs later on, so I want a central locations for such disk, keeping them separate from the VMs. This is not a big deal, I should probably not complain about it... But it get's worse.

When I create a new VM VM01, using a new multi-attach disk, the disk file location is referenced in the VM01.vbox xml file of the new VM, together with the corresponding difference disk Snapshots/{UUID}.vdi.


   <MediaRegistry>   
   <HardDisks>   
    <HardDisk uuid="{a28da29c-ffbb-4bec-910d-eb9604e4c85b}" location="D:/VBOX/DISKS/Win2003-32 SATA.vdi" format="VDI" type="MultiAttach">   
    <HardDisk uuid="{076b181e-6347-4d40-9ea8-adace71d70bc}" location="Snapshots/{076b181e-6347-4d40-9ea8-adace71d70bc}.vdi" format="VDI"/>   
    </HardDisk>   
   </HardDisks>   
   <DVDImages/>   
   <FloppyImages/>   
   </MediaRegistry>  


When I create a second VM VM02 using the same multiattach disk, the location of the master disk file and the differencing disk is not referenced in the VM02.vbox file at all.


   <MediaRegistry>  
   <HardDisks/>  
   <DVDImages/>  
   <FloppyImages/>  
   </MediaRegistry>  

In fact, the new differencing disk for VM02 is now registered in the VM01.vbox file.

   <MediaRegistry>  
   <HardDisks>  
    <HardDisk uuid="{a28da29c-ffbb-4bec-910d-eb9604e4c85b}" location="D:/VBOX/DISKS/Win2003-32 SATA.vdi" format="VDI" type="MultiAttach">  
    <HardDisk uuid="{076b181e-6347-4d40-9ea8-adace71d70bc}" location="Snapshots/{076b181e-6347-4d40-9ea8-adace71d70bc}.vdi" format="VDI"/>  
    <HardDisk uuid="{ca35f5b3-63b0-4448-ba53-1ea4c230f449}" location="D:/VBOX/VM02/Snapshots/{ca35f5b3-63b0-4448-ba53-1ea4c230f449}.vdi" format="VDI"/>  
    </HardDisk>  
   </HardDisks>  
   <DVDImages/>  
   <FloppyImages/>  
   </MediaRegistry>  

Not good. If VM01 for some reason becomes unavailable, VM02 will also fail to start, with an VBOX_E_OBJECT_NOT_FOUND error, as it has no clue where any of it's disk files are.


If I remove VM01 from the VirtualBox interface, all the harddisk references are copied into the VM02.vbox file. But if I remove both, expecting to still be able to reuse the multi-attach disk, I am in trouble, unless I create a new VM before I shut down VirtualBox.

The solution


I'm afraid it's not a good one. For now, we have to accept that multi-attach disks and all their differencing disks, regardless of what VM the disk is attached to, are registered in the .vbox file that belongs to the first VM that gets the multi-attach disk attached.

What I do, is to keep a collection of VMs registered in VirtualBox, for no other purpose than to keep my multi-attach disks and their differencing disks registered. I include all these VMs in my backup, together with the selection of VMs that for other reasons qualify for backup.

This method clutters my VirtualBox interface, but choosing a proper naming convention at least prevents me from deleting the last VM that holds a multi-attach disk.