1、创建快照
vish snapshot-create-as vm8 vm8-01.snap
下图的报错是因为:raw格式不支持快照
建议这样命名快照:
快照命名:vm1.snap01,vm1.snap03,vm1.snap04。。。。。。
2、查看快照
virsh snapsshot-list vm2 #查看虚拟机vm2的快照
3、恢复快照
virsh snapshot-revert vm2 vm2.snap3 #给虚拟机VM2恢复第三个快照
4、删除快照
virsh snapsshot-delete --snapshotname vm2.snap3 vm2 #删除vm2虚拟机的第三个快照
5、生产操作实例
[root@localhost ~]# virsh list --all #查看虚拟机
Id 名称 状态
----------------------------------------------------
9 centos7.0-01 running
- win7-01 关闭
[root@localhost ~]# virsh snapshot-list win7-01 #查看虚拟机win7-01的快照
名称 生成时间 状态
------------------------------------------------------------
jihuo 2021-08-11 20:25:56 +0800 shutoff
#给centos7.0-01创建1个快照centos7-chunjing.snap
[root@localhost ~]# virsh snapshot-create-as centos7.0-01 centos7-chunjing.snap
已生成域快照 centos7-chunjing.snap #这里要等2分钟
[root@localhost ~]# virsh snapshot-list centos7.0-01 #查看虚拟机centos7.0-01的快照
名称 生成时间 状态
------------------------------------------------------------
centos7-chunjing.snap 2021-08-11 20:35:17 +0800 running
[root@localhost ~]#
#克隆centos7.0-01
[root@localhost ~]# virsh shutdown centos7.0-01 #克隆前先关闭
域 centos7.0-01 被关闭
[root@localhost ~]# virt-clone -o centos7.0-01 --auto-clone #克隆
正在分配 'centos7.0-01-clone.qcow2' 》》》| 200 GB 00:00:29 #这里需要50秒左右
成功克隆 'centos7.0-01-clone'。
[root@localhost ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
- centos7.0-01 关闭
- centos7.0-01-clone 关闭 #这个就是被克隆出来的
- win7-01 关闭
##我们再克隆一个,这次带参数改名
virt-clone -o centos7.0-01 -n centos7-03 --auto-clone #-n是改名
正在分配 'centos7-03.qcow2' 》》》|| 200 GB 00:00:24
成功克隆 'centos7-03'。
[root@localhost ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
- centos7-03 关闭
- centos7.0-01 关闭
- centos7.0-01-clone 关闭
- win7-01
#我们将centos7.0-01-clone克隆的改个名试试
[root@localhost ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
1 centos7.0-01 running
- centos7-03 关闭
- centos7.0-01-clone 关闭
- win7-01 关闭
[root@localhost ~]# virsh domrename centos7.0-01-clone centos7-02
Domain successfully renamed
[root@localhost ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
1 centos7.0-01 running
- centos7-02 关闭 #改成功了
- centos7-03 关闭
- win7-01 关闭
console口链接虚拟机
虚拟机中输入这个命令,就可以console口链接虚拟机。
下面的这个命令是在虚拟机中执行:
grubby --update-kernel=ALL --args="console==ttyS0,115200n8" #输入完必须重启
reboot
然后在宿主机中执行:
virsh console centos7-02