本文說明如何將現有的磁碟從本地備援儲存體 (LRS) 轉換為區域備援儲存體 (ZRS)。
如需瞭解 ZRS 的概念,請參閱受控磁碟的區域備援儲存體
限制
只有進階 SSD 和標準 SSD 受控磁碟支援受控磁碟的 ZRS。 進階 SSD v2 受控磁碟不支援受控磁碟的 ZRS。 強制卸離僅支持數據磁碟。
區域可用性
ZRS 磁碟目前已在以下地區內上市:
- 南非北部
- 東亞
- 東南亞
- 澳大利亞東部
- US Gov 維吉尼亞州
- 巴西南部
- 加拿大中部
- 中國北部 3
- 北歐
- 西歐
- 法國中部
- 德國中西部
- 印度中部
- 以色列中部
- 義大利北部
- 日本東部
- 南韓中部
- 墨西哥中部
- 紐西蘭北部
- 挪威東部
- 波蘭中部
- 卡達中部
- 西班牙中部
- 瑞典中部
- 瑞士北部
- 阿拉伯聯合大公國北部
- 英國南部
- 美國中部
- 美國東部
- 美國東部 2
- 美國中南部
- 美國西部 2
- 美國西部 3
判斷基礎結構備援
將磁碟從 LRS 轉換為 ZRS 之前,您必須先識別磁碟是分區還是區域。 如何根據磁碟分區或區域來移轉磁碟變更。
- 登入 Azure 入口網站
- 瀏覽至您的磁碟,並在 [概觀] 索引標籤的 [可用性區域] 底下 查看。
- 如果此值為 [不需要基礎結構備援],您就會擁有區域磁碟。 使用區域移轉來移轉磁碟。
- 如果值是任何其他值,您就會有分區磁碟。 使用分區移轉來移轉磁碟。
執行下列命令並觀察輸出。 如果區域中沒有值,您就會有區域磁碟。 使用區域移轉來移轉磁碟。 否則,您就會有分區磁碟。 使用分區移轉來移轉磁碟。
Get-AzDisk -DiskName your_disk_name_here -ResourceGroupName your_RG_name_here
執行下列命令並觀察輸出。 如果區域中沒有值,您就會有區域磁碟。 使用區域移轉來移轉磁碟。 否則,您就會有分區磁碟。 使用分區移轉來移轉磁碟。
az disk show --name your_disk_name_here --resource-group your_RG_name_here
區域移轉
您可以使用下列選項,直接變更區域磁碟的磁碟類型。
請遵循這些步驟:
- 登入 Azure 入口網站。
- 從虛擬機器清單中選取 VM。
- 如果 VM 未停止,請選取 VM [概觀] 窗格頂端的 [停止],並等候 VM 停止。
- 在 VM 的窗格中,從功能表中選取 [磁碟]。
- 選取您要轉換的磁碟。
- 從功能表中選取 [大小 + 效能]。
- 將 [帳戶類型] 從原始磁碟類型變更為所需的磁碟類型。
- 選取 [儲存],然後關閉磁碟窗格。
磁碟類型會立即轉換。 您可以在轉換之後啟動 VM。
$diskName = 'yourDiskName'
# resource group that contains the managed disk
$rgName = 'yourResourceGroupName'
# Choose between StandardSSD_ZRS or Premium_ZRS based on your scenario
$storageType = 'Premium_ZRS'
# 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
#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 StandardSSD_ZRS or Premium_ZRS based on your scenario
sku='Premium_ZRS'
#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
分區移轉
在本節中,您會將資料從目前的受控磁碟移轉至 ZRS 受控磁碟。
如果您有分區磁碟,則無法直接變更其類型。 您必須建立快照集,並使用該快照集來建立新的 ZRS 磁碟。
步驟 1:建立您的快照集
建立快照集的最簡潔的方式是在 VM 離線時進行。 請參閱快照集。 如果您選擇此方法,預期會有一段停機時間。 若要使用 Azure 入口網站、PowerShell 或 Azure CLI 建立 VM 的快照集,請參閱建立虛擬硬碟的快照集
如果您要擷取連接至執行中 VM 的磁碟快照集,請先閱讀快照集中的指導,再繼續進行。
步驟 2:移轉受控磁碟上的資料
現在您已擁有原始磁碟的快照集,您可以使用它們來建立 ZRS 受控磁碟。
將資料移轉至 ZRS 受控磁碟
使用下列 Azure CLI 程式碼片段,從來源磁碟快照集建立 ZRS 受控磁碟:
# Create a new ZRS Managed Disks using the snapshot Id and the SKU supported
storageType=Premium_ZRS
location=westus2
az disk create --resource-group $resourceGroupName --name $diskName --sku $storageType --size-gb $diskSize --source $snapshotId
步驟 3:使用新磁碟建立新的 VM
現在,您已將資料移轉至 ZRS 受控磁碟或區域性受控磁碟,接下來請將這些新磁碟設定為 OS 和資料磁碟,以建立新的 VM:
az vm create -g MyResourceGroup -n MyVm --attach-os-disk newZonalOSDiskCopy --attach-data-disks newZonalDataDiskCopy --os-type linux