This is a step by step guide on how to use Disk2VHD tool (downloaded from internet) to perform a Physical to Cloud or Virtual to Cloud migration.  We used this mechanism to migrate the eCommerce servers from their on premise Data Center to Azure and completed the migration of 40+ servers in short time frame.  We also used this mechanism to migrate Windows XP SP3 desktops to Azure.

This is a useful guide which is not available in the internet with all the steps and details, so we decided to create one.


Overview

The following guide assumes that the user has basic knowledge of using Windows and PowerShell.

Although some familiarity with the Azure Portal would be beneficial, it is not necessary, as a step by step approach will be provided.

Script workflow:

  • Download the Disk2vhd utility
  • Run Disk2vhd on the physical server you wish to convert to a Hyper-V VM
  • Create a new VM on the Hyper-V enabled physical machine and attach the .VHD(s) created by the Disk2vhd utility
  • Start the new VM (with no vSwitch) and verify everything is operating as expected
  • Remove any unwanted devices from device manager that are remnants from the physical device.
  • Install Hyper-V Integration Services (for Windows 2003 Server and older OS version)
  • Shut down physical server
  • Associate VM NIC with appropriate vSwitch and configure IP information
  • Upload this VHD to Azure Storage Blob and create a VM using this VHD

Pre-requisites

The following prerequisites must be met, before performing the Core capacity check steps.

  1. Disk2VHD tool (this can be downloaded from https://technet.microsoft.com/en-gb/sysinternals/ee656415.aspx )
  2. A shared network location where the converted VHD file can be saved
  3. A Physical server with Windows 10 or Windows 2012 R2 and above OS installed with Hyper-V Role/feature enabled.
  4. Hyper-V Integration Services installer (vmguest.iso or vmguest.iso)
  5. Internet connection
  6. Valid Azure Subscription
  7. The person who will perform the below steps must have one of the following roles in the Azure subscription
    • Owner
    • Contributor
  8. Some familiarity with the Azure Portal would be beneficial, although not necessary
  9. Latest version of Microsoft .NET Framework (download link)
  10. Latest version of Microsoft Windows Management Framework (download link)
  11. Latest version of Microsoft PowerShell (download link including detailed installation guide)
  12. Latest version of Azure cmdlets (installation guide), although steps are provided below
  13. Some familiarity with PowerShell ISE, although not necessary (documentation)
  14. Some familiarity with the Azure Portal would be beneficial, although not necessary
  15. Some familiarity with PowerShell scripting would be beneficial, although not necessary

Pre-capture Checks and Procedures

It’s a hard fact that physical to virtual conversions are fraught with peril. The older the operating system, the greater the risk. A few things that you should do to prepare:

  • Perform a complete backup to a safe location.
  • Verify that there aren’t any problems with the system. Check event logs, etc. Run CHKDSK.
  • Remove any unnecessary software and drivers, but do not make any changes to the system’s vital configuration that cannot be easily redone. If the P2V fails, you don’t want to be left with an unusable source system. RAID drivers are a common paint point but removing them will render your system unusable.
  • Optional: Remove the system from the domain. This will avoid post-conversion issues.
  • Stop as many services as possible, especially any that run databases. Disk2VHD essentially captures an application-consistent backup, but it will have superior results if all applications are closed when it runs. This also prevents anyone from using those services. Anything that happens to the system after the Disk2VHD process begins will be lost.

Using Disk2VHD in GUI Mode

Copy the “disk2vhd.exe” file to the computer whose drive(s) is/are to be converted and double-click on it from that computer. You’ll be presented with a screen like the following:

Figure 1 Disk2VHD GUI on Windows Server 2008 R2 SP1

Figure 2: Disk2VHD GUI on Windows Server 2003 R2

That screenshot was taken from a Windows 2008 R2 computer; some older operating systems will not have the “System Reserved” partition If the system that you’re creating a VHD from has this partition, you’ll need to include it if you wish for the VHD to be bootable.

Select a destination in the “VHD File Name” text box. The button at the end of that line with the triple dots serves as a browse button. If keeping the option for VSS snapshots, it’s perfectly acceptable to create the VHD(s) on the same drive that you’re copying as long as there is enough room.

Once we are satisfied with all the selections, click the “Create” button.

The software will first indicate that it is creating the VSS snapshot.

After that, it will begin the process of copying out the data. If you make any changes to the drive’s data after that, they will not be saved. You can continue to use the system during the copy process.

Output

One VHD file will be made for each disk in the source. If there is only one VHD to be created, it will be exactly the file name you specified. If there is more than one, each VHD will be the filename you specified with a hyphen and the disk number appended.

Test the VHDX

On a system with Hyper-V 2012 or later installed, run the following, substituting in your actual path:

Test-VHD -Path <path to vhd filename>\<filename>.VHD

This testing isn’t overly comprehensive, but it can identify any immediate red flags that would prevent it from being usable with Hyper-V.

Create the Virtual Machine

All that the Disk2VHD Hyper-V P2V tool does is prepare the VHD/VHDX files. It does not create a virtual machine. The following steps will demonstrate using Hyper-V Manager to create the VM using the VHDs/VHDXs that were output by Disk2VHD in the steps above.

Please do copy the captured VHDs/VHDXs from the shared location to the local drive on the Hyper-V enabled build machine before proceeding to follow the steps below.

Copy the created VHD files to a location that your Hyper-V host can access them.

Step Snapshot (if any)
Open Hyper-V Manager and ensure that the host you want to work with is selected
  1. In the right pane, click on “Hyper-V Settings…” In the dialog box,
  2. Click on “Virtual Hard Disks” in the “Server” section.
  3. The right pane of the dialog will show the folder that the host is currently set to access VHDs from.

It isn’t required that you place them in that folder, but you can be certain that the Hyper-V host will be able to access VHDs there.

Convert the VHD files to fixed size VHDs

Before we can proceed further, lets convert the captured VHDs/VHDXs to fixed size VHD files which is currently the only recognized format for any virtual machine in Azure. The below steps show how we can convert a dynamically expanding VHD/VHDX file to a fixed Size VHD file.

Step Snapshot (if any)
Open Hyper-V Manager and ensure that the host you want to work with is selected
In the right pane, click on “Edit Disk…

This will pop up the Edit Virtual Hard Disk Wizard.

Edit Virtual Hard Disk wizard

Before you Begin page, click Next

Locate Virtual Hard Disk dialog

  1. Click Browse
  2. Browse to the folder where the captured VHD/VHDX are stored on local machine. Select the file
  3. Click open
  4. Click Next to proceed further
In Choose Action dialog, select Convert as the option and click Next
Convert Virtual Hard Disk wizard

Select VHD as the format and client Next

Convert Virtual Hard Disk wizard

Choose Fixed size and click Next

Convert Virtual Hard Disk, Configure Disk wizard page

  1. Click Browse
  2. Browse to the location where the converted fixed size disk need to be stored
  3. Click Save
  4. Click Next in Wizard
Completing the Edit Virtual Hard Disk Wizard page

Click Finish after you have reviewed the details

A dialog will pop up showing the conversion progress status.

This dialog will close automatically once the conversion is completed.

Standardize the converted VHD

We now have a Fixed size VHD file which is ready to be standardized. We will now create a Virtual Machine, follow the steps below.

Step Snapshot (if any)
Open Hyper-V Manager and ensure that the host you want to work with is selected
Once you have placed the files where you want them, go to the Actions pane at the right. Click New, then Virtual Machine to start the wizard.
The first page of the New Virtual Machine Wizard is purely informational. Click Next when ready.
he first data screen asks for the name of the virtual machine and the initial location. The name that you choose will be used as a label in all virtual machine tools, including Hyper-V Manager
On the next screen (windows 10, 2012 and later), you’ll be asked to choose the Generation of the virtual machine. Choose Generation 1

Click Next

On the next screen, you set the preliminary memory settings for the virtual machine. You only have two options: the amount of Startup memory and whether you wish to Use Dynamic Memory for this virtual machine.

Just click Next with default values

Next, you’ll need to determine how to connect the virtual network adapter.

You can leave it at Not Connected, which means the virtual machine will begin its life without any network connectivity.

OR

you can connect it to a virtual switch right away

Click Next when ready

After networking, you’ll be asked to configure the first virtual hard disk for the virtual machine. Choose Use existing virtual disk option.

  1. Click Browse
  2. Browse to the VHD file that you converted
  3. Open to select the file.
  4. Click Next
Once you click Finish, the wizard undertakes all the options that you selected and creates the virtual machine.

The wizard does not turn the virtual machine on, so you have an opportunity to make any desired modifications beforehand, such as to vCPU count or memory allocation.

Right click on the Virtual Machine (from Virtual Machines pane)

Choose Connect

Start the Virtual Machine once you see the Virtual Machine Connection window popup.
When you see that the VM has started and is waiting to be logged in,

Press the Ctrl + Alt + Del button combination shortcut on the menu pane or simply by choosing Action (menu item)

If you find the Shutdown Event Tracker window, just type a message stating “disk2vhd conversion” as the reason and click OK
Additionally, if you try to click the mouse in the Connection window and get a popup as shown, that would mean the VHD is running Windows 2003 Server OS. In these case, we will require to browse and perform the initial configuration tasks using keyboard till Hyper-V Integration services are installed.
if you find any “Found New Hardware Wizard”, please press “Esc” key to ignore them.
After the system is fully logged in, you might find a System Settings Change dialog.

Press TAB key and select No.

Press Windows Start button, while you are connected to the Build Machine (in Full Screen please)

Use Navigation keys to go to Control Panel (for Windows 2003 Servers)

Choose Add Remove Programs (Programs and Features in Windows 2008 and later)

Browse to see if there are any other virtual guest agents installed, e.g. VMWare Tools, etc.

If you find, please uninstall them by selecting the Uninstall (for Windows 2008 or later) or Remove option (for Windows 2003)

Wait till the uninstall completes
If you are working on Windows 2003 Server VHD, check the next 2 steps.

If you are working on Windows 2008 and later version of OS, please go to the step of installing Hyper-V integration services straight

Once the server reboots after uninstall of any other guest agent, you will see the screen presenting 2 boot options

Choose Windows Server 2003 , <edition> option to proceed to boot. (using arrow keys)

Login with the account

  1. Browse to C:\ drive
  2. Locate Boot.ini file
  3. Delete the Disk2VHD boot entry from the file
  4. Save boot.ini file
After Reboot, we will now install Hyper-V Integration Services on the VM.

We must first attach the vmguest.iso (downloaded from the links provided earlier in this document) to the Virtual Machine Connection.

Click Media -> Insert Disk… option.

Browse the location for vmguest.iso

Select Open

You will see a popup asking you if you wish to proceed with the installation process of the Hyper-V Integration services.

Click Yes to begin the process

The installation process will require few restarts to ensure all the required services are installed and working correctly.

Click Yes.

This whole process can take up to 30 minutes per VM.

Once the VHD is ready, you will be able to use mouse in the VM you just created and can take a break from using keyboard unless to type any data or entry.

Standardization checks

Verify that Hyper-V Integration Services is installed successfully.

LAN Connection

When the Virtual Machine restarts, you will find the Local Area Connection notification which might indicate that Hyper-V services has worked and Network Adaptor is connected.

Figure 3: Hyper-V Integration Services Check – LAN connection

To confirm it, open command window by typing cmd.exe in Run dialog, in the command prompt window, type ipconfig command to see if the VM has been assigned an IP Address as shown below.

Figure 4: Hyper-V Integration Services Check – Ipconfig check

Hyper-V Services Check

Launch Services Panel (You can easily get there at any point by simply hitting WIN + R on your keyboard to open the Run dialog, and typing in services.msc), and check if the Hyper-V services are in Running or Started state

Figure 5: Hyper-V Integration Services Check – Services install check

Check Essential Services are running

Check if the windows essential services are running in the Virtual Machine, if they are with issues, please try to rectify the error before uploading to Azure. A few essential services are highlighted in the picture below:

Figure 6: Hyper-V Integration Services Check – Few Essential Services

Final Steps before uploading to Azure

The last step is to shut down the Virtual machine in Hyper-V, and upload the VHD which is described in the below steps

Step Snapshot (if any)
Shutdown the Virtual Machine from OS Level with an appropriate Shutdown Event Tracker message

Operating System: Reconfiguration(Planned)

Detach the VHD from the Virtual Machine in Hyper-V.

  1. Click File -> Settings in Virtual Machine Connection
  2. In the Settings dialog, navigate to IDE Controller 0 under Hardware and select the Hard Drive (which is the VHD file we attached)
  3. Click Remove in the Hard Drive details pane.
  4. Click OK to commit.
 

Upload the VHD to Azure using Microsoft Azure Storage Explorer

Launch the Microsoft Azure Storage Explorer and login using your Azure Portal access id.

PS: the GUI screenshot is taken based on the Microsoft Azure Storage Account version 0.8.13

Browse to the desired Storage Account and the Blob Container within where the VHD need to be uploaded from the Explorer Pane
In the right-side Details Pane, click Upload – Upload Files … option
In the Upload Files dialog

  1. Click the 3 dots next to Files field to open the “Select files to upload” dialog.
  2. Browse to the location where the Standardized VHD is stored
  3. Select the VHD file
  4. Click Open
  5. Click Upload

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami