-
Notifications
You must be signed in to change notification settings - Fork 336
/
create-vm-from-snapshot.sh
40 lines (27 loc) · 1.34 KB
/
create-vm-from-snapshot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Verified per Raman Kumar as of 2/23/2022
# <FullScript>
#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 Managed Disk
osDiskName=myOSDiskName
#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 OS type
osType=linux
#Provide the name of the virtual machine
virtualMachineName=myVirtualMachineName
#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
az disk create --resource-group $resourceGroupName --name $osDiskName --sku $storageType --size-gb $diskSize --source $snapshotId
#Create VM by attaching created managed disks as OS
az vm create --name $virtualMachineName --resource-group $resourceGroupName --attach-os-disk $osDiskName --os-type $osType
# </FullScript>