Here is what I will cover today:
- Create an Ubuntu Linux VM with managed disk
- Generalize the VM and make it ready for image capture
- Capture the VM image
- Remove the VM
- Create a Virtual Machine Scale Set (VMSS) with OS managed disk from the captured image
Let’s get things started:
Create a VM with managed disk
This is probably the easiest thing you can do. Simply use Azure Portal/CLI/PowerShell to create a VM with Ubuntu 16.04-LTS which uses a managed disk. I don’t go over the steps because I assume you already know how. If not, simply google it.
Generalize the VM and make it ready for image capture
Log into your Linux VM using SSH and run the following command to generalize it and make it ready for image capturing:
sudo waagent -deprovision+user
Capturing the VM image
You have different ways to capture the VM image but I prefer to use the Azure Portal. You need to first stop and deprovision the VM and then capture the image:
Now that it is stopped, you need to capture the image:
Remove the VM
Now that the image is ready, you can go ahead and remove the VM and all related resources. In the end you will have only the image in your resource group:
Create a VMSS with OS managed disk from the captured image
Now you can use the following PowerShell script to deploy a Virtual Machine Scale Set (with OS managed disk from the captured image) with an internal load balancer in front of it. The script also creates a virtual network and subnet:
https://gist.github.com/esarabadani/b93a8e6637f8b7bf6c374b7b009b98a4