你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

更改 Azure 托管磁盘的磁盘类型

适用于:✔️ Linux VM ✔️ Windows

Azure 托管磁盘有五种磁盘类型:Azure 超级磁盘、高级 SSD v2、高级 SSD、标准 SSD 和标准 HDD。 可以根据性能需求轻松在高级 SSD、标准 SSD 和标准 HDD 之间进行切换。 高级 SSD 和标准 SSD 也可用于区域冗余存储。 你目前无法从超级磁盘或高级 SSD v2 切换,必须部署具有现有磁盘快照的新磁盘。 有关详细信息,请参阅迁移到高级 SSD v2 或超级磁盘

非托管磁盘不支持此功能。 但是,可以轻松通过 CLIPowerShell 将非托管磁盘转换为托管磁盘,然后即可切换磁盘类型。

在开始之前

由于转换需要重启虚拟机 (VM),因此请在预先存在的维护时段内计划磁盘迁移。

限制

  • 每天只能更改两次磁盘类型。
  • 只能更改托管磁盘的磁盘类型。 如果是非托管磁盘,请通过 CLIPowerShell 将其转换为托管磁盘,以在磁盘类型之间进行切换。

将 VM 的所有托管磁盘从一个帐户切换到另一个帐户

此示例展示了如何将 VM 的所有磁盘转换为高级存储。 不过,通过在此示例中更改 $storageType 变量,可以将 VM 的磁盘类型转换为标准 SSD 或标准 HDD。 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小。 此示例还切换到了支持高级存储的大小:

# Name of the resource group that contains the VM
$rgName = 'yourResourceGroup'

# Name of the your virtual machine
$vmName = 'yourVM'

# Choose between Standard_LRS, StandardSSD_LRS, StandardSSD_ZRS, Premium_ZRS, and Premium_LRS based on your scenario
$storageType = 'Premium_LRS'

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

# Stop and deallocate the VM before changing the size
Stop-AzVM -ResourceGroupName $rgName -Name $vmName -Force

$vm = Get-AzVM -Name $vmName -resourceGroupName $rgName

# Change the VM size to a size that supports Premium storage
# Skip this step if converting storage from Premium to Standard
$vm.HardwareProfile.VmSize = $size
Update-AzVM -VM $vm -ResourceGroupName $rgName

# Get all disks in the resource group of the VM
$vmDisks = Get-AzDisk -ResourceGroupName $rgName 

# For disks that belong to the selected VM, convert to Premium storage
foreach ($disk in $vmDisks)
{
	if ($disk.ManagedBy -eq $vm.Id)
	{
		$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
		$disk | Update-AzDisk
	}
}

Start-AzVM -ResourceGroupName $rgName -Name $vmName

更改单个托管磁盘的类型

对于开发/测试工作负荷,可以混合使用标准磁盘和高级磁盘来降低成本。 可以选择仅升级需要更高性能的磁盘。 此示例展示了如何将单个 VM 磁盘从标准存储转换为高级存储。 不过,通过在此示例中更改 $storageType 变量,可以将 VM 的磁盘类型转换为标准 SSD 或标准 HDD。 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小。 还可以使用这些示例将磁盘从本地冗余存储 (LRS) 磁盘更改为区域冗余存储 (ZRS) 磁盘,反之亦然。 此示例还展示了如何切换到支持高级存储的大小:


$diskName = 'yourDiskName'
# resource group that contains the managed disk
$rgName = 'yourResourceGroupName'
# Choose between Standard_LRS, StandardSSD_LRS, StandardSSD_ZRS, Premium_ZRS, and Premium_LRS based on your scenario
$storageType = 'Premium_LRS'
# Premium capable size 
$size = 'Standard_DS2_v2'

$disk = Get-AzDisk -DiskName $diskName -ResourceGroupName $rgName

# Get parent VM resource
$vmResource = Get-AzResource -ResourceId $disk.ManagedBy

# Stop and deallocate the VM before changing the storage type
Stop-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name -Force

$vm = Get-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name 

# Change the VM size to a size that supports Premium storage
# Skip this step if converting storage from Premium to Standard
$vm.HardwareProfile.VmSize = $size
Update-AzVM -VM $vm -ResourceGroupName $rgName

# Update the storage type
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$disk | Update-AzDisk

Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name

迁移到高级 SSD v2 或超级磁盘

目前,只能通过存储在标准存储上的快照(增量标准 HDD 快照)将现有磁盘迁移到超级磁盘或高级 SSD v2。 不支持使用存储在高级存储上的快照和其他选项进行迁移。

高级 SSD v2 磁盘和超级磁盘都有各自的一组限制。 例如,两者都不能用作 OS 磁盘,并且并非在所有区域中都可用。 有关详细信息,请参阅高级 SSD v2 限制超级磁盘 GA 范围和限制部分。

重要

将标准 HDD、标准 SSD 或高级 SSD 迁移到超级磁盘或高级 SSD v2 时,逻辑扇区大小必须为 512。

以下脚本将标准 HDD、标准 SSD 或高级 SSD 的快照迁移到超级磁盘或高级 SSD v2。

$diskName = "yourDiskNameHere"
$resourceGroupName = "yourResourceGroupNameHere"
$snapshotName = "yourDesiredSnapshotNameHere"

# Valid values are 1, 2, or 3
$zone = "yourZoneNumber"

#Provide the size of the disks in GB. It should be greater than the VHD file size.
$diskSize = '128'

#Provide the storage type. Use PremiumV2_LRS or UltraSSD_LRS.
$storageType = 'PremiumV2_LRS'

#Provide the Azure region (e.g. westus) where Managed Disks will be located.
#This location should be same as the snapshot location
#Get all the Azure location using command below:
#Get-AzLocation

#Select the same location as the current disk
#Note that Premium SSD v2 and Ultra Disks are only supported in a select number of regions
$location = 'eastus'

#When migrating a Standard HDD, Standard SSD, or Premium SSD to either an Ultra Disk or Premium SSD v2, the logical sector size must be 512
$logicalSectorSize=512

# Get the disk that you need to backup by creating an incremental snapshot
$yourDisk = Get-AzDisk -DiskName $diskName -ResourceGroupName $resourceGroupName

# Create an incremental snapshot by setting the SourceUri property with the value of the Id property of the disk
$snapshotConfig=New-AzSnapshotConfig -SourceUri $yourDisk.Id -Location $yourDisk.Location -CreateOption Copy -Incremental 
$snapshot = New-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -Snapshot $snapshotConfig

$diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id -DiskSizeGB $diskSize -LogicalSectorSize $logicalSectorSize -Zone $zone
 
New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName

后续步骤

使用快照创建 VM 的只读副本。