-
Notifications
You must be signed in to change notification settings - Fork 2
/
virt-install-vm.sh
66 lines (59 loc) · 1.71 KB
/
virt-install-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
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#Prepare kickstartfile to $dist-vm.ks and start install
if [ -z $5 ];
then
echo "Syntax: ./virt-install-vm.sh disk_format size vcpu mem dist"
echo "Syntax: ./virt-install-vm.sh <qcow2/raw> 10G 2 1024 fedora22"
exit 1
fi
vm=master
bridge=virbr0
disk_format=$1
size=$2
vcpu=$3
mem=$4
dist=$5
# please note: this repo only contains fedora22's ks_file,
# please be careful about the .ks URL when you choose a different distro.
ks_file="https://raw.githubusercontent.com/psuriset/kvm_io/master/$dist-vm.ks"
master_image=master.$disk_format
image_path=/var/lib/libvirt/images
yum install -y wget
wget $ks_file -O /src/$dist-vm.ks
extra="ks=file:/$disk-vm.ks console=ttyS0,115200"
if ! rpm -qa | grep -qw virt-install; then
yum install -y virt-install
fi
if [ $dist == "fedora22" ]; then
location="https://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/x86_64/os/"
fi
echo deleting master image
/bin/rm -f $image_path/$master_image
echo deleting vm image copies
for i in `seq 1 $nr_vms`; do
set -x
/bin/rm -f $image_path/vm*.qcow2
set +x
done
echo creating new master image
qemu-img create -f $disk_format $image_path/$master_image $size
sync
echo undefining master xml
virsh list --all | grep master && virsh undefine master
echo calling virt-install
virt-install --name=$vm\
--virt-type=kvm\
--disk format=qcow2,path=$image_path/$master_image\
--vcpus=$vcpu\
--ram=$mem\
--network bridge=$bridge\
--os-type=linux\
--os-variant=$dist\
--graphics none\
--extra-args="$extra"\
--initrd-inject=/src/$dist-vm.ks\
--serial pty\
--serial file,path=/tmp/$vm.console\
--location=$location\
--noreboot
#--cdrom=/root/Fedora-Server-DVD-x86_64-22.iso\