kvm部署虚拟机 简单

标题脚本

vim kvm.sh
#!/usr/bin/bash
##this is kvm bushu xuniji
##2021-3-27
#定义固定变量
KVM_KS_FILE=/home/ks.cfg
KVM_ISO=/tmp/CentOS-7-x86_64-Minimal-1708.iso
new_disk=/home/kvm/data/
#输入自定义变量

read -p "输入虚拟机名称 : " VM_NAME
read -p "输入内存大小,不带单位 : " MEM_SIZE
read -p “输入cpu个数:” VCPUS
read -p “输入主机名 :” HOST_NAME
read -p “输入磁盘大小” DISK_SIZE
#设置默认值
DEF_MEM_SIZE=1024
DEF_VCPUS=1
DEF_DISK_SIZE=10G
DEF_VM_NAME=“centos$(date +%Y%m%dT%H%M%S)”

VM_NAME=KaTeX parse error: Expected '}', got 'EOF' at end of input: {VM_NAME:-DEF_VM_NAME}
MEM_SIZE=KaTeX parse error: Expected '}', got 'EOF' at end of input: {MEM_SIZE:-DEF_MEM_SIZE}
VCPUS=KaTeX parse error: Expected '}', got 'EOF' at end of input: {VCPUS:-DEF_VCPUS}
DISK_SIZE=KaTeX parse error: Expected '}', got 'EOF' at end of input: {DISK_SIZE:-DEF_DISK_SIZE}
qemu-img create -f qcow2 n e w d i s k new_disk newd​iskHOST_NAME $DISK_SIZE

#开始创建
virt-install -v
–arch x86_64 --virt-type kvm
–name ${VM_NAME}
–memory ${MEM_SIZE}
–vcpus ${VCPUS}
–os-type linux
–location KaTeX parse error: Undefined control sequence: \ at position 11: {KVM_ISO} \̲ ̲ --network …{KVM_KS_FILE}"
–extra-args “ks=file:/ks.cfg
console=tty0 console=ttyS0,115200n8
hostname=${HOST_NAME}”
–disk n e w d i s k new_disk newd​iskHOST_NAME,cache=writeback,io=threads,bus=virtio

上一篇:ORACLE 只读数据文件备份与恢复


下一篇:Prometheus监控CPU,Memory,Disk