Starting a VM that was used to create an image
Re-enable a VM that was used to create an image.
John Savill
July 11, 2017
1 Min Read
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 10.242.63.32 -DnsServer 10.242.63.11, 10.242.63.12 $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 -WindowsNew-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like