Moving a VM from one Microsoft Hyper-V host to another is not earth shattering news, but have you done it lately?...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
Microsoft Server 2012 and 2012 R2 have made this migration fairly easy using the graphical Hyper-V Manager. If you're like me and want to accelerate the migration -- even automate the process -- then PowerShell can help. You can further accelerate the migration using SMB 3.0 file shares to truly go to the next level of Live Migration bliss.
There are many reasons to move a virtual machine from one host to another, everything from load balancing to decommissioning an older host. One challenge in the past was the downtime incurred during the lengthy move, but not anymore. The entire process of moving a VM and its storage from one host to another can be performed without a hitch with live migrations.
There are generally three options for performing a Microsoft Live Migration:
- Shared nothing live migration -- In this migration, you move the VM and its storage from one server to another.
- Live Storage Migration -- The VM definition stays on the current host, but you move the storage (virtual hard disk) to another location.
- Live Migration -- This lets you move a VM from one cluster node to another without downtime.
In this article, I'll focus on shared nothing live migration, which is the most time consuming of the three options. While you can perform these tasks with System Center Virtual Machine Manager, I'm going to go through the migration using only the Hyper-V cmdlets on Server 2012.
Try it for yourself
I love testing new ideas and techniques in a lab environment, and so should you before trying this in production. My lab environment consists of a domain control and two Hyper-V hosts (named S1 and S2). I have a virtual machine (named Server1) already running on S1. The goal is to migrate the VM without losing client activity.
Shared nothing live migration simply means that you will move a VM and its storage from one Hyper-V host to another without downtime. This is a complicated process under the hood, but Microsoft has streamlined the approach and made it fairly simple.
I perform all my management from a client computer using PowerShell remoting or RSAT. In your lab environment, you may not have a client to perform these tasks, so go ahead and perform them from the Hyper-V host running the VM.
Checking the VM status
Perform a quick status check of the VM to make sure everything is functioning. Check the state and current storage location on the Hyper-V host that contains the running:
Get-VM -Name server1 | Format-Table -Property Name, Path, State
PS C:\> Get-VMHardDiskDrive -VMName Server1 | Format-Table `
-Property VMName, Path
Enabling and performing a Live Migration
I often wish I had an "easy" button, and in this case I do. Setting up the migration for basic settings is simple. You need to enable the migration capability and choose a migration network. In production, it would be best to have multiple network interface cards and push the migrations across the isolated network without the public traffic. For lab testing, it's fine to use the existing network, since there are no end users that could be affected.
To enable VM migration, type the following at both Hyper-V servers or use PowerShell remoting from your client.
PS C:\> Enable-VMMigration
Add a VM migration network on both Hyper-V hosts:
PS C:\> Add-VMMigrationNetwork 192.168.3.0/24
Moving the VM and its storage to another Hyper-V host is now just a single command away. I'm going to move the VM to the host named S2 and place the storage in a location of "C:\HyperV." For testing during the migration I like to start a ping to the VM just to see that there is no communication loss. Here is the "easy" button.
PS C:\> Move-VM –Name Server1 -DestinationHost s2 `
Now for some serious power
If you really want to accelerate your migrations, regardless if your VMs are in a cluster or stand alone, use the new SMB 3.0 file shares. This includes many features that you will find discussed in other articles on TechTarget, but the bottom line is that it increases performance.
Start by setting up the SMB 3.0 share and permissions. This will be the location you want the VM's storage moved. You will need to create the share with permissions for the administrator and the two hosts, plus assign those permissions to NTFS. I created this on both Hyper-V hosts so I could move the VM back and forth.
PS C:\> New-SmbShare -Name Share1 -Path C:\hyperv `
-FullAccess Company\administrator, Company\S1, Company\S2
PS C:> Set-SmbPathAcl -ShareName Share1
Performing the move using the SMB share is very similar to before:
PS C:\> Move-VM –Name Server1 -DestinationHost s2 `
It is possible to run into some permission issues, especially if you're trying to perform this from your client. To resolve these, enable constrained delegation between the hosts and your client. You can find more information from this TechNet video.
Moving VMs using Live Migration is easy to setup and easy to automate if you know the PowerShell cmdlets. Consider testing out the new SMB 3.0 shares for an extra boost!