Monday, January 6, 2014

Online export virtual machines in Windows Server 2012 R2 with Hyper-V

In Windows Server 2012 R2, the "Export" virtual machine feature was updated. Now, it supports live "Exportvirtual machines. In previous versions, administrators had to shut down the virtual machine before exporting virtual machines. Administrators can use this feature to duplicate the existing virtual machine and then import the virtual machines to test environment for troubleshooting or testing somethings. The "Export" feature also supports to export a virtual machine checkpoint. It's a great improvement of Hyper-V in Windows Server 2012 R2.

  • Export a running virtual machine in Windows Server 2012 R2 with Hyper-V role
  • Import the virtual machine which is live exported
  • Export a checkpoint from a running virtual machine
  • Import the checkpoint file to be a virtual machine 

  • 1 Windows Server 2012 R2 with Hyper-V role is named HV02
  • 1 virtual machine is running in HV02 is named MS01.test.tls1.lab

Export and import a running virtual machine in HV02
1. On HV02, log in as local Administrator.
2. Launch "Hyper-V Manager".

Now, the virtual machine, MS01.test.tls1.lab, is running. Next to "Actions" menu, there is a option to "Export" this virtual machine.

3. In the "MS01.test.tls1.lab", I launched a PowerShell console and performed a cmdlet.

4. Back to "Hyper-V Manager", right-click "MS01.test.tls1.lab", select "Export".

5. On "Export Virtual Machine" window, next to "Location", type "G:\".

One of hard disk in HV02 is named G:.

6. Click "Export".

Now, MS01.test.tls1.lab is being exported to G:\.

7. After exported the virtual machine, next to "Actions" menu, click "Import Virtual Machine".

8. On "Before You Begin" window, click "Next".
9. On "Locate Folder" window, click "Browse" and then go to "G:" to select "MS01.test.tls1.lab" folder.

10. Click "Next".
11. On "Select Virtual Machine" window, click "Next".

12. On "Choose Import Type" window, select "Copy the virtual machine (create a new unique ID)".

13. Click "Next".
14. On "Choose Destination" window, check "Store the virtual machine in a different location" and then type "H:\" under "Virtual machine configuration folder", "Checkpoint store" and "Smart Paging folder".

15. Click "Next".
16. On "Choose Storage Folders" window, next to "Location", type "H:\".

17. Click "Next".
18. On "Summary" window, click "Finish".

The state of imported virtual machine, MS01.test.tls1.lab, is "Saved".

19. Right-click the imported virtual machine, MS01.test.tls1.lab, select "Start".

20.  Double-click to connect the virtual machine.

As a result, the current state of MS01.test.tls1.lab has been cloned successfully.

Remark: We can also use "Export-VM -Name <VMName> -Path <Location>" to export the live VM.

Finally, I deleted the imported MS01.test.tls1.lab in Hyper-V Manager.

Export a checkpoint from MS01.test.tls1.lab and then import to a virtual machine in HV02
1. Go to "MS01.test.tls1.lab", create a file named "Error01" on the desktop.

2. Click "Checkpoint" icon to create a checkpoint.

3. On "Checkpoint Name" window, type "Error01".

4. Click "Yes".
5. Launch "PowerShell" as administrator.
6. Perform "Get-VMSnapshot -VMName <VMName>".

7. Perform "Export-VMSnapshot -Name <Snapshot name> -VMName <VMname> -Path <Location>" to export a checkpoint to be a virtual machine.

Remark: We can also export a checkpoint to be a virtual machine by Hyper-V Manager.

8. Perform "Import-VM -Path <The XML of the exported virtual machine> -Copy -GenerateNewId -SnapshotFilePath <Location> -VhdDestinationPath <Location> -VirtualMachinePath <Location> -SmartPagingFilePath <Location>" to import the VM to specific location with virtual hard disks, checkpoint, smart paging and virtual machine xml.

This step is same as "Import Virtual Machine" in "Hyper-V Manager".

9. The imported virtual machine is named "Error01" and the state is "Saved". Perform "Start-VM -VMName <VMName>" to start the imported VM.

10. Back to "Hyper-V Manager", double-click "Error01".

As a result, we can imported a checkpoint to be a virtual machine successfully.


This posting is provided “AS IS” with no warranties, and confers no rights!

No comments:

Post a Comment