Starting a VM that was used to create an image

Starting a VM that was used to create an image

Q. I created an image from a VM using managed disks but now the source VM won't start, why?

A. When you create an image from a VM the source is normally generalized (SYSPREP is executed) and even if you didn't run SYSPREP the VM is still marked as generalized which means it will not sure. You cannot unset generalized. Instead you need to delete the source VM and recreate using the existing disk. Below is some PowerShell that recreates a VM using existing managed disk and places in availability set.

$rgName = "RGSavillEastRG"
$location = "East US"
$vmName = "SavTechESTNP2"
$computerName = "SavTechESTNP2"
$vnetName = "EastERVnet"
$vnetsub = "InfraStaticInfra"
$vmsize = 'Standard_A2'
$assetname = 'ASSAVNPS'
$osDiskName = "SavTechESTNP2_SavTechESTNP2"

$disk = get-azurermdisk -ResourceGroupName $rgName -DiskName $osDiskName
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName
$subnetId = (Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $vnetsub).Id

$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $vmName) -ResourceGroupName $rgname `
    -Location $location -SubnetId $subnetId -PrivateIpAddress -DnsServer, 

$avSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rgName -Name $assetname

$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmsize -AvailabilitySetId $avSet.Id
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -ManagedDiskId $disk.Id -CreateOption Attach -Windows
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm


Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.