Pre-Requisites
Install Azure PowerShell Module or Azure CLI
In order to create a custom image using this guide, you will need to have either the Azure PowerShell Module or Azure CLI tools available on your workstation.
Login to Azure Account
Once the proper Azure tools are installed, you need to set them up to work with your Azure Resource Manager subscription:
Login to your Azure account and display the available subscriptions:
Login-AzureRmAccount Get-AzureRmSubscription
azure config mode arm azure login azure account list
Select the Azure Subscription we will be working with:
Select-AzureRmSubscription -SubscriptionName <Subscription Name>
azure account set <Name>
Image Creation
Windows
- Launch a VM using the base image you wish to customize. At this stage you must decide if you wish to use Managed Disks or not.
Connect to the operational VM and make any necessary modifications:
-
$wc = New-Object System.Net.Webclient $wc.DownloadFile("https://rightlink.rightscale.com/rll/10/rightlink.install.ps1", ` "$pwd\rightlink.install.ps1") Powershell -ExecutionPolicy Unrestricted -File rightlink.install.ps1
Install updates
Install applications
Etc...
-
From the VM: Prepare the VM for image capture by running SYSPREP from an elevated command prompt:
C:\windows\system32\sysprep\sysprep.exe /oobe /generalize /shutdown
Wait for the VM to be in a
Stopped
state...From your Workstation: Deallocate the VMs resources:
Stop-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> -Force
azure vm deallocate --resource-group <Resource Group Name> --name <VM Name>
From your Workstation: Generalize the VM:
Set-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> -Generalized
azure vm generalize --resource-group <Resource Group Name> --name <VM Name>
From your Workstation: Capture the image:
Managed Image:$vm = Get-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> $image = New-AzureRmImageConfig -Location <Region> -SourceVirtualMachineId $vm.ID New-AzureRmImage -Image $image -ImageName <Name of Image> -ResourceGroupName <Resource Group Name>
az image create --resource-group <Resource Group Name> --name <Name of Image> --source <VM Name>
Unmanaged Image:
Save-AzureRmVMImage -VMName <VM Name> -ResourceGroupName <Resource Group Name> -DestinationContainerName "vhds" -VHDNamePrefix <choose unique prefix string>
azure vm capture --resource-group <Resource Group Name> --name <VM Name> --vhd-name-prefix <choose unique prefix string>
The unmanaged image will be captured as a virtual hard drive (VHD), with the prefix you defined and in the same Storage Account as the source VM, at the following path:
<Storage Account>/system/Microsoft.Compute/Images/vhds/
Note:RightScale Cloud Management will only discover vhds as
images
when stored within thesystem
container.The source VM is no longer usable once it has been sysprepped and marked as generalized. Run the following command once the image has been successfully captured to delete the source VM:
Remove-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> -Force
azure vm delete --resource-group <Resource Group Name> --name <VM Name> --quiet
Wait for RightScale Cloud Management to discover the newly captured image. This takes approximately 5-10 minutes.
Once RightScale Cloud Management has discovered the image, you can add it to an existing MultiCloud Image or create a new MultiCloud Image.
Note:If you have installed RightLink 10, the MultiCloud Image must be tagged with
rs_agent:type=right_link_lite
Linux
- Launch a VM using the base image you wish to customize. At this stage you must decide if you wish to use Managed Disks or not.
SSH to the operational VM and make any necessary modifications:
-
curl -s https://rightlink.rightscale.com/rll/10/rightlink.install.sh | sudo bash -s
Install updates
Install applications
Etc...
-
From the VM: Run the following commands to sanitize the VM and prepare it for capture:
sudo rm -rf /var/lib/cloud/ /tmp/* sudo rm -f /var/log/cloud-init* /etc/udev/rules.d/70-persistent-net.rules sudo find /root -name authorized_keys -type f -exec rm -f {} \; sudo find /home -name authorized_keys -type f -exec rm -f {} \; sudo find /var/log -type f -exec cp /dev/null {} \; history -c sync sudo waagent -deprovision+user -force
Close the SSH session by typing:
exit
From your Workstation: Stop and Deallocate the VMs resources:
Stop-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> -Force
azure vm deallocate --resource-group <Resource Group Name> --name <VM Name>
From your Workstation: Generalize the VM:
Set-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> -Generalized
azure vm generalize --resource-group <Resource Group Name> --name <VM Name>
From your Workstation: Capture the image:
Managed Image:$vm = Get-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> $image = New-AzureRmImageConfig -Location <Region> -SourceVirtualMachineId $vm.ID New-AzureRmImage -Image $image -ImageName <Name of Image> -ResourceGroupName <Resource Group Name>
az image create --resource-group <Resource Group Name> --name <Name of Image> --source <VM Name>
Unmanaged Image:
Save-AzureRmVMImage -VMName <VM Name> -ResourceGroupName <Resource Group Name> -DestinationContainerName "vhds" -VHDNamePrefix <choose unique prefix string>
azure vm capture --resource-group <Resource Group Name> --name <VM Name> --vhd-name-prefix <choose unique prefix string>
The unmanaged image will be captured as a VHD, with the prefix you defined and in the same Storage Account as the source VM, at the following path:
<Storage Account>/system/Microsoft.Compute/Images/vhds/
Note:RightScale Cloud Management will only discover vhds as
images
when stored in the above mentioned path.The source VM is no longer usable once it has been marked as generalized. Run the following command once the image has been successfully captured to delete the source VM:
Remove-AzureRmVM -Name <VM Name> -ResourceGroupName <Resource Group Name> -Force
azure vm delete --resource-group <Resource Group Name> --name <VM Name> --quiet
Wait for RightScale Cloud Management to discover the newly captured image. This takes approximately 5-10 minutes.
Once RightScale Cloud Management has discovered the image, you can add it to an existing MultiCloud Image or create a new MultiCloud Image.
Note:If you have installed RightLink 10, the MultiCloud Image must be tagged with
rs_agent:type=right_link_lite