CLI를 사용하여 스냅샷에서 관리 디스크 만들기(Linux)

이 문서에는 스냅샷에서 관리 디스크를 만들기 위한 두 개의 스크립트가 포함되어 있습니다. 첫 번째 스크립트는 플랫폼 관리형 키가 있는 관리 디스크용이고 두 번째 스크립트는 고객 관리형 키가 있는 관리 디스크용입니다. 이러한 스크립트를 사용하여 OS 및 데이터 디스크의 스냅샷에서 가상 머신을 복원합니다. 각 스냅샷에서 OS 및 데이터 관리 디스크를 만든 다음, 관리 디스크를 연결하여 새 가상 머신을 만듭니다. 스냅샷에서 만든 데이터 디스크를 연결하여 기존 VM의 데이터 디스크를 복원할 수도 있습니다.

Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

사전 요구 사항

샘플 스크립트

Azure Cloud Shell 시작

Azure Cloud Shell은 이 문서의 단계를 실행하는 데 무료로 사용할 수 있는 대화형 셸입니다. 공용 Azure 도구가 사전 설치되어 계정에서 사용하도록 구성되어 있습니다.

Cloud Shell을 열려면 코드 블록의 오른쪽 위 모서리에 있는 사용해 보세요를 선택하기만 하면 됩니다. 또한 https://shell.azure.com 로 이동하여 별도의 브라우저 탭에서 Cloud Shell을 시작할 수 있습니다.

Cloud Shell이 열리면 환경에 대해 Bash가 선택되어 있는지 확인합니다. 후속 세션은 Bash 환경에서 Azure CLI를 사용합니다. 복사를 선택하여 코드 블록을 복사하고 Cloud Shell에 붙여넣고 Enter 키를 눌러 실행합니다.

Azure에 로그인

Cloud Shell은 로그인한 초기 계정에서 자동으로 인증됩니다. 다음 스크립트를 통해 다른 구독을 사용하여 로그인하고 <Subscription ID>를 Azure 구독 ID로 바꿉니다. Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

자세한 내용은 활성 구독 설정 또는 대화형으로 로그인을 참조하세요.

플랫폼 관리형 키가 있는 디스크

#Provide the subscription Id of the subscription where you want to create Managed Disks
subscriptionId="<subscriptionId>"

#Provide the name of your resource group
resourceGroupName=myResourceGroupName

#Provide the name of the snapshot that will be used to create Managed Disks
snapshotName=mySnapshotName

#Provide the name of the new Managed Disks that will be create
diskName=myDiskName

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

#Provide the storage type for Managed Disk. Acceptable values are Standard_LRS, Premium_LRS, PremiumV2_LRS, StandardSSD_LRS, UltraSSD_LRS, Premium_ZRS, and StandardSSD_ZRS.
storageType=Premium_LRS

#Required for Premium SSD v2 and Ultra Disks
#Provide the Availability Zone you'd like the disk to be created in, default is 1
zone=1

#Set the context to the subscription Id where Managed Disk will be created
az account set --subscription $subscriptionId

#Get the snapshot Id 
snapshotId=$(az snapshot show --name $snapshotName --resource-group $resourceGroupName --query [id] -o tsv)

#Create a new Managed Disks using the snapshot Id
#Note that managed disk will be created in the same location as the snapshot
#If you're creating a Premium SSD v2 or an Ultra Disk, add "--zone $zone" to the end of the command
az disk create --resource-group $resourceGroupName --name $diskName --sku $storageType --size-gb $diskSize --source $snapshotId

고객 관리형 키가 있는 디스크

#Provide the subscription Id of the subscription where you want to create Managed Disks
subscriptionId="<subscriptionId>"

#Provide the name of your resource group
resourceGroupName=myResourceGroupName

#Provide the name of the snapshot that will be used to create Managed Disks
snapshotName=mySnapshotName

#Provide the name of the new Managed Disks that will be create
diskName=myDiskName

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

#Provide the storage type for Managed Disk. Premium_LRS or Standard_LRS.
storageType=Premium_LRS

#Provide the name of the target disk encryption set
diskEncryptionSetName=myName

#Provide the target disk encryption set resource group
diskEncryptionResourceGroup=myGroup

#Required for Premium SSD v2 and Ultra Disks
#Provide the Availability Zone you'd like the disk to be created in, default is 1
zone=1

#Set the context to the subscription Id where Managed Disk will be created
az account set --subscription $subscriptionId

#Get the snapshot Id 
snapshotId=$(az snapshot show --name $snapshotName --resource-group $resourceGroupName --query [id] -o tsv)

#Get the disk encryption set ID
diskEncryptionSetId=$(az disk-encryption-set show --name $diskEncryptionSetName --resource-group $diskEncryptionResourceGroup)

#Create a new Managed Disks using the snapshot Id
#Note that managed disk will be created in the same location as the snapshot
#To change the location, add the --location parameter
#If you're creating a Premium SSD v2 or an Ultra Disk, add "--zone $zone" to the end of the command
az disk create -g $resourceGroupName -n $diskName --source $snapshotId --disk-encryption-set $diskEncryptionSetID --location eastus2euap

성능 영향 - 백그라운드 복사 프로세스

스냅샷에서 관리 디스크를 만들면 백그라운드 복사 프로세스가 시작됩니다. 이 프로세스가 실행되는 동안 VM에 디스크를 연결할 수 있지만 백그라운드 복사가 완료될 때까지 대기 시간이 길어지고 IOPS 및 처리량이 낮아져 성능에 영향을 미치게 됩니다(4k 디스크는 읽기 영향을 받고 512e는 읽기 및 쓰기 영향 둘 다 받게 됨). Ultra Disks 및 프리미엄 SSD v2의 경우 다음 명령을 사용하여 백그라운드 복사 프로세스의 상태를 확인할 수 있습니다.

Important

Ultra Disk 또는 프리미엄 SSD v2 이외의 디스크 유형에 대한 백그라운드 복사 프로세스의 상태를 가져오기 위해 다음 섹션을 사용할 수 없습니다. 다른 디스크 유형은 항상 100%를 보고합니다.

subscriptionId=yourSubscriptionID
resourceGroupName=yourResourceGroupName
diskName=yourDiskName
az account set --subscription $subscriptionId
az disk show -n $diskName -g $resourceGroupName --query [completionPercent] -o tsv

리소스 정리

다음 명령을 실행하여 리소스 그룹, VM 및 모든 관련된 리소스를 제거할 수 있습니다.

az group delete --name myResourceGroupName

샘플 참조

이 스크립트에서는 다음 명령을 사용하여 스냅샷에서 관리 디스크를 만듭니다. 테이블에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 주의
az snapshot show 스냅샷의 이름 및 리소스 그룹 속성을 사용하여 스냅샷의 모든 속성을 가져옵니다. ID 속성은 관리 디스크를 만드는 데 사용됩니다.
az disk create 관리 스냅샷의 스냅샷 ID를 사용하여 관리 디스크 만들기

다음 단계

관리 디스크를 OS 디스크로 연결하여 가상 머신 만들기

Azure CLI에 대한 자세한 내용은 Azure CLI 설명서를 참조하세요.

추가 가상 머신 및 관리 디스크 CLI 스크립트 샘플은 Azure Linux VM 설명서에서 확인할 수 있습니다.