-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-vm.sh
executable file
·52 lines (43 loc) · 1.29 KB
/
create-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
#!/bin/sh
# Creates a virtual machine from a base image, using CoW
# DO NOT DELETE YOUR BASE IMAGE AFTER YOU CREATE A VM, YOU WILL LOSE DATA
# If you don't want CoW copies of your base image, replace the `qemu-img` command below with:
# cp -v $6 $VMDIR/$1.qcow2
set -e
. ./config.sh
usage() {
echo "$0 <name> <domain> <cpus> <memory> <disksize> <baseimage> <user> <MAC address>"
}
if [ $# -ne 8 ]; then
usage
exit 1
fi
if [ ! -f ./create-local-config.sh ]; then
echo "This script needs ./create-local-config.sh to run!"
exit 1
fi
if [ ! -f $6 ]; then
echo "Can't find base image at $6!"
usage
exit 1
fi
if [ -f $VMDIR/$1 ]; then
echo "Refusing to overwrite image at $VMDIR/$1!"
exit 1
fi
qemu-img create -f qcow2 -F qcow2 -b $6 $VMDIR/$1.qcow2 $5
./create-local-config.sh $1 $2 $7
chown -v $VMUSER:$VMGROUP $VMDIR/$1.qcow2 $VMDIR/$1-cidata.iso
chmod -v 0600 $VMDIR/$1.qcow2 $VMDIR/$1-cidata.iso
# Manually copying images requies a pool refresh
virsh pool-refresh $VMPOOL
virt-install \
-n $1 \
--memory $4 \
--vcpus $3 \
--os-variant $OSVARIANT \
--controller scsi,model=virtio-scsi \
-w bridge=$VMBRIDGE,model=virtio,mac=$8 \
--disk vol=$VMPOOL/$1.qcow2,bus=scsi,cache=directsync --import \
--disk vol=$VMPOOL/$1-cidata.iso,device=cdrom,bus=scsi,cache=directsync \
--autostart --noautoconsole