Membuat disk terkelola dari file VHD di akun penyimpanan dalam langganan yang sama dengan CLI (Linux)

Skrip ini membuat disk terkelola dari file VHD di akun penyimpanan dalam langganan yang sama. Gunakan skrip ini untuk mengimpor VHD khusus (tidak digeneralisasi/disiapkan) ke disk OS terkelola untuk membuat mesin virtual. Atau, gunakan untuk mengimpor VHD data ke disk data terkelola.

Jika Anda tidak memiliki Langganan Azure, buat Akun gratis Azure sebelum memulai.

Prasyarat

Sampel skrip

Meluncurkan Azure Cloud Shell

Azure Cloud Shell adalah shell interaktif gratis yang dapat Anda gunakan untuk menjalankan langkah-langkah dalam artikel ini. Shell ini memiliki alat Azure umum yang telah dipasang sebelumnya dan dikonfigurasi untuk digunakan dengan akun Anda.

Untuk membuka Cloud Shell, cukup pilih Cobalah dari sudut kanan atas blok kode. Anda juga dapat meluncurkan Cloud Shell di tab browser terpisah dengan membuka https://shell.azure.com.

Saat Cloud Shell terbuka, verifikasi bahwa Bash dipilih untuk lingkungan Anda. Sesi berikutnya akan menggunakan Azure CLI dalam lingkungan Bash, Pilih Salin untuk menyalin blok kode, tempelkan ke Cloud Shell, lalu tekan Enter untuk menjalankannya.

Masuk ke Azure

Cloud Shell diautentikasi secara otomatis dengan akun awal yang digunakan untuk masuk. Gunakan skrip berikut untuk masuk menggunakan langganan yang berbeda, menggantikan <Subscription ID> dengan ID Langganan Azure Anda. Jika Anda tidak memiliki Langganan Azure, buat Akun gratis Azure sebelum memulai.

subscription="<subscriptionId>" # add subscription here

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

Untuk informasi selengkapnya, lihat mengatur langganan aktif atau masuk secara interaktif

Jalankan skrip

#Provide the subscription Id
subscriptionId="<subscriptionId>"

#Provide the name of your resource group.
#Ensure that resource group is already created 
resourceGroupName=myResourceGroupName

#Provide the name of the Managed Disk
diskName=myDiskName

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


#Provide the URI of the VHD file that will be used to create Managed Disk. 
# VHD file can be deleted as soon as Managed Disk is created.
# e.g. https://contosostorageaccount1.blob.core.windows.net/vhds/contosovhd123.vhd 
vhdUri=https://contosostorageaccount1.blob.core.windows.net/vhds/contosoumd78620170425131836.vhd

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


#Provide the Azure location (e.g. westus) where Managed Disk will be located. 
#The location should be same as the location of the storage account where VHD file is stored.
#Get all the Azure location supported for your subscription using command below:
#az account list-locations
location=westus

#If you're creating an OS disk, uncomment the following lines and replace the values
#osType = 'yourOSType' #Acceptable values are either Windows or Linux
#hyperVGeneration = 'yourHyperVGen' #Acceptable values are either v1 or v2

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

#Create the Managed disk from the VHD file 
#If you're creating an OS disk, add the following: --os-type $osType -hyper-v-generation $hyperVGeneration 
az disk create --resource-group $resourceGroupName --name $diskName --sku $storageType --location $location --size-gb $diskSize --source $vhdUri

Membersihkan sumber daya

Jalankan perintah berikut untuk menghapus grup sumber daya, VM, dan semua sumber daya terkait.

az group delete --name myResourceGroupName

Referensi sampel

Skrip ini menggunakan perintah berikut untuk membuat disk yang dikelola dari VHD. Setiap perintah dalam tabel ditautkan ke dokumentasi spesifik perintah.

Perintah Catatan
az disk create Membuat disk terkelola menggunakan URI VHD di akun penyimpanan dalam langganan yang sama

Langkah berikutnya

Membuat mesin virtual dengan melampirkan disk terkelola sebagai disk OS

Untuk informasi selengkapnya tentang antarmuka tingkat panggilan Azure, lihat Dokumentasi antarmuka tingkat panggilan Azure.

Sampel skrip CLI mesin virtual dan disk terkelola lainnya dapat ditemukan di dokumentasi Mesin Virtual Azure Linux.