gpt4 book ai didi

powershell - Azure:从通用镜像部署 VM 时出错(镜像不可部署)

转载 作者:行者123 更新时间:2023-12-03 05:54:51 29 4
gpt4 key购买 nike

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

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

最佳答案

OS provisioning for VM 'MyVM' failed. Error details: This installation of Windows is undeployable. Make sure the image has been properly prepared (generalized).

根据错误消息,您似乎没有正确地概括了VM。我们应该RDP到Azure VM,并运行sysprep,在系统准备工具对话框中,选择进入系统开箱即用体验(OOBE),并确保选中通用复选框。在“关机选项”中,选择关机enter image description here

有关通用化 Windows 虚拟机的更多信息,请参阅此 link .

I'm also unable to start the VM again because it's told me it's generalised

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

关于powershell - Azure:从通用镜像部署 VM 时出错(镜像不可部署),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42950360/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com