このスクリプトは、同じサブスクリプションのストレージ アカウントに VHD ファイルからマネージド ディスクを作成します。 このスクリプトを使用して、特殊化された VHD を管理 OS ディスクにインポートし、それをもとに仮想マシンを作成します。 または、このスクリプトを使用して、データ VHD をマネージド データ ディスクにインポートします。
このサンプルを実行するには、最新バージョンの Azure CLI をインストールします。 開始するには、az login
を実行して、Azure との接続を作成します。
Azure CLI のサンプルは、bash
シェル用に記述されています。 このサンプルを Windows PowerShell またはコマンド プロンプトで実行するには、スクリプトの要素を変更する必要があります。
Azure サブスクリプションをお持ちでない場合は、開始する前に Azure 無料アカウントを作成してください。
サンプル スクリプト
# Verified per Raman Kumar as of 2/23/2022
# <FullScript>
#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
# </FullScript>
スクリプトの説明
このスクリプトは、以下のコマンドを使って VHD からマネージド ディスクを作成します。 表内の各コマンドは、それぞれのドキュメントにリンクされています。
コマンド | 注記 |
---|---|
ディスクを作成するための az コマンドaz disk create | 同じサブスクリプション内のストレージ アカウントに VHD の URI を使用してマネージド ディスクを作成する |
次のステップ
マネージド ディスクを OS ディスクとして接続することで仮想マシンを作成する
Azure CLI の詳細については、Azure CLI のドキュメントのページをご覧ください。
その他の仮想マシンとマネージド ディスクの CLI サンプル スクリプトは、Azure Linux VM のドキュメントにあります。