从托管数据磁盘创建虚拟机

creating vm from managed data disk

我在托管的 Azure 数据磁盘中有 OS 数据。我想从这个数据磁盘创建一个 VM。我尝试使用 az vm create --resource-group myResourceGroup --location eastus --name myVM \ --os-type linux --attach-os-disk myManagedDisk

我面临的问题是新创建的虚拟机已启动 运行,但是当我尝试使用 IP 地址通过 ssh 连接到它时,我无法这样做。

另外,如何为这个新创建的 VM 提供用户名和密码?它说 --admin-username--admin-password 选项不适用于此类命令?

您似乎无法使用原始密码登录新虚拟机,请通过 Azure 门户重置密码,然后使用新密码登录。

It says the --admin-username and --admin-password options are unavailable for this type of command?

是的,Azure 不支持为现有 OS 磁盘重置用户名和密码。

如果您想重置用户名和密码,也许您应该从该虚拟机创建一个新映像。创建新镜像将通用此VM,并删除用户设置,然后您将无法登录原始VM,如果要创建新VM镜像,请先备份os磁盘。

更新:

请按照ose 步骤复制托管磁盘并创建新 VM: 1.Stop 原始 VM,然后通过 Azure 门户创建该 OS 磁盘的快照。
2.Use 创建新磁盘的快照。
3.Use 用于创建 Azure VM 的新 OS 磁盘。

#Provide the subscription Id of the subscription where managed disk exists
$sourceSubscriptionId='yourSourceSubscriptionId'

#Provide the name of your resource group where managed disk exists
$sourceResourceGroupName='mySourceResourceGroupName'

#Provide the name of the managed disk
$managedDiskName='myDiskName'

#Set the context to the subscription Id where Managed Disk exists
Select-AzureRmSubscription -SubscriptionId $sourceSubscriptionId

#Get the source managed disk
$managedDisk= Get-AzureRMDisk -ResourceGroupName $sourceResourceGroupName -DiskName $managedDiskName

#Provide the subscription Id of the subscription where managed disk will be copied to
#If managed disk is copied to the same subscription then you can skip this step
$targetSubscriptionId='yourTargetSubscriptionId'

#Name of the resource group where snapshot will be copied to
$targetResourceGroupName='myTargetResourceGroupName'

#Set the context to the subscription Id where managed disk will be copied to
#If snapshot is copied to the same subscription then you can skip this step
Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId

$diskConfig = New-AzureRmDiskConfig -SourceResourceId $managedDisk.Id -Location $managedDisk.Location -CreateOption Copy 

#Create a new managed disk in the target subscription and resource group
New-AzureRmDisk -Disk $diskConfig -DiskName $managedDiskName -ResourceGroupName $targetResourceGroupName