-
Notifications
You must be signed in to change notification settings - Fork 31
/
virt-boot
executable file
·100 lines (85 loc) · 1.66 KB
/
virt-boot
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
boot_vol_bus=virtio
ARGS=$(getopt -o s:b:c:u:v:ik: --long ssh-key:,size:,import,bus:,base-image:,config:,user-data:,vendor-data: -n virt-boot -- "$@")
if [ $? -ne 0 ]; then
echo "usage: $myname --base-image <baseimage> <name>"
exit 2
fi
eval set -- "$ARGS"
: ${base_image:=$VIRT_BASE_IMAGE}
while :; do
case "$1" in
--bus)
boot_vol_bus="$2"
shift 2
;;
-b|--base-image)
base_image="$2"
shift 2
;;
-s|--image-size)
base_image_size="$2"
shift 2
;;
-c|--config-drive)
config_image="$2"
shift 2
;;
-k|--ssh-key)
ssh_key="$2"
shift 2
;;
-u|--user-data)
user_data="$2"
shift 2
;;
-v|--vendor-data)
vendor_data="$2"
shift 2
;;
-i|--import)
no_snapshot=1
shift
;;
--) shift
break
;;
esac
done
dom_name=$1
shift
if [ -z "$dom_name" ]; then
echo "ERROR: you must specify a domain name." >&2
exit 1
fi
if [ "$ssh_key" ] && [ -f "$ssh_key" ]; then
ssh_key_data=$(cat "$ssh_key")
fi
(
virsh destroy $dom_name
virsh undefine $dom_name
) > /dev/null 2>&1
if [ "$no_snapshot" = 1 ]; then
boot_vol=$base_image
else
boot_vol=$(virt-vol ${base_image_size:+-s $base_image_size} \
$base_image $dom_name.qcow2)
if [ $? -ne 0 ]; then
echo "ERROR: failed to create boot volume" >&2
exit 1
fi
fi
if ! [ "$config_image" ]; then
config_image=/tmp/${dom_name}-config.iso
create-config-drive \
-h $dom_name \
${ssh_key:+-k $ssh_key} \
${user_data:+-u $user_data} \
${vendor_data:+-v $vendor_data} \
$config_image
fi
virt-install -n $dom_name \
--disk vol=$boot_vol,bus=$boot_vol_bus --import \
--noautoconsole \
${config_image:+--disk path=$config_image,device=cdrom} \
"$@"