locked
How to clone existing Azure Virtual Machine without destroy it ? RRS feed

  • Question

  • Hi all

    How to clone existing Azure Virtual Machine without destroy it ? As I know that clone is possible using creating image, but it seems that will destroy existing VM :(

    Is there any safe way to create image without destroy or make broken existing VM ?

    Monday, November 24, 2014 2:35 PM

Answers

  • Hi,

    Cloning a machine can be done in one of two ways.  The default mechanism of which has great documentation is to use the 'capture' mechanism in the portal to make a new image of the virtual machine.  This process involves you running sysprep on the machine and shutting it down.  The sysprep mechanism is a Windows operating system mechanism that will generify the configuration and configure the virtual machine to boot up in provisioning mode.  An image that is captured can then be used just like any other Azure image.  You can prepare an image in this manner and start up as many virtual machines as you wish.  Once you run sysprep and shut down your virtual machine, you then click the Capture button in the portal.  This will add the drive to your list of Azure images and it will delete the virtual machine.  Pay attention here - running sysprep on your Azure virtual machine will start you down a path where that virtual machine will no longer boot, and when you complete the operation by running Capture, the virtual machine will be deleted from your Azure subscription.  If this is not your desired outcome, don't start down this path.

    The second mechanism to copy a virtual machine is to make a copy of the underlying VHD stored in blob storage, then register this as a disk.  This process involves you simply shutting down your virtual machine, copying the disk image, then starting it back up again.  You can then register the copy of the VHD file as another disk and make a new virtual machine using that disk image.  Please note that this mechanism is not using sysprep, and that has implications.  Keep in mind that Azure is just a virtual server host and that everything about the operating system still applies.  For example, you do not want to clone a domain controller and put it in the same network otherwise you are likely to corrupt your domain database.  Conversely you cannot run sysprep on a domain controller and have the machine boot successfully.  Pay close attention to operating systems operations before you choose how you are going to copy/clone your new virtual machine.

    You can also refer  : http://community.adxstudio.com/blogs/shan/2012-06-28-cloning-windows-azure-virtual-machines/

    http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-capture-image-windows-server/

    Regards,

    Bharath

    Monday, November 24, 2014 7:44 PM

All replies

  • Hi,

    Cloning a machine can be done in one of two ways.  The default mechanism of which has great documentation is to use the 'capture' mechanism in the portal to make a new image of the virtual machine.  This process involves you running sysprep on the machine and shutting it down.  The sysprep mechanism is a Windows operating system mechanism that will generify the configuration and configure the virtual machine to boot up in provisioning mode.  An image that is captured can then be used just like any other Azure image.  You can prepare an image in this manner and start up as many virtual machines as you wish.  Once you run sysprep and shut down your virtual machine, you then click the Capture button in the portal.  This will add the drive to your list of Azure images and it will delete the virtual machine.  Pay attention here - running sysprep on your Azure virtual machine will start you down a path where that virtual machine will no longer boot, and when you complete the operation by running Capture, the virtual machine will be deleted from your Azure subscription.  If this is not your desired outcome, don't start down this path.

    The second mechanism to copy a virtual machine is to make a copy of the underlying VHD stored in blob storage, then register this as a disk.  This process involves you simply shutting down your virtual machine, copying the disk image, then starting it back up again.  You can then register the copy of the VHD file as another disk and make a new virtual machine using that disk image.  Please note that this mechanism is not using sysprep, and that has implications.  Keep in mind that Azure is just a virtual server host and that everything about the operating system still applies.  For example, you do not want to clone a domain controller and put it in the same network otherwise you are likely to corrupt your domain database.  Conversely you cannot run sysprep on a domain controller and have the machine boot successfully.  Pay close attention to operating systems operations before you choose how you are going to copy/clone your new virtual machine.

    You can also refer  : http://community.adxstudio.com/blogs/shan/2012-06-28-cloning-windows-azure-virtual-machines/

    http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-capture-image-windows-server/

    Regards,

    Bharath

    Monday, November 24, 2014 7:44 PM
  • We can clone a VM by creating Snapshot of the managed disk and then creating a new VM with it using Powershell. There is no way to do it from Azure portal so we have to either use cli or powershell.

    The detailed steps to do it are explained in the below post-

    https://www.techmanyu.com/how-to-quickly-clone-a-vm-in-azure/

    Sunday, April 8, 2018 9:12 PM