22

There doesn't seem to be a straight answer online about this. I have an existing Virtual Machine on Azure and I want to clone it to another region in case my existing server goes down. It needs to be the exact replica but all I can find are moving virtual machines, not cloning. I assume you can't do a certain type of clone maybe because of the computer names cant be the same for the VM.

Is there a good article on what to do, or should I start from scratch and build the virtual machine up again trying to replicate what I already have?

1

3 Answers 3

3

If you are using classic deployment, basically all you have to do is:

  1. Sysprep your server (Windows) or deprovision the agent (Linux)
  2. Hit Capture using the portal to create an image of your VM
  3. Use Azcopy to copy the VHD file generated to the secondary region
  4. Create new image (secondary region) using the VHD file you just copied
  5. Deploy a new virtual machine using this image (secondary region)

If you are using ARM, read this.

References:

Capture an image of an Azure Windows virtual machine

How to capture a classic Linux virtual machine as an image

Transfer data with the AzCopy Command-Line Utility

4
  • 5
    Doesn't this leave your original machine "generalized"? What if you want to continue using both the original and the clone?
    – Andy Jones
    Apr 11, 2017 at 12:05
  • You can't. After generalize you have to redeploy. Apr 11, 2017 at 12:14
  • 3
    That "After generalize you have to redeploy" part is very important and was unclear to me. I tried to generalize a VM and didn't realize I was going to be completely locked out of it. And because I didn't properly shutdown the VM (instead I selected reboot) then I wasn't even able to clone it. Fortunately it was jus a test VM.
    – Simon
    Apr 14, 2017 at 19:30
  • 2
    @Simon, yes, this is the biggest gripe I have with Microsoft's documentation. It should say "WARNING! DO NOTHING UNTIL YOU UNDERSTAND ALL OF THIS!" The generalization procedure (sysprep, capture, etc.) is just FULL of places where you can cross the River Styx into the underworld, and if you weren't fully prepared beforehand, there is no returning from it.
    – Forbin
    Jun 23, 2020 at 20:44
6

Here is how I did it, did not have to use PowerShell and my original VM still worked after.

Result if you use sysprep from documentation:

Once you have run sysprep on an VM it is considered generalized and it cannot be restarted. The process of generalizing a VM is not reversible. If you need to keep the original VM functioning, you should take a copy of the VM and generalize the copy.

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource?toc=%2Fazure%2Fvirtual-machines%2Fwindows%2Fclassic%2Ftoc.json

Steps:

Start by copying a disk. Create a snapshot, then create a disk from the snapshot. This allows you to keep the original VHD as a fall back.

  1. In the left menu, click on All resources.
  2. In the All types drop-down, de-select Select all and then scroll down and select Disks to find the available disks.
  3. Click on the disk that you would like to use. The Overview page for the disk opens.
  4. In the Overview page, on the menu at the top, click + Create snapshot.
  5. Type a name for the snapshot.
  6. Choose a Resource group for the snapshot. You can either use an existing resource group or create a new one.
  7. Choose whether to use standard (HDD) or Premium (SDD) storage.
  8. When you are done, click Create to create the snapshot.
  9. Once the snapshot has been created, click on + Create a resource in the left menu.
  10. In the search bar, type managed disk and select Managed Disks from the list.
  11. On the Managed Disks page, click Create.
  12. Type a name for the disk.
  13. Choose a Resource group for the disk. You can either use an existing resource group or create a new one. This will also be the resource group where you create the VM from the disk.
  14. Choose whether to use standard (HDD) or Premium (SDD) storage.
  15. In Source type, make sure Snapshot is selected.
  16. In the Source snapshot drop-down, select the snapshot you want to use.
  17. Make any other adjustments as needed and then click Create to create the disk.

Create a VM from a disk Once you have the managed disk VHD that you want to use, you can create the VM in the portal.

  1. In the left menu, click on All resources.
  2. In the All types drop-down, de-select Select all and then scroll down and select Disks to find the available disks.
  3. Click on the disk that you would like to use. The Overview page for the disk opens. In the Overview page, make sure that DISK STATE is listed as Unattached. If it isn't, you might need to either detach the disk from the VM or delete the VM to free up the disk.
  4. In the menu at the top of the pane, click + Create VM.
  5. On the Basics page for the new VM, type in a name and select either an existing resource group or create a new one.
  6. On the Size page, select a VM size page and then click Select.
  7. On the Settings page, you can either let the portal create all new resources or you can select an existing Virtual network and Network security group. The portal always create a new NIC and public IP address for the new VM.
  8. Make any changes to the monitoring options and add any extensions as needed.
  9. When you are done, click OK.
  10. If the VM configuration passes validation, click OK to start the deployment.

I choose to create a new virtual network since the servers themselves did not need any local connections.

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-specialized-portal#copy-a-disk

1
  • Thanks for this. NB: I had issues when I created the VHD in one subscription, then copied it to another (via AZ Storage Explorer) and tried to create a VM from the copy. By creating the VHD in the target subscription, all works as expected.
    – JohnLBevan
    Oct 21, 2021 at 16:22
1

I would use Site Recovery in Azure.

This should help guide you. https://docs.microsoft.com/en-us/azure/site-recovery/site-recovery-migrate-azure-to-azure

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .