On a regular base I need to do physical-to-virtual (P2V) conversions at clients, to turn physical machines into virtual machines (VMs). The only problem is that in the current SCVMM version, namely SCVMM 2012 R2, the P2V functionality has been removed. As a solution you can install a down-level version of SCVMM, like the 2012 SP1 version, but in this blog post I will explain you how to do it with use of the disk2vhd tool from Microsoft.
You will need to follow the steps below:
1) First of all clean up the server that will be converted to a VM and remove all unnecessary software. Check the Event Viewer for critical problems and fix them. Also run Windows Updates and install all necessary updates.
2) Secondly open a command prompt and run “sfc /scannow”.This command will inspect all of the important Windows files on the server, including Windows DLL files. If the System File Checker finds an issue with any of these protected files, it will replace it.
3) As a third step run “chkdsk /f c:”.Check Disk will then perform an analysis of the disk and repairs all errors on the C: drive. If the volume is in use (like the C: drive always is) chkdsk will run on start-up. So close all applications and reboot the system.
4) When the chkdsk is completed, boot into the operating system and defrag your C: drive with “defrag /f c:”
5) As a next step first download “Contig v 1.7” here. Contig is designed to defragment individual files, or specified groups of files, and does not attempt to move files to the beginning of the partition. Combined usage of the -s parameter and the wildcard symbol * allows whole directories and drives to be defragmented. Run “contig –s c:\*”
6) When the contig has finished, use the Microsoft Virtual Disk Pre-Compactor tool to write out all of the free space to zeros. You can download the Precompact tool here. Run “precompact.exe”
7) Now we are ready to use Disk2vhd v2.01 to make a new, dynamic-sized VHDX file. You can download the tool here. Preferably create the new disk on another disk then the C: because the tool uses a lot of IOPS.
8) When the new VHDX is created, copy it to the preferred location. It’s best you copy it to the Clustered Shared Volume (CSV) where the VM will reside on. In my example I copied it to: C:\ClusterStorage\Volume4\”VM folder”
9) As you can see in the screenshot below the disk now has a size of 125 GB.
10) The next step is to create a new VM (same name as the physical server) with SCVMM and attach the VHDX as the drive where the OS resides on. Then shut down the physical machine and boot up the VM. It should start, adjust the IP address to the one of the physical and the P2V should be done.
11) Now open up a Hyper-V Manager on the host and install the Integration Services. I always do this from the Hyper-V host and not from SCVMM, simply because it’s faster.
12) An important step is to convert the dynamic VHDX to a fixed-sized VHDX (only fixed-sized VHDX are supported by Microsoft in a production environment). So in SCVMM open the properties of the VM, and go to Hardware Configuration. Here you change the dynamic disk to a fixed one. When running you see the following job in progress.
13) As a last step you can adjust the size of the VM, so it uses less disk space on your CSV. To do this you need to RDP to it. When connected open run and type “diskmgmt.msc”. This command will open Disk Management. There you can shrink the volume. Shrink it as most as possible. When shrinked there will be unallocated disk space. In my case around 325,31 GB.
14) After the shrink, go back to SCVMM and reopen the properties of the VM, go to Hardware Configuration and select “Compact virtual hard disk”.
15) The result you can see below. The fixed VHDX now only uses 140,45 GB instead of 465,42 GB.
This concludes this blog post, hope it helps!
Keep tuned and I will be back with more.
Wim Matthyssen (@wmatthyssen)