将 Azure 托管磁盘存储从标准类型转换为高级类型,或者从高级类型转换为标准类型Convert Azure managed disks storage from Standard to Premium or Premium to Standard

Azure 托管磁盘有三种磁盘类型:高级 SSD、标准 SSD 和标准 HDD。There are three disk types of Azure managed disks: premium SSD, standard SSD, and standard HDD. 可以根据性能需求在三种 GA 磁盘类型(高级 SSD、标准 SSD 和标准 HDD)之间切换。You can switch between the three GA disk types (premium SSD, standard SSD, and standard HDD) based on your performance needs.

非托管磁盘不支持此功能。This functionality is not supported for unmanaged disks. 但是,可以轻松将非托管磁盘转换为托管磁盘,然后即可切换磁盘类型。But you can easily convert an unmanaged disk to a managed disk to be able to switch between disk types.

本文介绍了如何使用 Azure CLI 将托管磁盘从一种磁盘类型转换为另一种类型。This article shows how to convert managed disks from one disk type to another by using the Azure CLI. 若要安装或升级 CLI 工具,请参阅安装 Azure CLITo install or upgrade the tool, see Install Azure CLI.

准备阶段Before you begin

  • 磁盘转换需要重启虚拟机 (VM),因此请在预先存在的维护时段内计划磁盘存储迁移。Disk conversion requires a restart of the virtual machine (VM), so schedule the migration of your disk storage during a pre-existing maintenance window.
  • 对于非托管磁盘,请先转换为托管磁盘,以便可以在存储选项之间切换。For unmanaged disks, first convert to managed disks so you can switch between storage options.

将 VM 的所有托管磁盘从一个帐户切换到另一个帐户Switch all managed disks of a VM between from one account to another

此示例展示了如何将 VM 的所有磁盘转换为高级存储。This example shows how to convert all of a VM's disks to premium storage. 不过,通过在此示例中更改 SKU 变量,可以将 VM 的磁盘类型转换为标准 SSD 或标准 HDD。However, by changing the sku variable in this example, you can convert the VM's disks type to standard SSD or standard HDD. 请注意,若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小Please note that To use Premium managed disks, your VM must use a VM size that supports Premium storage. 此示例还会切换到支持高级存储的大小。This example also switches to a size that supports Premium storage.

备注

请先运行 az cloud set -n AzureChinaCloud 更改云环境,然后才能在 Azure 中国中使用 Azure CLI。Before you can use Azure CLI in Azure China , please run az cloud set -n AzureChinaCloud first to change the cloud environment. 若要切换回 Azure 公有云,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Azure Public Cloud, run az cloud set -n AzureCloud again.


#resource group that contains the virtual machine
rgName='yourResourceGroup'

#Name of the virtual machine
vmName='yourVM'

#Premium capable size 
#Required only if converting from Standard to Premium
size='Standard_DS2_v2'

#Choose between Standard_LRS, StandardSSD_LRS and Premium_LRS based on your scenario
sku='Premium_LRS'

#Deallocate the VM before changing the size of the VM
az vm deallocate --name $vmName --resource-group $rgName

#Change the VM size to a size that supports Premium storage 
#Skip this step if converting storage from Premium to Standard
az vm resize --resource-group $rgName --name $vmName --size $size

#Update the SKU of all the data disks 
az vm show -n $vmName -g $rgName --query storageProfile.dataDisks[*].managedDisk -o tsv \
| awk -v sku=$sku '{system("az disk update --sku "sku" --ids "$1)}'

#Update the SKU of the OS disk
az vm show -n $vmName -g $rgName --query storageProfile.osDisk.managedDisk -o tsv \
| awk -v sku=$sku '{system("az disk update --sku "sku" --ids "$1)}'

az vm start --name $vmName --resource-group $rgName

将各个托管磁盘从一种磁盘类型切换为另一种磁盘类型Switch individual managed disks from one disk type to another

对于开发/测试工作负荷,可以混合使用标准磁盘和高级磁盘来降低成本。For your dev/test workload, you might want to have a mix of Standard and Premium disks to reduce your costs. 可以选择仅升级需要更高性能的磁盘。You can choose to upgrade only those disks that need better performance. 此示例展示了如何将单个 VM 磁盘从标准存储转换为高级存储。This example shows how to convert a single VM disk from Standard to Premium storage. 不过,通过在此示例中更改 SKU 变量,可以将 VM 的磁盘类型转换为标准 SSD 或标准 HDD。However, by changing the sku variable in this example, you can convert the VM's disks type to standard SSD or standard HDD. 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小To use Premium managed disks, your VM must use a VM size that supports Premium storage. 此示例还会切换到支持高级存储的大小。This example also switches to a size that supports Premium storage.


#resource group that contains the managed disk
rgName='yourResourceGroup'

#Name of your managed disk
diskName='yourManagedDiskName'

#Premium capable size 
#Required only if converting from Standard to Premium
size='Standard_DS2_v2'

#Choose between Standard_LRS, StandardSSD_LRS and Premium_LRS based on your scenario
sku='Premium_LRS'

#Get the parent VM Id 
vmId=$(az disk show --name $diskName --resource-group $rgName --query managedBy --output tsv)

#Deallocate the VM before changing the size of the VM
az vm deallocate --ids $vmId 

#Change the VM size to a size that supports Premium storage 
#Skip this step if converting storage from Premium to Standard
az vm resize --ids $vmId --size $size

# Update the SKU
az disk update --sku $sku --name $diskName --resource-group $rgName 

az vm start --ids $vmId 

将托管磁盘从一种磁盘类型切换为另一种磁盘类型Switch managed disks from one disk type to another

执行以下步骤:Follow these steps:

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 在“虚拟机”列表中选择 VM。Select the VM from the list of Virtual machines.
  3. 如果该 VM 未停止,请在 VM“概述”窗格的顶部选择“停止”,然后等待该 VM 停止。 If the VM isn't stopped, select Stop at the top of the VM Overview pane, and wait for the VM to stop.
  4. 在 VM 对应的窗格中,从菜单中选择“磁盘”。In the pane for the VM, select Disks from the menu.
  5. 选择要转换的磁盘。Select the disk that you want to convert.
  6. 在菜单中选择“配置”。Select Configuration from the menu.
  7. 将“帐户类型”从原始磁盘类型更改为所需的磁盘类型。Change the Account type from the original disk type to the desired disk type.
  8. 选择“保存”并关闭磁盘窗格。Select Save, and close the disk pane.

磁盘类型会即时更新。The update of the disk type is instantaneous. 转换后,可以重启 VM。You can restart your VM after the conversion.

后续步骤Next steps

使用快照创建 VM 的只读副本。Make a read-only copy of a VM by using snapshots.