Monday, January 18, 2010

Creating virtual image of your PC using disk2vhd and SunVirtualBox

Why do we need to create an image?

When we take the backups we normally do it by copying the data to some external storage. However, we know very well that it is not only data that is critical to us. Our complete PC, with OS and applications installed is the working environment that we need to carry on our work in addition to data. There is an easy way to create the virtual backup of your machine so that you can use that image on any machine and get your complete working environment back in no time. Also if you need to get another developer on the project you can create a standard dev machine image.

What do we need  ?

1. Microsoft Disk2vhd http://technet.microsoft.com/en-us/sysinternals/ee656415.aspx

2. Sun VirtualBox http://www.virtualbox.org/ (Recommended, required for 64 bit machines)

OR Microsoft Virtual PC http://www.microsoft.com/windows/virtual-pc/ (doesn’t support 64 bit windows)

3. External hard disk (with free space equivalent to you machines used disk space)

Steps:

1. Create Virtual image using Disk2Vhd. Either do it from command prompt or through UI. Remember to ensure that your external drive is formatted on NTFS otherwise it will not create more than 4GB file. For my 67 GB image it took around 2 hours to create the file on external drive. Also if you gave got other virtual images on your PC’s drive then better backup them manually from your machine hard disk to external hard disk in order to keep the back up image size small. I wonder if we can get an option in Disk2Vhd to select the files/folders that we want to be excluded from the image.

Command Line Usage

Disk2vhd includes command-line options that enable you to script the creation of VHDs.

Specif the volumes you want included in a snapshot by drive letter (e.g. c:) or use "*" to include all volumes.

Usage: diskvhd <[drive: [drive:]...]|[*]> <vhdfile>
Example: disk2vhd * c:\vhd\snapshot.vhd

User Interface

ee656415_Disk2vhd_1_4r(en-us,MSDN_10)

 

2. Once the image is taken then you can run Sun VirtualBox and create a new virtual machine. Select the right parameters (like the operating system of your original machine) and allocate enough RAM (at least 50% of the original machine). Now you just need to start the machine. With Sun VirtualBox you do not need to worry about creating loopback connections as we do in MS VirtualPC. As soon as your virtual machine comesup it will be able to start using the network connection of the host to access internet.

Here is the image of my own machine running on the original machine.

 

machine into machine