Azure:从广义映像部署VM时出错(Image Undeployable)

时间:2017-03-22 11:28:39

标签: powershell azure virtual-machine vhd

我一直在尝试使用Powershell(遵循MS文档)从通用映像部署新VM但我不断收到此错误。

New-AzureRmVM : Long running operation failed with status 'Failed'.
ErrorCode: OSProvisioningClientError
ErrorMessage: OS provisioning for VM 'MyVM' failed. Error details: This installation of Windows is undeployable. Make sure the image has been properly prepared (generalized).
Instructions for Windows: https://azure.microsoft.com/documentation/articles/virtual-machines-windows-upload-image/ 
StartTime: 22/03/2017 10:06:24
EndTime: 22/03/2017 10:10:37
OperationID: 549f97d1-ca39-4bc5-bd6c-65e37a8d398f
Status: Failed
At C:\Visual Studio Projects\Deployment\VmSetup.ps1:97 char:1
+ New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmVM], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand

麻烦的是我确实运行了一个sysprep并对图像进行了概括。

Code          : OSState/generalized
Level         : Info
DisplayStatus : VM generalized
Message       : 
Time          : 

我也无法再次启动虚拟机,因为它告诉我它已被推广。

Failed to start virtual machine 'OtherVM'. Error: Operation 'start' is not allowed on VM 'OtherVM' since the VM is generalized.

图像保存脚本:

#Script to save image
$vmName = "OtherVM"
$rgName = "MyResourceGroup"
#Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName
Set-AzureRmVM -ResourceGroupName $rgName -Name $vmName -Generalized
$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName -Status
$vm.Statuses

#Save VM Image
Save-AzureRmVMImage -ResourceGroupName $rgName -Name $vmName `
-DestinationContainerName "generalisedimages" -VHDNamePrefix "gen" `
#-Path "C:\VMTemplate\VmTemplate.json"
Write-Output "Imaged saved."

部署脚本。

#
# VmDeploy.ps1
#
#Sign into Azure account
#Login-AzureRmAccount

# Name of the virtual machine. This example sets the VM name as "myVM".
$vmName = "MyVM"

#Set resource group and subnet name
$rgName = "MyResourceGroup"
$subnetName = "default"
$singleSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24

#Set location and vNet name
$location = "UK South"
$vnetName = "{0}-vnet" -f $rgName
$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $singleSubnet

#Create public IP
$ipName = "{0}-ip" -f $vmName
$pip = New-AzureRmPublicIpAddress -Name $ipName -ResourceGroupName $rgName -Location $location -AllocationMethod Dynamic

#Create NIC
$nicName = "{0}-nic" -f $vmName
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id

#Create network security group and allow RDP
$nsgName = "{0}-nsg" -f $vmName
$rdpRule = New-AzureRmNetworkSecurityRuleConfig -Name Rdp -Description "Allow RDP" `
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 110 `
    -SourceAddressPrefix Internet -SourcePortRange * `
    -DestinationAddressPrefix * -DestinationPortRange 3389
$httpRule = New-AzureRmNetworkSecurityRuleConfig -Name Http -Description "Allow HTTP" `
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 120 `
    -SourceAddressPrefix Internet -SourcePortRange * `
    -DestinationAddressPrefix * -DestinationPortRange 80
$httpsRule = New-AzureRmNetworkSecurityRuleConfig -Name Https -Description "Allow HTTPS" `
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 130 `
    -SourceAddressPrefix Internet -SourcePortRange * `
    -DestinationAddressPrefix * -DestinationPortRange 443
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rgName -Location $location -Name $nsgName -SecurityRules $rdpRule, $httpRule, $httpsRule

#Get completed virtual network
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName $rgName -Name $vnetName

#Uri of VM image
$imageURI = "https://*******.blob.core.windows.net/system/Microsoft.Compute/Images/generalisedimages/genosDisk.86g419f6-0de6-4331-hi54-32hse8de6bd4.vhd"
# Enter a new user name and password to use as the local administrator account 
# for remotely accessing the VM.
$cred = Get-Credential
# Name of the storage account where the VHD is located. This example sets the 
# storage account name as "myStorageAccount"
$storageRgName = $rgName
$storageAccName = "mystorage"

# Size of the virtual machine. This example creates "Standard_D2_v2" sized VM. 
# See the VM sizes documentation for more information: 
# https://azure.microsoft.com/documentation/articles/virtual-machines-windows-sizes/
$vmSize = "Standard_A1"

# Computer name for the VM. This examples sets the computer name as "myComputer".
$computerName = "New VM"

# Name of the disk that holds the OS. This example sets the 
# OS disk name as "myOsDisk"
$osDiskName = "OsDisk"

# Assign a SKU name. This example sets the SKU name as "Standard_LRS"
# Valid values for -SkuName are: Standard_LRS - locally redundant storage, Standard_ZRS - zone redundant
# storage, Standard_GRS - geo redundant storage, Standard_RAGRS - read access geo redundant storage,
# Premium_LRS - premium locally redundant storage. 
$skuName = "Standard_LRS"

# Get the storage account where the uploaded image is stored
$storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $storageRgName -AccountName $storageAccName
Write-Output $storageAcc

# Set the VM name and size
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize

#Set the Windows operating system configuration and add the NIC
$vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName `
    -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

# Create the OS disk URI
$osDiskUri = '{0}vhds/{1}-{2}.vhd' `
    -f $storageAcc.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $osDiskName
Write-Output "OS Disk URI:" $osDiskUri

# Configure the OS disk to be created from the existing VHD image (-CreateOption fromImage).
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $imageURI -Windows
Write-Output $vm

# Create the new VM
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm

$vmList = Get-AzureRmVM -ResourceGroupName $rgName
$vmList.Name

1 个答案:

答案 0 :(得分:0)

  

VM'MyVM'的操作系统配置失败。错误详细信息:此安装   Windows无法部署。确保图像正确   准备(一般化)。

根据错误消息,您似乎正确地使用了广义VM。 我们应该RDP到Azure VM,并运行sysprep,在系统准备工具对话框中,选择输入系统即用型体验(OOBE),并确保选中了Generalize复选框。在关机选项中,选择关机enter image description here

有关概括Windows虚拟机的详细信息,请参阅此link

  

我也无法再次启动虚拟机,因为它告诉我它   广义

捕获Azure widnows VM的映像,此过程删除原始虚拟机。 在捕获Azure虚拟机的映像之前,建议备份目标虚拟机