Cloning Virtual Box Machines
By Adil James, MMNS
Virtual Box is probably the best program, currently, for making virtual machines. I haven’t tried the others, but I did Google the issue and by reputation it’s by far the fastest, and it’s free. It’s made by Sun, so with the backing of such a major tech company you know it has to be pretty good.
I have had two virtual XP installations running at the same time on a dual core machine with 2.5 gigs of RAM. I had a full load of other programs running as I recall, including Firefox (which sometimes eats a lot of memory). They ran okay but did crash the machine (grinding everything to a standstill, which had never happened before)—still I am amazed at how well the whole thing functioned.
We happen to have several XP Pro licenses because we bought several machines brand new, some of which are now running other OSs.
An issue with Virtual Box machines is cloning, however. It should actually be pretty easy to clone a machine, but actually it takes some doing. So I am going to give you the solution that I came to after some effort and lessons learned.
Of course it’s a good idea to get the copy of the virtual machine into good shape (i.e. activated if applicable, with the programs that you want, whatever settings you want, and all the updates run). These instructions assume you have Virtual Box running on a Windows machine (here Windows 7 RC [sorry, I made a mistake, this is really windows XP running with a facelift (using Seven Remix) to look like W7… but I would think these basic principles still apply to W7 although I have not tested these directions under W7]), and in this case the Virtual Box machine I am cloning is also Windows (here XP). This method uses a “non-documented†internal command of Virtual Box that could be turned off at any time by Sun but as of yesterday (January 19, 2010) and today too, it worked fine. There is another way using a documented command (clonehd) but I used the non-documented command because I had already made a copy of the drive I wanted and the easiest thing seemed to be to just make it usable—and this way worked for me and made sense to me.
Although we did this on a Windows machine it should be pretty similar and about as easy in another OS, for example in Linux it is pretty routine to work on the command line so should be easier I guess. Most of the instructions on the web seemed like they were aimed at Linux/Ubuntu users so that is why I did this instruction set for Windows. Should make it easier to follow the paths and figure out where the necessary files are.
I don’t know what will happen if you have snapshots of the drive you want to clone—I didn’t have any snapshots of mine. In many directions the first step is to get rid of all snapshots.
Be careful because these virtual machines will eat a hard drive very quickly. I have about four virtual machines and my C drive went from being healthy and half empty to being nearly filled to capacity in just a couple of days.
Sorry, you have to go to the command line to do this.
Here is step by step how to do it:
Before you begin you must make sure the virtual machine to be cloned is turned off.
1) Make a copy of the .vdi file for the machine you want to clone. The path is:
C:\Documents and Settings\[user]\.VirtualBox\HardDisks\*.vdi
Just right click the file you want and copy it, giving the new file an easy-to-remember name, like for example “XP.vdi†is the original file and “XPCopy.vdi†is the new copy of it. Paste the copy into the same folder.
2) Reset the user id of the copy. This is the part of the procedure that uses an undocumented command, namely “sethduuid†(here are the instructions I used but I will summarize below):
Open a command window: Start – Run – type “cmd†in the box to open a black command window.
Type the following commands (filling in your user name in the [user] box) in the command window:
cd C:\Documents and Settings\[user]\.VirtualBox\HardDisks
“C:\Program Files\Sun\VirtualBox\VBoxManage.exe†internalcommands sethduuid XPCopy.vdi
In above command make sure the path is right on your machine, and don’t forget the quotation marks around the path to VBoxManage.exe. Of course you will have to put the correct name of your copied hard disk image, in this example I used XPCopy.vdi (and in the actual demo below I used “XPCopy2.vdiâ€) but yours is likely different.
3) Now you have to make a new Virtual Box machine and link it to your clone:
Open Sun Virtual Box … New … Next … [type the name of your clone machine and change the OS and version as necessary] … Next … [i just use the defaults] … Next … click “use existing hard disk†and click the folder button, click “Add†and browse to the new .vdi file (in my example mine is XPCopy.vdi) … click “Open†… Select … Next … Finish
Ha. You’re all done. Start that new clone up and you’re in business. I just followed these steps myself and it all worked but in case I left out a step or something please leave a comment on this article, which will eventually come to my attention.
I love your comments so whether you want to say thanks or want to say this doesn’t work for you or something please add a comment.
Errors:
1) I renamed a copy then stored the copy on an external drive then brought the .vdi copy back to the VirtualBox/HardDisks folder, and when I tried to reset the user id and got the error message “VERR_FILE_NOT_FOUNDâ€.
I kept getting this error, but not now…
I suspect I was not in the “HardDisks†subdirectory and this is why I was getting this error. You must be in the correct directory where you have the copy before this sethduuid command will work.
2) The whole reason I realized the importance of resetting the user id was because I got the error “Cannot register the hard disk…†“UUID … already exists in the media registry†when I tried to link to a .vdi image from a new machine, but without first going through the procedure of resetting the user id. The user id is attached to each virtual box image by Sun, not Microsoft. You cannot just copy another virtual machine’s hard disk and then start a new virtual machine and link to it, you’ll get the user id error.
2010
1,074 views
views
0
comments