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 Service Management subscription:
Login to your Azure account and display the available subscriptions:
Add-AzureAccount Get-AzureSubscriptionazure config mode asm azure login azure account listSelect the Azure Subscription we will be working with:
Select-AzureSubscription -SubscriptionName <Subscription Name>azure account set <Name>
Image Creation
Windows
- Launch a VM using the base image you wish to customize.
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 /shutdownWait for the VM to be in a
Stoppedstate...From your Workstation: Capture the image:
Note:The VM will be deleted as part of the capture process.
Save-AzureVMImage -Name <VM Name> -ServiceName <Cloud Service Name> -ImageName <New Image Name> -ImageLabel <New Image Label/Description>azure vm capture <VM Name> <New Image Name> --label <New Image Label/Description> --deleteThe image will be captured as a virtual hard drive (VHD) and saved in the same Storage Account as the source VM at the following path:
<Storage Account>/vhds/. At the same time it will also be registered as an Image within Azure.Wait for RightScale Cloud Management to discover the newly registered 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.
SSH to the operational VM and make any necessary modifications:
Install RightLink 10. Something like:
curl -s https://rightlink.rightscale.com/rll/10/rightlink.install.sh | sudo bash -s -lInstall 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 -forceClose the SSH session by typing:
exitFrom your Workstation: Shut down the VM that was already deprovisioned in the previous steps with:
Stop-AzureVM -Name <VM Name> -ServiceName <Cloud Service Name> -Forceazure vm shutdown <VM Name>From your Workstation: Capture the image:
Note:The VM will be deleted as part of the capture process.
Save-AzureVMImage -Name <VM Name> -ServiceName <Cloud Service Name> -ImageName <New Image Name> -ImageLabel <New Image Label/Description>azure vm capture <VM Name> <New Image Name> --label <New Image Label/Description> --deleteThe image will be captured as a vhd and saved in the same Storage Account as the source VM at the following path:
<Storage Account>/vhds/. At the same time it will also be registered as an Image within Azure.Wait for RightScale Cloud Management to discover the newly registered 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