forked from samli008/kvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm-esxi
37 lines (33 loc) · 1.21 KB
/
vm-esxi
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
read -p "input vm name:[e01]" name
name=${name:-e01}
read -p "input local disk [disk01]:" disk
disk=${disk:-disk01}
read -p "input memory size 8[G]:" mem
mem=${mem:-8}
mem=$((mem*1024))
read -p "input vcpu core [2]:" cpu
cpu=${cpu:-2}
read -p "input vlan [vlan200]:" vlan
vlan=${vlan:-vlan200}
read -p "VNC port [5921]:" port
port=${port:-5921}
read -p "VNC passwd:[liyang]" pass
pass=${pass:-liyang}
cp /kvm/esxi /kvm/$name
qemu-img create -f qcow2 /kvm/$disk 500G
virt-install --name $name --virt-type kvm --ram $mem --vcpus $cpu,maxvcpus=40 \
--import --disk path=/kvm/$name,bus=sata \
--import --disk path=/kvm/$disk,bus=ide \
--cpu host-passthrough \
--network network=br100,portgroup=$vlan,model=e1000 \
--network network=br100,portgroup=vlan200,model=e1000 \
--network network=br100,portgroup=vlan200,model=e1000 \
--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"