Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, September 1, 2016 11:35 AM
Hi all, I have created an image from an existing VM. Now I have a generalized VM that looks useless to me. For example, I can not start the VM anymore. It just displays the following error message.
Failed to start virtual machine 'vmname'. Error: Operation 'start' is not allowed on VM 'vmname' since the VM is generalized.
My question is, what can I do with this VM? Is it best to simply delete it and save some resources?
Thanks in advance.
All replies (6)
Friday, September 2, 2016 8:10 AM ✅Answered | 1 vote
once a vm is generalised you can get it back, its something of a process and should be much simpler than this but anyhow this is the process that works for me - maybe there is an easier way but i haven't found it.
1) first step is to sysprep.exe the os / generalise and shut it down. (guess this part you have done already) this will delete all users from the vm
2) next you need to create an osDisk from the generalised VM. these powershell scripts will need to be edited to put in the correct resource group names and vm names. For this example i'm using a vm called GOLDIMAGE in resource group of GOLDIMAGERG
# SAVE VM GOLD IMAGE
# set azure rm subscription
Select-AzureRmSubscription -SubscriptionId "4xxxxxe-13bf-4xxxx-9xx-7xxxx656dbc9d"
# stop the image
Stop-AzureRmVm -ResourceGroupName GOLDIMAGERG -Name "GOLDIMAGE"
# generalise the image
Set-AzureRmVm -ResourceGroupName GOLDIMAGERG -Name "GOLDIMAGE" -Generalized
# create osdisk image from GOLD vhd
Save-AzureRmVMImage -ResourceGroupName GOLDIMAGERG -Name "GOLDIMAGE" -DestinationContainerName "storage1" -VHDNamePrefix "GOLDIMAGE"
3) Now you will have an osDisk image in your storage, you need to get the image name from storage and put it in the script below. it will be in blobs/system/Microsoft.Compute/Images/[storagename] and will look like GOLDIMAGE-osDisk...<guid>..vhd
4) now you can use the osDisk image to boot your generalised vm into a new vm
$subscriptionId = '40bxxxxe-13xxf-4xxx-91xx5-7xx5xx65d' # Your SubscriptionId
$storageAccountName = 'storage1' # Storage account name where your custom image is and where your VM vhd will go
$sourceImageUri = 'https://storage1.blob.core.windows.net/system/Microsoft.Compute/Images/storage1/GOLDIMAGE-osDisk.5aeb550b-4c70-4fb4-89a2-ebc07a933ed6.vhd'
# end of custom variables
# Authenticate against Azure and cache subscription data
#Login-AzureRmAccount
# Switch subscription
Select-AzureRmSubscription -SubscriptionId $subscriptionId
# Get the storage account
$storageAccount = Get-AzureRmStorageAccount | ? StorageAccountName -EQ $storageAccountName
if(-not $storageAccount) {
throw "Unable to find storage account '$storageAccountName'. Cannot continue."
}
# Enable verbose output and stop on error
$VerbosePreference = 'Continue'
$ErrorActionPreference = 'Stop'
# some reserved script variables
$resourceGroupName = "GOLDIMAGERG";
$location = $storageAccount.Location
$adminUsername = 'SomeAdmin'
$adminPassword = 'YOUR PASSWORD'
$vmSuffix = Get-Random -Minimum 10000 -Maximum 99999
$vmName = 'GOLDIMAGE'
$vmSize = 'Standard_D1'
$nicName = 'goldimagenic'
$ipName = 'goldimageip'
$domName = 'vm-from-customimage-powershell-{0}' -f $vmSuffix
$vnetName = 'scalevnet'
# Create the VNET or use existing VNET
#Write-Verbose 'Creating Virtual Network'
#$vnetDef = New-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Location $location -Name $vnetName -AddressPrefix '10.0.0.0/16'
Write-Verbose 'Adding subnet to Virtual Network'
#$vnet = $vnetDef | Add-AzureRmVirtualNetworkSubnetConfig -Name 'Subnet-1' -AddressPrefix '10.0.0.0/24' | Set-AzureRmVirtualNetwork
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName "NETWORKRG"
# Create the NIC
Write-Verbose 'Creating Public IP'
$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName -Location $location -Name $ipName -DomainNameLabel $domName -AllocationMethod Dynamic
Write-Verbose 'Creating NIC'
$nic = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Location $location -Name $nicName -PublicIpAddressId $pip.Id -SubnetId $vnet.Subnets[0].Id
# Specify the VM name and size
Write-Verbose 'Creating VM Config'
$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
# Specify local administrator account, and then add the NIC
$cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force) # you could use Get-Credential instead to get prompted
# NOTE: if you are deploying a Linux machine, replace the -Windows switch with a -Linux switch.
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
# Specify the OS disk
$diskName = 'osdisk'
$osDiskUri = '{0}vhds/{1}{2}.vhd' -f $storageAccount.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $diskName
# NOTE: if you are deploying a Linux machine, replace the -Windows switch with a -Linux switch.
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $sourceImageUri -Windows
Write-Verbose 'Creating VM...'
$result = New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location -VM $vm
Thursday, September 1, 2016 4:50 PM | 1 vote
Hi,
Thank you for posting here! We are happy to assist you.
- Maybe you can resize the instance of the virtual machine, making it larger. If it does not work, you can delete and recreate the virtual machine. When you delete the virtual machine, please detach the data disk from the virtual machine.
You could resize the VM as per your requirement and to the available VM size, kindly refer the link below for more details on this:
https://msdn.microsoft.com/en-us/library/dn168976(v=nav.70).aspx
Important: Things to know when the VM is shutdown (deallocated):
- By stopping (deallocating) a VM, you not only stop the VM’s OS, you also free up the hardware and network resources Azure previously provisioned for it (a process called deallocation).
- Unless you configured static addresses, you also release the internal DIP address, as well as the public VIP address (if no other VMs are using the public VIP, as the VIP is assigned to the cloud service and not directly to the virtual machine). When you restart the VM, it will then pick up a new public VIP (if it is not joining a cloud service that already has one) as well as a new DIP.
- The VM’s OS and data disks remain intact in Azure storage and can be used to restart the VM later. However, the temporary (scratch) disk associated with the VM is released and any data on that disk could be lost.
Regards,
Sumanth BM
Friday, September 2, 2016 7:01 AM
You wrote:
"When you delete the virtual machine, please detach the data disk from the virtual machine."
How can I do that? I would prefer to do this using PowerShell. Is there any sample code available?
Wednesday, June 28, 2017 2:56 PM
I am in the same situation and I can not use the captured image. What should I do ?
Tuesday, November 28, 2017 1:27 PM
Rifat, have you tried the process suggested by Paul?
Sunday, March 18, 2018 10:41 PM
Same thing just happend to me, Azure said to read the document about generizing an OS first, which I thought no way I just want to capture this not kill that VM and to my surprise capturing the image automatically generized my current VM!
Thought I was following the instructions, turns out I didn't read it properly. I think generalizing an image should be something you choose to do, not have it done for you.
Failed to start virtual machine 'MBCM-Desktop'. Error: Operation 'Start VM' is not allowed on VM 'MBCM-Desktop' since the VM is generalized.