0

How To Import Windows 2008 R2 VM To Windows 2012 or 8.1 Using Boot To VHD

One of the popular topics lately has revolved around the Hyper-V Did Not Find Virtual Machines To Import error.  This issue can arise when we try and import a VM into Windows Server 2012 R2 or 8.1 which was originally exported from Windows Server 2008 or 2008 R2.  Such exported VMs from 2008 or 2008 R2 use a .exp file to hold the exported VM's configuration.  The issue is discussed in detail in the previous post, but one item that was worth teasing out was how to get the VMs into a state where they can be imported easily into Windows Server 2012 R2 or 8.1 without discarding the old VM configuration.

This is important as chances are there are many people out there with VMs exported from Windows Server 2008 or 2008 R2 that they will want to re-use in the future.  Consider the scenario where you have just finished installing 8.1 and you then realise that the old VMs will not import.  Do you really want to:

  • Wipe Windows 8.1
  • Install Windows 8
  • Import the VMs
  • Copy off the VM files
  • Wipe Windows 8
  • Install Windows 8.1
  • Import VMs

Backing up data, re-installing apps and applying Windows Updates is also likely in the above scenario, but the above list is enough to illustrate the point….

Hopefully the answer is no.  So what to do?  Well as Travis suggested in a comment we can use the Windows boot to VHD feature to get a parallel install on Windows running where we can perform the intermediate import task.  All this this can happen without impacting our main installation of Windows.

In this example we will have a machine running Windows Server 2012 R2.  As discussed 2012 R2 and 8.1 cannot import a VM which was exported from Hyper-V 2008 or 2008 R2.  We will:

  1. Create a VHD to hold parallel copy of Windows Server 2012
  2. Install Windows 2012 (non R2) into the VHD
  3. Copy and Import the VM
  4. Copy out the converted VM
  5. Import Converted VM into 2012 R2.

The steps are interchangeable for Windows 8.1 and 8.  So feel free to install Windows 8 into the VHD, this walkthrough uses Server 2012 instead.

Before embarking on the below, please make sure you have read and understood all the options at the bottom of the previous post.

The steps in this article are only necessary if you do not have any other Windows 2008 R2, Windows 8 or Server 2012 machines.  If you still have one of those machines your legacy (.exp) exported VMs can be imported without having to do the above.  Once imported simply copy over the VM folder to Hyper-V 2012 R2 or Windows 8.1

Create VHD

We will create a VHD on the root of the C: drive whilst running Server 2012 R2.  Note the start menu button to indicate that the below image is from 2012 R2.  This VHD will hold the OS for the copy of Windows 2012, and since we install Windows 2012 to the VHD the Server 2012 R2 installation will not be modified!  For more details on boot to VHD scenarios check out TechNet.

Open up Computer Management, then navigate to Disk Management.  Right Click and select Create VHD.

Create New VHD For Boot To VHD

Note that the VHD must be sufficiently large to hold the new Windows 2012 install with pagefile etc.  If you want to copy the VM to import to this partition later then allow additional space.  Alternatively leave the VM on a USB disk and attach that once the parallel copy of Windows is up and running.

In the Create and Attach Virtual Hard Disk window specify the options below, though the disk size can be increased as mentioned above.

Create Dynamically Expanding Windows 2012 VHD

In this case we shall make a VHD of 60 GB at the root of C:.

No need to do anything else to the VHD, next we will restart Server 2012 R2, boot off the DVD and install Server 2012 into the VHD just like it was a normal hard disk.  Well almost…

Install Windows Server 2012

Restart the host machine to boot from the Windows 2012 DVD, and click Install now.

Install Windows Server 2012

Lets select Windows Server 2012 Standard with GUI.  Again note this is Server 2012 --- not the R2 build!

Install Server 2012 Into VHD

Review and accept the license terms.

Accept License Terms

This will be a custom install since it is a fresh installation of Windows.  Remember the intent is not to interfere with the running copy of Server 2012 R2.  Also upgrading 2012 R2 to 2012 would be slightly strange…..

Install Windows 2012 Into VHD - Accept License Terms

Press Shift + F10 to activate the command prompt.  This party trick goes back to Windows 2000 days.  Prior to that there was the browse for LMHosts file in NT  and from the browse window you could run cmd.exe and get a cmd prompt.  I digress…

You will need to ensure that you know what drive letter the Win-2012.VHD file is now on.  It will not be on C:  so check the drive letters so you know where it is.  Once this is confirmed proceed to the next step.    In the example here it is on D: but other systems will be different.

In the command prompt we will use Diskpart.exe to mount up the VHD file that was prepared in the Windows Server 2012 R2 environment.  Run the following:

Diskpart.exe

Select VDisk file=D:Win-2012.vhd

Attach VDisk

Install Windows 2012 Into VHD - Attach VDisk Using Diskpart

Make sure that the Attach VDisk command was entered, else the disk will not be visible.

Click Refresh, and the VHD will appear.  Double check that the size is what we expect, 60 GB to ensure we do not install to the wrong partition, select this disk for the Server 2012 installation and click Next.

Install Windows 2012 Into VHD - Select VHD

Ignore the error stating that “Windows can’t be installed on this drive”.  For reference the details are:

Install Windows 2012 Into VHD - Ignore Error

Windows 2012 will install and do its thing….

Go get a coffee or Ardbeg depending upon what time it is or your preference…

Install Windows 2012 Into VHD - Coffee Time

Once installed, boot to the Windows 2012 installation.

We will need to install the Hyper-V role.  Using PowerShell run either:

Add-WindowsFeature Hyper-V –IncludeManagementTools –Restart

Or

If copying files from a Bitlocker encrypted disk, also install the Bitlocker feature run:

Add-WindowsFeature Hyper-V,Bitlocker  –IncludeManagementTools –Restart

Hyper-V will be installed, and Windows will restart automatically.

Now we are ready to import the legacy (.exp) VMs into our temporary Server 2012 installation.  They do not need to be powered on or anything, this is only to import them.

Copy And Import VMs

Here is the Server 2012 install.  For confirmation, note there is no start button.

Windows 2012 - Empty Hyper-V Manager

Attach, copy or do whatever is necessary to get your old VM files onto this machine.  In the below screenshot we see a VM called AD1HC1 that was copied to the C:Working folder.

This VM’s directory structure is shown below.

Note the .exp file which indicates that it was exported from Windows Hyper-V 2008 or 2008 R2.  Also note there is no XML file for the vm – only config.xml exists.

2 directory dtructure on 2008 r2 exp VM

In the Hyper-V console, right click the server name start the VM import wizard.

Browse to the folder containing the VM, and click Next.

Windows 2012 - Import VM

Confirm the VM name, and if correct click Next.

Windows 2012 - Import VM

When importing a VM in the newer versions of Hyper-V there are different options to import a VM in place.  Since we are using Windows 2012 we have these optionsHyper-V 2008 R2 had different ones.

In this case the files are where I want to use them, so lets use the Register option to suck them up as-is.

Click Next.

Windows 2012 - Import VM Register In Place

The import wizard completes. Click Finish.

Windows 2012 - Import VM Finshed

The legacy VM is now imported into Hyper-V 2012.

Copy Out The Converted VM

The VM is now imported and is visible in the Hyper-V interface.  There is no need to power on, since we just need to use this process to convert the VM to a format that can be imported to Windows 2012 R2 Hyper-V .

Windows 2012 Hyper-V VM imported - Visible In Hyper-V Manager

The export process in Windows Hyper-V 2012 is pretty much a straight file copy so we can either:

  1. Use the Hyper-V export wizard
  2. Copy out the files we need

Remember in this example we copied a VM called AD1HC1 to the C:Working folder.  So we need to copy over the contents of this folder to the original Windows 2012 R2 OS.

If your VM files were located on an external USB disk this makes things easy.  Once the files are where you need them restart and boot into Windows Server 2012 R2.

Import Converted VM into 2012 R2

Now that we are back into Windows Server 2012 R2 (note the start button is present), we are able to import the converted VM files.

Windows 2012  R2 Hyper-V Manager

One thing to note, check that there is no .exp file present in the VM folder that you are going to import to Hyper-V 2012 R2.  This was discussed in a previous post.  You will get an error if this is present.

Fire up the Hyper-V import wizard, and navigate to the folder that contains our converted files.  In this case I copied the VMs from C: Working to a USB disk that is now mounted as F:.

Select the VM and click Next.

Windows 2012  R2 Hyper-V Manager - Import Converted VM

Confirm the VM name, and click Next.

Windows 2012  R2 Hyper-V Manager - Import Converted VM

As before we have the options below when importing, chose as appropriate and click Next.

Windows 2012  R2 Hyper-V Manager - Import Converted VM

The wizard completes, and click Finish.

Windows 2012  R2 Hyper-V Manager - Import Converted VM

At this point the VM has been successfully imported.

To prove that it works here is the VM running on Windows 2012 R2.  Note that the creation date is the 19th of February 2010 and the VM has all of its original configuration.

Windows 2012  R2 Hyper-V Manager - Comverted VM Now Running

Job done Smile

Now if you want to keep the Server 2012 install on the VHD that's fine.  If you want to remove it, the steps are below.

Cleaning Up

When done with the import and export work we can easily remove the temporary Windows Server 2012 installation by:

  1. Deleting the  C:Win-2012.vhd file
  2. Run Msconfig.  On the Boot tab delete the entry for Windows Server 2012

MSConfig - Removing VHD Boot Option

Parting Thoughts

While this is a couple of steps to go through there are a couple of points that are worth noting:

  • Only need to do this once and we can keep the converted VM.
  • This is only necessary if you do not have any other 2008 R2, Windows 8 or Server 2012 machines.  If you still have one of those machines your legacy (.exp) exported VMs can be imported without having to do the above.  Once imported simply copy over the VM folder to Hyper-V 2012 R2 or Windows 8.1

Cheers,

Rhoderick

Rhoderick Milne [MSFT]

Leave a Reply

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