好资源导航 » 文章资讯 » KVM 维护常用命令

KVM 维护常用命令

创建虚拟机

# 创建目录
cd /data/vm/
# 创建虚机文件夹 155 表示IP为x.x.x.155的 主机目录
mkdir /data/vm/CentOS7-155
# 复制出是镜像
cp ../images/centos7.qcow2 /data/vm/CentOS7-155

opt_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-155  2021-09-08

# 查看快照
virsh snapshot-list CentOS7-155 

# 还原快照
virsh snapshot-revert  CentOS7-155  2021-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'):
    restore                        restore a domain from a saved state in a file
    save                           save a domain state to a file                       
    save-image-define              redefine the XML for a domain's saved state file
    save-image-dumpxml             saved state domain information in XML      
    save-image-edit                edit XML for a domain's saved state file

    managedsave                    managed save of a domain state
    managedsave-remove             Remove managed save of a domain
    managedsave-edit               edit XML for a domain's managed save state file
    managedsave-dumpxml            Domain information of managed save state file in XML
    managedsave-define             redefine the XML for a domain's managed save state file

Snapshot (help keyword 'snapshot'):
    snapshot-create                Create a snapshot from XML
    snapshot-create-as             Create a snapshot from a set of args
    snapshot-current               Get or set the current snapshot
    snapshot-delete                Delete a domain snapshot
    snapshot-dumpxml               Dump XML for a domain snapshot
    snapshot-edit                  edit XML for a snapshot
    snapshot-info                  snapshot information
    snapshot-list                  List snapshots for a domain
    snapshot-parent                Get the name of the parent of a snapshot
    snapshot-revert                Revert a domain to a snapshot

热门推荐