Duplicating VirtualBox Machines the Hard Way

VirtualBox is a great software package — and it provides an easier way to clone an virtual machine, but I didn’t know that. Already, I had manually copied a basic image of a Windows XP machine twice. I had three working copies, but I had to rename the files every time I wanted to start one up. I decided I was tired of this. I spent about two hours figuring this stuff out (with pacing time included). I advise following the link at the bottom of this post to see the proper way to do this.

I looked at the folowing files in my ~/.VirtualBox directory:
VirtualBox.xml
HardDisks/*.vdi
Machines/*.xml

I had the hard disks already in their directory. I copied the original machine’s .xml file twice so I had one for each hard drive. I looked inside each of those Machines/*.xml files and saw the place to change the name of the machine and the HardDisks/*.vdi file it used as the disk. Then I changed the names and the disks they used. Then I edited the VirtualBox.xml file to reflect the changes I had made.

I saved everything and started up VirtualBox. “Cannot create VirtualBox COM object with UUID: {00000000-0000-0000-0000-000000000000}; Object already exists,” it said. Ok, I just need to change the UUIDs in the files, I thought.

I opened up all the files again, grabbed a UUID generator, and changed the UUIDs. Saved everything. Started VirtualBox back up. There were no error messages, until I tried to start a copied machine that I had changed the UUID on. What was the reason? The UUID that I changed in the .xml files was embedded in the *.vdi files.

I powered my hex editor (bless, if you’re wondering. If you know of a better editor, let me know!). I looked for the UUID. I couldn’t find it. I looked for just the end, and I found that. I looked right next to it and found that the bytes for the first three byte groups were stored in reverse order (little-endian: least significant byte to most significant byte).

I found that the offset for the UUID was at 0x188. I wrote down my UUIDs I created and swapped the format around and entered it into the .vdi files at the above offset. Here’s an example:
UUDI: {23DF45A4-4378-2019-FAB7-ED4312DCC001}
Byte Group 1: 23 DF 45 A4
Byte Group 2: 43 78
Byte Group 3: 20 19
Byte Group 4: FA B7
Byte Group 5: ED 43 12 DC C0 01

The first three byte groups need to be re-ordered from big-endian to little endian:
Byte Group 1: 23 DF 45 A4 --> A4 45 DF 23
Byte Group 2: 43 78 --> 78 43
Byte Group 3: 20 19 --> 19 20

Then putting it together:
A4 45 DF 23 78 43 19 20 FA B7 ED 43 12 DC C0 01

Grab your hex editor a replace the 16 bytes at offset 0x188 with the bytes you computed above. Viola! It should work if you’ve done everything correctly.

As I’ve said before, all of this is completely unnecessary. I just didn’t realize there was an easy was to do this inside the program itself or via the command prompt.

A great blog post on how to use the commands is: http://srackham.wordpress.com/cloning-and-copying-virtualbox-virtual-machines/

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s