You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
924 B
28 lines
924 B
#!/usr/bin/bash
|
|
|
|
<<!
|
|
editor : NewRain
|
|
date : 2022-08-14
|
|
for kvm virtual machine
|
|
!
|
|
|
|
MAIN_PATH=$(cd $(dirname $0); cd ..; pwd)
|
|
IMAGE_PATH=/tmp/CentOS-7-x86_64-Minimal-2009.iso
|
|
VM_CPUS=1
|
|
VM_TEMPLATE_NAME=template
|
|
VM_MEMORY=2050 # 不能低于2G,单位为M
|
|
VM_DISK_SIZE=5 # 单位为G
|
|
VM_DISK_PATH=${MAIN_PATH}/template/${VM_TEMPLATE_NAME}.qcow2
|
|
|
|
cpus=`lscpu | awk '/^CPU\(s\):/{print $2}'`
|
|
if [ $VM_CPUS -ge $cpus ]; then
|
|
echo "CPU数量不能大于系统的CPU数量,宿主机cpu数量为:$cpus"
|
|
exit 1
|
|
fi
|
|
memory=`free -m | awk '/^Mem:/{print $2}'`
|
|
if [ $VM_MEMORY -ge $memory ]; then
|
|
echo "内存不能大于系统的内存,宿主机内存为:$memory"
|
|
exit 1
|
|
fi
|
|
|
|
virt-install --connect qemu:///system -n ${VM_TEMPLATE_NAME} -r ${VM_MEMORY} --disk path=${VM_DISK_PATH},size=${VM_DISK_SIZE} --os-type=linux --os-variant=centos7.0 --vcpus=${VM_CPUS} --location=${IMAGE_PATH} -x console=ttyS0 --nographics |