About this blog

'Going Spatial' is my personal blog, the views on this site are entirely my own and should in no way be attributed to anyone else or as the opinion of any organisation.

My tweets on GIS, Humanitarian, Tech, Games and Randomness

Thursday 20 February 2014

Virtualbox - changing the UUID of a hard drive

I have been using VirtualBox for the last few (several) years and I love it. While my main working laptop is chockful of software, it is never enough so I use lots of virtual machines, all being created, run and managed through the excellent VirtualBox.  It means that I can install some very beta software on a variety of platforms, test them out and then get rid of them. I also have virtual machines to ensure that I have a very clean environment for training. For example, I have a windows 7 virtual machine loaded with Python 2.7 that I use to train and practise Python almost exclusively. Pity that I can't really use VMs for gaming....

I tinker with Linux (lots of distros), different versions of Windows and I even have a VM running 'Haiku' (go on, get it here) and I am seriously thinking of getting an emulator and running the old Spectrum, BBC Micro and a few others. I miss the old games!

Anyway,  after many years of working I encountered an odd problem for the first time. I wanted to share a VM running Windows 2012 R2 with a work colleague of mine. I had added some new software, tweaked and tuned the OS to my liking. We needed to test out some additional software so rather than have my colleague install the OS from scratch, apply patches and hotfixes, I simply copied the VHD file (took about 15 minutes) onto a USB drive and gave it to him. He then added the VHD file as a new drive and fired up the VM inside VirtualBox.


He made a number of significant tweaks as we were testing some of our software and then wanted to hand it back to me. I grabbed the VHD, popped it into another folder alongside the other VMs I have AND renamed the VHD file before booting it up.

This is what I got:

Failed to open the hard disk file P:\myVM\test\Windows 2012 R2.vdi.
Cannot register the hard disk 'P:\myVM\test\Windows 2012 R2.vdi' {bf2f3871-9227-42ed-a1e3-38b0d619acc7} because a hard disk 'P:\myVM\Windows 2012 R2\Windows 2012 R2.vdi' with UUID {bf2f3871-9227-42ed-a1e3-38b0d619acc7} already exists.
Result Code: E_INVALIDARG (0x80070057)
Component: VirtualBox
Interface: IVirtualBox {fafa4e17-1ee2-4905-a10e-fe7c18bf5554}

Oh dear. Normally, I would use the 'clone' function to make a copy of a virtual machine but I did not this time. Laziness? Who knows.

Basically, I needed to change the UUID of the copied hard disk. When I copied the original VHD file, I did not (and could not) change the UUID of the new drive during the copying process and this UUID  is no doubt used by VirtualBox to uniquely identify hard drives.

So I was stuck - my initial searches did not reveal anything too useful except some cryptic hints on using the command line (thanks guys) but researching it further for a couple of hours, I finally managed to find all the pieces of information.

The command is below and is based on my own installation:

VirtualBox is installed under D:\Program Files\Oracle\VirtualBox and my VM is called 'windows 2012 R2 V2' and is under my 'P' drive.

Here's there command in full. 

D:\Program Files\Oracle\VirtualBox>VBOXMANAGE.exe internalcommands sethduuid "P:\myVM\Windows 2012 R2 V2\Windows 2012 R2 v2.vdi"

This then changed the UUID to some other random number. In fact, I ran the above commands a few times just to see if it continued to change. It did.

Now with the copied drive sporting a brand new (and unique) UUID, I mounted the new virtual machine and voila, it worked!

Addendum. I searched some more and found an earlier and almost identical (but much better written) article dealing with the same issue, by Bradley Schacht. Isn't the internet great? His blog is great by the way. Well worth a read.

No comments:

Post a Comment