虚拟机系列教程:虚拟机克隆
创始人
2024-05-31 12:44:03
0

克隆主要是对磁盘文件进行操作。

1)完整克隆

a、拷贝虚拟机磁盘文件
b、生成虚拟机配置文件
centos7-2
291b0480-955a-45e2-a001-690fded69d1b

c、导入xml并启动

[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 名称 状态

  • centos7 关闭
  • centos7-clone 关闭
    修改虚拟机名称

[root@centos8 ~]# virsh domrename centos7-clone centos7-2
Domain successfully renamed

[root@centos8 ~]# virsh list --all

Id 名称 状态

  • centos7 关闭
  • centos7-2 关闭
    将克隆的虚拟机跟原先的虚拟机xml文件导出来,查看其两者的区别在哪里?
    [root@centos8 opt]# virsh dumpxml centos7 > centos7.xml
    [root@centos8 opt]# virsh dumpxml centos7-3 > centos7-3.xml
    [root@centos8 opt]# vimdiff centos7.xml centos7-3.xml
    1、虚拟机name
    2、uuid不同
    3、source file的磁盘文件不同
    4、虚拟机的mac地址不同
    手动完整克隆虚拟机:
    1、拷贝虚拟机的磁盘文件
    cp centos7.qcow2 centos7-clone.qcow2
    2、拷贝虚拟机xml配置文件
    cp centos7.xml centos7-clone.xml
    3、修改name、磁盘文件路径
    4、将uuid删掉,下次启动虚拟机时,会自动生成新的uuid
    5、将mac删掉,下次启动虚拟机时,会自动生成新的
    6、导入虚拟机:virsh define centos7-clone.xml
    7、启动虚拟机:virsh start centos7-clone

2)链接克隆

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

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...