Windows

How do I create a virtual image of a working Windows installation with Disk2vhd?

Learn how to take your current Windows installation and create a vhd image that can then be imported into your virtual machine tool of choice.

For so many administrators and developers, virtual machines can be a very easy way to save time and money as well as beef up security. For Microsoft Windows users there are a few options for creating and using virtual machines. You can employ either Microsoft Virtual PC or Microsoft Hyper-V virtual machines to run instances of a Windows operating system as a guest on a Windows host machine. But that leaves the question of where do you get the images?

You can always install a fresh image or visit one of a number of sites that allow you to download various images in vhd format that can then be imported as a virtual machine. But what if you want to create your own virtual machine? What if you have created the perfect installation that you want to import as a virtual machine? How does one do that? Of course, there are tools for just that task. One of those tools, Disk2vhd, was created by Sysinternals (makers of many fine applications).

In this tutorial, you will learn how to take your currently running Windows installation and create a vhd image that can then be imported into your virtual machine tool of choice (so long as it supports vhd files).

This blog post is also available in PDF format in a free TechRepublic download.

How it works

Disk2vhd can create images from any drive attached to a PC so long as the drive has the necessary files. The tool works by using the Windows' Volume Snapshot capability found in any Windows operating system, starting with XP and later. In fact, the best method of using this tool is to save the .vhd file to an externally attached drive. If you save the image to the same drive you are taking the image from, performance will seriously degrade. Since the process is already fairly slow, you do not want to make matters worse.

You will also need to make sure that you have plenty of space on the target drive. Most likely the installation you are using to create your image is not a clean installation, but a specific image with various applications and configurations. This will cause the size to grow quite a bit. This also brings up another issue: If the drive is a VFAT-formatted drive, your image file cannot be over 4GB. So make sure either your file system will accept larger files or your vhd file is less than 4GB.

So, with that said, let's take a look at how this tool is used.

Getting and installing

There really is no installation involved with Disk2vhd. This application is not an installer file but a self-contained binary, which can be executed from any location (even a thumb drive). So when you download and extract the Disk2vhd file, you will see four files inside the newly created Disk2vdh directory. Of these files, the one you will use is disk2vhd. You can either double-click that file from within the Disk2vhd directory or pin the file to either the Start menu or the Quick Launch menu.

When you start the application, you will see the main window (Figure A). There is no configuration window, which makes this tool simple to use.

Figure A

The only configuration options available are selecting the volumes to include and determing the location of your target file.

As you can see, I have set the location of my target file to be on an external hard drive. This ensures that I have enough space for the image as well as keeps the process from dragging my machine to a crawl.

Once the minimal options are taken care of, all that is left to do is to click the Create button. Once you have done this, the process will begin. Depending on the size of your image file, this process could take some time. During the creation, you will see the progress bar very slowly inch across the window (Figure B).

Figure B

The time indicated on the bottom right of the window is an approximated completion time. In this case, the completion will take about thirty minutes.

Once the process is complete, you will have a file on your target drive named after your PC with the extension .vhd. It is this file that you can then import into the virtual machine tool of your choice. Without going into the specifics of each virtual machine tool, the process of adding these image files is simple:

  • Create a new virtual machine with the characteristics that match the machine used to create the image file.
  • During the process of creating the virtual machine, use the vhd file as the new machine's IDE disk.
  • When you first boot the new machine, the virtual machine tool will detect the machine's hardware and automatically install the drivers.

Those steps could vary, depending on the virtual machine tool you use.

Final thoughts

If you are an administrator who depends on virtual machines, then you need to take advantage of this incredibly handy tool. With Disk2vhd, you can create a very specific machine image for deployment via virtual machine.

Stay on top of the latest XP tips and tricks with TechRepublic's Windows XP newsletter, delivered every Thursday. Automatically sign up today!

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

24 comments
micron_z
micron_z

Does this allow instalation on fresh drive with all updates?(formated)

prashant.siemens
prashant.siemens

Hi, I have tried to run the same image on win2k3 in Virtual PC 2007 but not getting start. Getting blank screen....

prashant.siemens
prashant.siemens

Thankx...Information seems good. I have downloaded the s/w & will check soon. Thankx for info.

pgit
pgit

I tried this tool and it completed ok, but the image won't boot in virtualbox. I haven't tried it in VMWare yet, but this is on Linux so it's not guaranteed I can get VMWare installed properly... :\

ty
ty

Backed up a Laptop running Vista 32-bit to a VHD and tried creating/running the VM in Virtual PC 2007 SP1 on Windows XP 32-bit....VM tries to start but just stays on a black screen. Anyone else havint this issue?

esecson2000
esecson2000

Why not just use sanboxie to create a virtual sandbox and then back that up to an external drive.

AstroCreep
AstroCreep

I just used it a few weeks back to make an image of a computer that belonged to a company we acquired. It's nice because I have all of the data available if I need it (without the need to even boot the disk) and I can redeploy the original workstation (wasn't that old to begin with). When you mount a VHD in Win7 you can even open it as "Read Only" so you don't screw with the integrity of the file store.

Spitfire_Sysop
Spitfire_Sysop

I have some legacy systems used that need network access in NT. Does anyone know if I can easily duplicate these systems in a .VHD for a backup? I would need to rely on this image if the system goes down.

Mark W. Kaelin
Mark W. Kaelin

What application or applications do you use to make virtual images? Have you tried Disk2vhd?

Justin James
Justin James

This utility doesn't do anything about the drivers, kernel being used, and so on. Basically, you've cloned the disk onto new hardware, which is no guarantee that it will work (although it tends to work well in Unix-like OS's, I've found). In other words, this is NOT a physical-to-virtual tool! J.Ja

AstroCreep
AstroCreep

...checking the box labeled "Fix up HAL for Virtual PC"? If not, go ahead and try it again with that option checked and see how it works. If you DID check the box and it's not working, try it again with it UNchecked.

Justin James
Justin James

This utility doesn't do anything about the drivers, kernel being used, and so on. Basically, you've cloned the disk onto new hardware, which is no guarantee that it will work (although it tends to work well in Unix-like OS's, I've found). In other words, this is NOT a physical-to-virtual tool! J.Ja

Justin James
Justin James

I'm just going to post the exact same response to each of these similar items... This utility doesn't do anything about the drivers, kernel being used, and so on. Basically, you've cloned the disk onto new hardware, which is no guarantee that it will work (although it tends to work well in Unix-like OS's, I've found). In other words, this is NOT a physical-to-virtual tool! J.Ja

AstroCreep
AstroCreep

Did you create a new VM to use this VHD, or an existing VM? If so, did you configure it as a Windows Vista VM? Did you try booting it into Safe Mode?

daffoml
daffoml

See Justin's comment above. Hyper-V's P2V utility is just what you're looking for, you snap an image of the current box, and bring it up on a shiny new virtual box, forget the old hardware.

AstroCreep
AstroCreep

Have you tried using WinPE (or something of the like)? I haven't used WinPE much personally, so I don't know how it may (or may not) utilize VSS. There's also gotta be some free, pre-boot tools out there to make a snapshot of a volume that can be written as a virtual hard disk. Might want to see if VirtualBox has anything fitting the bill, as I know they can work with VHDs.

sfareed
sfareed

Hi, Disk2vhd is compatible with all Microsoft operating systems and their 64-bit editions. A download is available at the Sysinternals website. It is furthermore possible to run the tool directly from live.sysinternals.com. www.sysinternals.com

Justin James
Justin James

... because the OS will be booted in a VM with no clue what hardware drivers to use. I guess if I just wanted to mount the drive to pull data off of, that would be fine. Really, if you want to actually boot off of a virtualized drive, you are much better off using your virtualization system's P2V conversion utilities. Both Hyper-V and VMWare offer an agent based system that will convert most common OS's to a VM with the appropriate transferring of network settings and driver replacement. I can't speak for VMWare, but if I were using Hyper-V (which I do), Disk2Vhd is useless, because Hyper-V already supports this functionality. Indeed, I was even able to convert a FreeBSD physical machine to a Hyper-V VM, with a bit of elbow grease (http://www.formortals.com/how-to-perform-a-p2v-conversion-for-freebsd-to-run-on-hyper-v/). J.Ja

pgit
pgit

I tried this with a windows box, then tried the VM running on the very same box and it didn't go. Can't get any closer to 1 = 1 than that. So what is the holy grail? I tried running a physical hard drive installation of windows in a VM hosted on Linux and could never get it to go. Scary registry hacks and boot sector mayhem. I'd love to be able to fire up the windows installation in a VM for the few times I need it, rather than having to shut down Linux and reboot into it. I know it can be done, but apparently not easily.

ty
ty

Agghh! I wish the info I read before doing the process with D2VHD made it clear that this was for mounting the VHD only for data access. I have since wiped and reloaded the system, so I guess I won't be able to recover the system that is on the VHD, just get to the data by mounting the VHD. Justin, Thanks for the info on using the Hyper-V P2V tool. I will remember to use that next time. Ty

Realvdude
Realvdude

I agree that usually the best tool for the job is from the software that will be the consumer of the end result. Though I have been moving Windows installations between different machines for many years with great success, with the exception of NT. There is one caveat in that the OS will not remove the drivers for the old hardware; you can do this manually. I would also suggest that the first boot be in safe mode to limit the number of drivers that will attempt to load.

Justin James
Justin James

Hyper-V is free, System Center Virtual Machine Manager is not. Hyper-V does *not* come with free P2V tools. Paragon makes some tools in their backup and recovery series which can do P2V (and I beleive can handle Hyper-V), but I do not know the pricing details off hand. Point is, you can't just do a disk-to-disk image on the drive and expect it to work, in Hyper-V or VMWare, or whatever, at least not on the system disk. :( J.Ja

nnehrer
nnehrer

J.Ja, when I searched for System Center Virtual Machine Manager and got the home page I saw trial downloads but it also mentioned pricing and licensing. Does Hyper-V come with any free P2V tools? I've got it installed and running one VM but can't seem to find the P2v utilities. Thanks for the help.

Justin James
Justin James

Even when you are running the VM on the same hardware that the physical machine was on, the VM sees different hardware because the VM system abstracts it and presents a virtual device, not direct access to the hardware. The proper solution is to use the P2V converter which is available for your VM system. For Hyper-V, there is the System Center Virtual Machine Manager; it is a giant application with a zillion uses, but I installed it *solely* for its P2V and V2V (to convert VMWare VMs to Hyper-V) utilities. I know that VMWare has a similar system, but I do not know if it is free or not; I used it when converting a machine for use in VMWare Workstation. Regardless, the P2V and V2V utilities makes the boot sector changes and registry hacks and they do a very safe and good job of them. They also do them within the image itself, not the base system before the conversion, so it doesn't mangle your PC. There is no way around the need for registry hacks and boot sector changes, due to the virtualized hardware. You will find that once you have the utility, things are very smooth. The only hangup I've had with either one, is that if the machine uses a static IP, it is good to fire up Device Manager in a special mode that allows it to show the old, physical NIC and remove it so Windows doesn't complain that an installed but non-present NIC has the same IP address. J.Ja

Editor's Picks