In this post, I will show you how you can use the snapshot feature of managed disks to create an exact copy (including identity and SID) of a virtual machine.
This technique should only be used for lab and troubleshooting purposes. The official creation/deployment methods of Azure should be used for production deployments from a generalized image.
This technique is based on the snapshot feature of managed disks. If you are using un-managed disks (VHD files in storage accounts) then check out what managed disks offer and how to convert un-managed disks into managed disks.
The method I am using does the following:
Managed disk snapshots are done on a per disk basis. To create a consistent image of the original virtual machine, you must shut it down first (via Azure, not the guest OS). Once the virtual machine is shut down (deallocated), you can create a snapshot of each disk, one at a time.
Identify each of the disks of the virtual machine. Then open each disk and click Create Snapshot.
When you are creating the snapshot, use a descriptive name for the disk and save it to a resource group that you’ll remember. For example, if a data disk was connected to LUN0, be sure to give it a name to remind you to attach it back to LUN0 in the new machine.
Make sure you do this process for the OS disk and every data disk of the virtual machine. You cannot and do not need to do this for the temp drive.
You can generate newly managed disks from the snapshots that were just created. Create an OS disk from the OS disk snapshot and create a data disk from each data disk snapshot. To do this, click Create A Resource in the Azure Portal and search for and select Managed Disks.
Name the managed disk. Once again, use a name that reminds you to attach the disk back to the same slot it was connected to in the original machine. Be sure to pick the correct resource group (it’s hard to move a managed disk), and pick the disk type (Premium SSD, Standard HDD, etc). When it comes to source type, select Snapshot and pick the appropriate disk.
In my example, I’m creating a new data disk from the data disk snapshot. Note that you can pick a larger size if you wish. You will need to extend the partition later in the guest OS. Also note that you cannot create a disk smaller than the original disk using this method.
You should end up with one new disk for each original disk in the virtual machine. In the below example, you can see the snapshots and the new disks alongside the originally deployed disks and virtual machine.
Now you have enough to build the new machine. Open the new OS disk and click + Create VM. This will open the regular Create Virtual Machine blade. Many of the options will be greyed out because they are pre-configured in the existing disk. Finish the wizard and wait for the virtual machine to be deployed.
You can add each of the data disks to the virtual machine. Be sure that each data disk is attached to the same LUN as it was in the original virtual machine. Also, make sure that you copy the Host Caching configuration from the original virtual machine.
There is a pretty strong chance that some service in the virtual machine has failed because the virtual machine previously booted up without the data disks. To be safe, reboot the virtual machine.
Log into the virtual machine and ensure that:
If everything is OK, you can delete the snapshots, assuming that you don’t want to create any more test/troubleshooting copies of the virtual machine.