VirtualBox Maintenance – How to Maintain a Small Differential Hard Drive

clouddropboxvirtual machinevirtualboxvirtualization

I am trying to use a virtualbox hard drive over several computers using dropbox (a popular cloud tool) synchronization. I assume no two machines will open the same drive at the same time.

To reduce data transfers, I'd like to use only a differential of my hard drive that will store only a small volume of "documents", not syncing the whole hard drive (I don't trust Dropbox differential synchronization to be very effective). Using this official VirtualBox documentation, I made the following trick that only partly satisfies me.

  • Build up a differential drive with a trick:
    • Make the drive multiattach (see above documentation)
    • Make a simple change to the drive on the guest, that will create a diff file
  • Restore (using the VBox Media Manager, File > Virtual Media Manager) the base drive to "normal" mode (I need this to be able to attach it to several machines)
  • Detach the main drive from the machine, and instead attach the diff
    • This needs an extra trick when attaching to a new machine: attach then detach the main, then attach the diff, else VirtualBox won't recognize the disk GUID

This trick does the job: as I work only with the diff disk, the base is never modified and thus never synchronized over the network. The bad part though is that, even if very little growing in amount of stored data, the diff drive is growing in space the vdi (virtual drive storage file on the host) takes on the host because of how the guest OS fragments and moves files. And thus I am starting to synchronize an ever growing diff hard disk, losing the advantages of having a diff.

The problem is: I want is a way to regularly 'merge' or 'defragment changes' on the diff vdi to keep the synchronization small. I can afford (though I don't want it) to make a full sync of the main vdi every time I make this merge. But the only way I've though of is recreating a diff vdi using the same process and restore the files on that disk through some kind of backup. Not very handy. Anyone has a better idea?

Of course there is the other way to work only on a shared directory (between the host and teh guest), but that will need extra configuration (lots of symbolic links on the guest) and I don't want host users to mess up with guest files.

Have I been clear enough?

Best Answer

VBoxManage modifyhd --compact will cut out any blocks that you have zeroed out with an appropriate tool (see manual). Not sure whether attaching a separate disk for the documents (maybe write-through) would be better for your needs.