克隆主要是对磁盘文件进行操作。
a、拷贝虚拟机磁盘文件
b、生成虚拟机配置文件
centos7-2
291b0480-955a-45e2-a001-690fded69d1b
[root@centos8 ~]# virt-clone -o centos7 --auto-clone
ERROR 要克隆的域必须已经关闭。
[root@centos8 ~]# virsh destroy centos7
Domain ‘centos7’ destroyed
[root@centos8 ~]# virt-clone -o centos7 --auto-clone
‘centos2-clone.qcow2’ 15% [== ] 102 MB/s | 1.5 GB 00:01:25 正在分配 ‘centos2-clone.qcow2’ | 10 GB 00:00:13
成功克隆 ‘centos7-clone’。
[root@centos8 ~]# ll /opt
总用量 9477500
-rw------- 1 root root 1633353728 2月 27 14:03 centos2-clone.qcow2 #比centos2少个快照,所以文件大小要比centos2小
-rw-r–r-- 1 root root 1887109120 2月 27 14:03 centos2.qcow2
[root@centos8 ~]# virsh list --all
Id 名称 状态
[root@centos8 ~]# virsh domrename centos7-clone centos7-2
Domain successfully renamed
[root@centos8 ~]# virsh list --all
Id 名称 状态
a、基于源磁盘文件、生成链接磁盘文件
[root@centos8 opt]# qemu-img create -f qcow2 -F qcow2 -b centos2-clone.qcow2 centos3.qcow2
Formatting ‘centos3.qcow2’, fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=10737418240 backing_file=centos2-clone.qcow2 backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16
[root@centos8 opt]# qemu-img info centos3.qcow2
image: centos3.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: centos2-clone.qcow2
backing file format: qcow2
Format specific information:
compat: 1.1
compression type: zlib
lazy refcounts: false
refcount bits: 16
corrupt: false
extended l2: false
b、生成虚拟机配置文件
c、导入xml并启动
以上两步合并一条命令:
[root@centos8 opt]# virt-install --virt-type kvm --os-type=linux --os-variant rhel7.4 --name centos7-3 --memory 1024 --vcpus 1 --disk /opt/centos3.qcow2 --boot hd --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole