KVM 维护常用命令

【KVM 维护常用命令】眼前多少难甘事,自古男儿当自强。这篇文章主要讲述KVM 维护常用命令相关的知识,希望能为你提供帮助。
常用命令 创建虚拟机

# 创建目录 cd /data/vm/ # 创建虚机文件夹 155 表示IP为x.x.x.155的 主机目录 mkdir /data/vm/CentOS7-155 # 复制出是镜像 cp ../images/centos7.qcow2 /data/vm/CentOS7-155opt_ip=155 # 内存大小MB opt_memory=4096 # cpu 4核 opt_cpu=4 mac=55 virt-install --os-variant centos7.0 --arch=x86_64 --name CentOS7-$opt_ip --memory $opt_memory --vcpus $opt_cpu --disk path=/data/vm/CentOS7-$opt_ip/centos7.qcow2,format=qcow2,device=disk,bus=virtio --network bridge=br0 --mac=52:54:00:82:9e:$mac --boot hd --graphics none --accelerate --force --autostart --import --noautoconsole

虚拟机维护
# 查看虚机 virsh list# 关闭虚机 virsh destory CentOS7-155# 删除配置 virsh undefine CentOS7-155# 删除数据 rm -rf /opt/data/vm/CentOS7-155# 创建快照,快照期间虚机是paused状态,无法使用 virsh snapshot-create-as CentOS7-1552021-09-08# 查看快照 virsh snapshot-list CentOS7-155 # 还原快照 virsh snapshot-revertCentOS7-1552021-09-08# 删除快照 virsh snapshot-delete CentOS7-155 2021-09-08# 磁盘扩容,要先停机 qemu-img resize /data/vm/CentOS7-$opt_ip/centos7.qcow2 +50G qemu-img check /data/vm/CentOS7-$opt_ip/centos7.qcow2

virsh快照相关命令汇总
Domain Management (help keyword \'domain\'): restorerestore a domain from a saved state in a file savesave a domain state to a file save-image-defineredefine the XML for a domain\'s saved state file save-image-dumpxmlsaved state domain information in XML save-image-editedit XML for a domain\'s saved state filemanagedsavemanaged save of a domain state managedsave-removeRemove managed save of a domain managedsave-editedit XML for a domain\'s managed save state file managedsave-dumpxmlDomain information of managed save state file in XML managedsave-defineredefine the XML for a domain\'s managed save state fileSnapshot (help keyword \'snapshot\'): snapshot-createCreate a snapshot from XML snapshot-create-asCreate a snapshot from a set of args snapshot-currentGet or set the current snapshot snapshot-deleteDelete a domain snapshot snapshot-dumpxmlDump XML for a domain snapshot snapshot-editedit XML for a snapshot snapshot-infosnapshot information snapshot-listList snapshots for a domain snapshot-parentGet the name of the parent of a snapshot snapshot-revertRevert a domain to a snapshot


    推荐阅读