TechOnTip Weblog

Run book for Technocrats

Hyper-V Virtual Machine Recovery

Posted by Brajesh Panda on August 15, 2010

  1. Scenario: 1

Best way for backup/restore/movement of Hype-V virtual machine is export & import process.

Export Process

  • Switch off the Virtual Machine
  • Right Click the Virtual Machine
  • Click On Export
  • Provide the path where you like to export the virtual machine

Import Process

  • In case you are importing to same Hyper-V server make sure you rename the old VM for as “-Old”. This is for only identification purpose
  • Open Hyper-V MMC Console
  • Right Click Hyper-V Server
  • Click Import New Virtual Machine
  • Provide Path to the folder where exported virtual machine is located
  • Select Move/Copy as per your scenario. If you are importing to same Hyper-V server, better to select generate a new SID for the virtual machine. It will avoid any conflict with old server

     

  1. Scenario: 2

Sometime we wrongly delete virtual machines from hyper-v console or if host OS get’s corrupted we found orphan virtual machines. These Orphan VMs can’t be directly imported to Hyper-V console. But no need to be panic… there are some manual steps by which you can register those VMs to the hyper-v console. But I think this is a unsupported process by Microsoft.

Note:

  • In case you would like to re-build/re-install the Hyper-V OS make sure none of the config file or snapshot files are in OS system drive. Else you will lose data at the time of formatting.
  • You may need same version Hyper-V instance to recover

How much you are lucky??

  • Do you have complete VM i.e. Virtual Machine Config File, All VHDs in a single location or you know the location where are they? – If not, it is worst!
  • Do you have multi snapshot virtual machines?? – If yes, it is worst. Hold your horses!

 

 

Disconnected VM Re-registration Process

If Virtual Machine VHD, AVHD & corresponding XML files are intact in the original location, No worries. Else, if you are coping/collecting/restoring all files to a single folder, you may have to edit XML files to mention actual VHD & AVHD paths.

  1. Note down system path to the virtual machine config file. Let suppose S:\BRAJESHTESTVM\
  2. Note down VM GUID name from the XML file. You can select the xml file & press F2, then Ctrl + C to copy the name. Let suppose “51CB2AF3-64D3-468A-863D-7E0C349F2261
  3. Open XML file & Verify VHD & AVHD are present as per mentioned locations
  4. In Windows Explorer open
  • C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines
  1. Right Click on Virtual Machines folder with Shift Key. Click on Start Command Prompt from here
  2. It will open up command prompt from the directory
  3. Create a symbolic link to the VM Config XML file using below command
  • C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines>mklink 51CB2AF3-64D3-468A-863D-7E0C349F2261.xmlS:\BRAJESHTESTVM\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261.xml
  • If syntax of the command is correct you will get a result like below

    Symbolic link created for 51CB2AF3-64D3-468A-863D-7E0C349F2261.xml <<===>> S:\BRAJESHTESTVM\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261.xml

  • Now you will able to see a symbolic link XML file inside the C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines folder
  • And also you will able to see the VM has been registered in the Hyper-V Console.
  • However if you try to start/switch this VM on you will get below error; as file access permissions are not configured correctly.

     

  1. In the same command prompt use below command line parameters to set right permissions. Over here we are configuring Full Control permissions, however you may configure respective granular permission. I would like to recommend configure Full Control & later on after recovery fine tune the permissions accordingly if you want.
  • C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines>icacls “C:\ProgramData \Microsoft\Windows\Hyper-V\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261.xml” /grant “NT VIRTUAL MACHINE\51CB2AF3-64D3-468A-863D-7E0C349F2261“:(F) /L
  • Observe the F & L at the end of the command, L means we are working on a symbolic link. F means full control permission. “NT VIRTUAL MACHINE\51CB2AF3-64D3-468A-863D-7E0C349F2261″ is the service SID which need permission to start the VM. It is a combination between “NT VIRTUAL MACHINE” & VM GUID.
  • If syntax of your command is correct it will result below output on your cmd prompt console processed file: C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261.xml

    Successfully processed 1 files; Failed processing 0 files

  1. Before you start/switch on the Virtual Machine I would like to suggest to verify if this VM has any previous snapshots. If yes, you have to complete same procedure for each snapshot files before you switch on your VM.
    For each snapshot follow step 10 to 16. Else move to step 17!

Snapshot Registration Process

  1. In Original Virtual Machine data folder browse snapshot folder. Note down system path & GUID of the virtual machine snapshot config file. (If you have multiple snapshots you have to perform same task for all of them one by one). Let suppose we have one snapshot & it’s GUID is
    21B074A8-DA46-4FF1-A163-2E4B1551DCFF
  2. Open XML file & Verify VHD & AVHD are present as per mentioned locations
  3. In Windows Explorer open
  • C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\Snapshots
  1. Right Click on Virtual Machines folder with Shift Key. Click on Start Command Prompt from here
  2. It will open up command prompt from the directory
  3. Create a symbolic link to the VM Config XML file using below command
  • C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots>mklink 21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xmlS:\BRAJESHTESTVM\Snapshots\21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xml
  • If syntax of the command is correct you will get a result like below

    Symbolic link created for 21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xml <<===>> S:\BRAJESHTESTVM\Snapshots\21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xml

  • Use below command syntax to provide proper permission to the VM GUID C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots>icacls “C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots\21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xml” /grant “ NT VIRTUAL MACHINE\51CB2AF3-64D3-468A-863D-7E0C349F2261“:(F) /L
  • Remember NT VIRTUAL MACHINE\51CB2AF3-64D3-468A-863D-7E0C349F2261 is the VM GUID.
  • If syntax of above command is correct it will give below results in the command prompt

    Processed file: C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots\21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xml

    Successfully processed 1 files; Failed processing 0 files

  1. From hyper-v console verify respective vm is showing reference to all snapshots & VHD config is pointing to the right VHD & AVHD files. If yes move to step 17 for next action.

Final Permission configuration

  1. Before you switch on the VM, make sure VM Service ID (GUID) has right permission on each VM files including VHDs. Use below syntax to configure the same.

    S:\>icacls
    S:\BRAJESHTESTVM\ /T /grant “NT VIRTUAL MACHINE\51CB2AF3-64D3-468A-863D-7E0C349F2261“:(F)

  • If syntax of above command is correct you will get below result in the command prompt

processed file: S:\BRAJESHTESTVM\

processed file: S:\BRAJESHTESTVM\BRAJESHTESTVM_C_Drive.vhd

processed file: S:\BRAJESHTESTVM\BRAJESHTESTVM_C_Drive_6DA4425D-5C8E-4247-9AB4-43A0F8F362DE.avhd

processed file: S:\BRAJESHTESTVM\BRAJESHTESTVM_D_Drive.vhd

processed file: S:\BRAJESHTESTVM\BRAJESHTESTVM_D_Drive_E52E811F-7946-4FAE-BA4F-7545C363EF73.avhd

processed file: S:\BRAJESHTESTVM\Snapshots

processed file: S:\BRAJESHTESTVM\Virtual Machines

processed file: S:\BRAJESHTESTVM\Snapshots\21B074A8-DA46-4FF1-A163-2E4B1551DCFF

processed file: S:\BRAJESHTESTVM\Snapshots\21B074A8-DA46-4FF1-A163-2E4B1551DCFF.xml

processed file: S:\BRAJESHTESTVM\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261

processed file: S:\BRAJESHTESTVM\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261.xml

processed file: S:\BRAJESHTESTVM\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261\51CB2AF3-64D3-468A-863D-7E0C349F2261.bin

processed file: S:\BRAJESHTESTVM\Virtual Machines\51CB2AF3-64D3-468A-863D-7E0C349F2261\51CB2AF3-64D3-468A-863D-7E0C349F2261.vsv

Successfully processed 13 files; Failed processing 0 files

  1. Let’s switch on the virtual machine; BANG, vm is not starting. It will throw below error

  • It is related to Virtual Ethernet Network Card. If you go to setting of virtual machine you will see “configuration error” for network cards.

  • Either connect them to a valid virtual network switch or configure them as not connected.
  • Now you should able to switch on your virtual machine.
  • After you start your virtual machine, you may need to clean up unused & hidden network cards to use same old IP address.

 

 

 

 

 

 

Advertisements

2 Responses to “Hyper-V Virtual Machine Recovery”

  1. Download e-music…

    […]Hyper-V Virtual Machine Recovery « TechOnTip Weblog[…]…

  2. i3laze said

    Great article! Saved my day after Hyper-V host reinstall.

    Used Explorer to search for *.xml original paths in common folders c:\hyper-v d:\hyper-v to recover 10+ VMs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: