Cloning Linux Guest in Hyper-V 2012 R2

Cloning a Linux guest comes with its own challenges as it doesn’t include an out-of-the-box tool like SysPrep to generalise OS unique settings like Windows.

This scenario is composed of:

  • Microsoft Windows Server 2012 R2
  • Hyper-V Manager
  • Red Hat Enterprise Linux Server Release 6.6

In Hyper-V Manager:

  1. Right click an existing VM you would like to clone from and click Export.
  2. Select a location to export current VM. I suggest a generic folder called export located in the same directory storing existing VM files.
  3. Right click Hyper-V node on the left hand pane and select Import Virtual Machine…
  4. Follow the Wizard selecting the newly exported folder to import from (the sub-folder created within export).
  5. In the Wizard, change Import Type to Copy the virtual machine (create a new unique ID).
  6. In the wizard, change store locations to a new location. Ideally into a folder corresponding to new server hostname, removing subfolder structures such as snapshots and machineconfig. (ie. C:\HyperV\NewHostname).
  7. Ensure storage folders is also pointing to the same folder as above step.
  8. Complete the Wizard.
  9. Modify newly imported VM Settings:
    1. Change VM name to correspond.
    2. Disable or Disconnect network interface card from Virtual Switch.
  10. Start VM (This is required to bring VM from Saved state to normal).
  11. Modify /etc/sysconfig/network updating the hostname.
  12. Modify /etc/sysconfig/network-scripts/ifcfg-eth0 updating the IP address
  13. Power VM off.
  14. Modify VM settings, connect network adapter and alocate static MAC address.
  15. Power VM on.
  16. Modify /etc/sysconfig/network-scripts/ifcfg-eth0 updating HWADDR to match new static MAC address.
  17. Delete /etc/udev/rules.d/70-persistent-net.rules file reboot. This will enable the auto-detection of the NIC at reboot.
  18. Reboot server.