forked from samli008/kvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm
28 lines (26 loc) · 975 Bytes
/
vm
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
read -p "input vm type 2008 2012 c6 c7 [c7]:" vm
vm=${vm:-c7}
read -p "input vm name:" name
read -p "input memory size 1[G]:" mem
mem=${mem:-1}
mem=$((mem*1024))
read -p "input vcpu core [1]:" cpu
cpu=${cpu:-1}
read -p "input bridge [br1]:" br
br=${br:-br1}
read -p "VNC port [5921]:" port
port=${port:-5921}
read -p "VNC passwd:[liyang]" pass
pass=${pass:-liyang}
cp /kvm/$vm /kvm/$name
virt-install --name $name --virt-type kvm --ram $mem --vcpus $cpu,maxvcpus=40 \
--import --disk path=/kvm/$name,cache=writeback,bus=virtio \
--network bridge=$br,model=virtio --graphics vnc,password=$pass,port=$port,listen=0.0.0.0 \
--noautoconsole --noreboot
cp /etc/libvirt/qemu/$name.xml /kvm/xml/$name.xml
virsh undefine $name
sed -i "/<\/console>/a <input type='tablet' bus='usb'\/>" /kvm/xml/$name.xml
virsh define /kvm/xml/$name.xml
virsh start $name
echo "vmname:$name vncport:$port vncpasswd:$pass" >> /kvm/vm-list
echo "please start vm and via VNC port $port connection vm"