Tag Archives: madness

Hyper-V crazy replication

This is not supported by Microsoft, of course: it’s crazy! But it may be funny, also.

This post is about running  Hyper-V replica by using only one host. I ever liked doing interesting things with minimal resources. But pay attention: if you never implemented Hyper-V replica, you may need additional guidance. Here I’m not giving you a step-by-step guide, but you will find some useful links with details.

So I’ll show you how to test Hyper-V replica with a single host, that is a single physical computer, and possibly with a single VM (however, you can replicate more VMs at the same cost). There are some limitations, of course. Since the second Hyper-V host is a virtual machine, it cannot run them. It can however send and receive replicas, and this lets you also try both failover and test failover.

First of all, you must have got a 64 bit physical computer supporting virtualization and install Windows Server 2012 R2 on it (this may work also with Windows Server 2012). Let’s call this server “HVHOST”.

Replication is simpler if we have a domain, however if you prefer to manage self signed certificates, you may choose not to install Active Directory.

ADDS role may be installed on the physical Hyper-V host (this is not recommended, but you can do it). To add still a bit of insanity, in my lab I installed it on the VM instead, and then joined the physical host to the new domain. To be honest, I made also that host the node of a cluster, but please don’t follow me on this path, it is really too crazy.

So you’ll have to install ADDS and create a domain. I’m not going to explain this. You’ll have also to install the Hyper-V role. That is simple.

Once you have the Hyper-V role in place, create a VM, based on the same operating system as the host. This will be your second host, let’s call it “VMHOST”. Remember to join it to the domain (you may use an “internal” virtual switch to connect VMHOST to HVHOST without placing it on the external network).

Now the first tricky step. You cannot install Hyper-V on the VM in the usual way. You must do it by using PowerShell. So, sign in on VMHOST, open an elevated PoweShell Session and type these commands (more on this):

Enable-WindowsOptionalFeature –Online -FeatureName Microsoft-Hyper-V –All -NoRestart
Install-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature

Then restart your VM.

As the first replication test, let’s try to replicate from VMHOST to HVHOST. We need to create VMs in VMHOST, right? Better, we’ll create them on HVHOST, and then import them on VMHOST.

If you follow my advice, you’ll create and mount on HVHOST a new VHD, by using Disk Management. Then in Hyper-V Manager create one or more VMs placing them (VM configuration and disks) on the mounted VHD. Install on them whatever operating system you want.

When they are ready, turn off them and unmount the VHD containing them. Now attach the VHD to the SCSI controller of VMHOST and sign in to VMHOST. If necessary use Disk Management (on the VM) to bring online the attached disk, and then use the Hyper-V manager to import the VMs that are found there.

Note: on HVHOST, the VMs you created should now be in a “critical” state. You can remove them.

We are ready for replication. The VMs you imported in VMHOST cannot start, but they can be replicated to HVHOST in the usual way, and you can also try every kind of failover, since the replicas can start.

The replica can be done also in the opposite direction. We just have a VM on our host: that is VMHOST. We can replicate VMHOST to itself. This is really crazy!

To avoid a crash of your lab environment, however, there is a small trick to implement.

On VMHOST, create a new VHD and attach it to VMGUEST (you may use the wizard in Hyper-V manager). Sign on to VMGUEST, open disk management, bring online and format that new disk. Then configure replication to use the new disk as the “default location to store replica files” in Hyper-V Settings/Replication Configuration.

You are almost ready. When you enable VMHOST replication, pay attention at the wizard page that lets you choose which disks to replicate. Ensure that only the main disk (the one containing the operating system) is selected.

Hyper-V replica: select disk

And now, have fun!