-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create_Image_from_VM.sh
55 lines (44 loc) · 1.15 KB
/
Create_Image_from_VM.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/bash
set -e
# ----------------------------------------------
# This script creates a new image from a give VM
#
# Please update variables
# imgName
# vmName
# resGroup
# to meet your requirements
#
# ***************
# ** IMPORTANT **
# ***************
# remember to deprovision the VM before cloning, i.e. ssh the VM
# and run the following command
# sudo waagent -deprovision -force
# Please note that after such command the VM is no more accessible: so
# after creating the image it is recommend to delete th VM.
# ----------------------------------------------
# -----------------
# main variables
#
imgName=ROL-image-a
vmName=ROL-test-a
resGroup=ROL-test
# -----------------
# default variables
#
user=hlt_admin
passwd=HltMtUser2017
# 0) deallocate the actual VM with all the above pars
args="--resource-group $resGroup --name $vmName"
az vm stop $args
az vm deallocate $args
# 1) generalize the actual VM with all the above pars
#
args="--resource-group $resGroup --name $vmName"
az vm generalize $args
# 2) create the image
args="--resource-group $resGroup --name $imgName"
args="$args --source $vmName"
az image create $args
echo exit code $?