总结
如果是完整克隆的那种虚拟机,是可以直接在openstack使用的,如果镜像格式没问题的话。
因为kvm虚拟机大部分都是链接克隆出来的镜像,不可用直接复制使用,所以需要创建新的镜像文件
创建空盘:qemu-img create -f qcow2 mcwlink1-new.qcow2 50G
将链接克隆镜像数据导入到空盘,此时会将依赖的基础镜像数据一同导入:qemu-img create -f qcow2 -b mcwtemplate.qcow2 mcwlink2.qcow2
迁移部分信息
基础镜像:mcwtemplate.qcow2
链接克隆镜像,依赖上面基础镜像:mcwlink1.qcow2
链接克隆镜像,依赖上面基础镜像:mcwlink2.qcow2
根据链接克隆镜像mcwlink1.qcow2,创建的可以在openstack正常使用的镜像: mcwlink1-new.qcow2
可正常在openstack使用的链接克隆迁移镜像制作过程
创建两个链接克隆磁盘
[email protected] img\]# ls mcwtemplate.qcow2 v012-c73-st1-extend.qcow2 vm1-c73-history001.qcow2 vq25-cloudservice020.qcow2 vq42-cloudservice38.qcow2 mcwtestbase.qcow2 \[[email protected] img\]# qemu-img create -f qcow2 -b mcwtemplate.qcow2 mcwlink1.qcow2 Formatting 'mcwlink1.qcow2', fmt=qcow2 size=53687091200 backing_file='mcwtemplate.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off \[[email protected] img\]# qemu-img create -f qcow2 -b mcwtemplate.qcow2 mcwlink2.qcow2 Formatting 'mcwlink2.qcow2', fmt=qcow2 size=53687091200 backing_file='mcwtemplate.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off \[[email protected] img\]# pwd /data/kvm/img \[[email protected] img\]# 定义两个实例的配置 \[[email protected] ares\]# ls mcwlink1.xml mcwlink2.xml mcwtest.xml \[[email protected] ares\]# virsh define mcwlink2.xml Domain mcwlink2 defined from mcwlink2.xml \[[email protected] ares\]# virsh start mcwlink2 Domain mcwlink2 started \[[email protected] ares\]# 两个虚拟机都做点改动 \[[email protected] ares\]# virsh console mcwlink1 Connected to domain mcwlink1 Escape character is \^
root@mcwlink1 \~\]# ls anaconda-ks.cfg ks-post.log ks-pre.log original-ks.cfg cobbler.ks ks-post-nochroot.log mcw.txt \[root@mcwlink1 \~\]# cat mcw.txt mcwlink1 \[root@mcwlink1 \~\]# \[[email protected] ares\]# virsh console mcwlink2 Connected to domain mcwlink2 Escape character is \^
root@mcwlink2 \~\]# cat mcw.txt mcwlink2 \[root@mcwlink2 \~\]# \[[email protected] ares\]# 查看两个链接克隆的磁盘,是依赖基础镜像磁盘的 \[[email protected] img\]# qemu-img info mcwlink1.qcow2 image: mcwlink1.qcow2 file format: qcow2 virtual size: 50G (53687091200 bytes) disk size: 8.1M cluster_size: 65536 backing file: mcwtemplate.qcow2 Format specific information: compat: 1.1 lazy refcounts: false \[[email protected] img\]# qemu-img info mcwlink2.qcow2 image: mcwlink2.qcow2 file format: qcow2 virtual size: 50G (53687091200 bytes) disk size: 14M cluster_size: 65536 backing file: mcwtemplate.qcow2 Format specific information: compat: 1.1 lazy refcounts: false \[[email protected] img\]# mcwlink1-new.qcow2 创建空磁盘,然后使用转换格式的命令将磁盘数据写入到新磁盘,这样做,是会将依赖的基础磁盘backing file一同写入到新磁盘的,这样这个新磁盘就可以在openstack上用了,不然用它创建实例会报错无法创建openstack实例,会去找依赖的基础镜像backing file, 我们也可以看到,下面的磁盘也不是几十m的链接克隆的磁盘了 \[[email protected] img\]# qemu-img convert -f qcow2 -O qcow2 mcwlink1.qcow2 mcwlink1-new.qcow2 \[[email protected] img\]# qemu-img info mcwlink1-new.qcow2 image: mcwlink1-new.qcow2 file format: qcow2 virtual size: 50G (53687091200 bytes) disk size: 3.5G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false \[[email protected] img\]# 使用新的磁盘创建虚拟机,可以看到,原本的数据mcw.txt还在 \[[email protected] ares\]# virsh define mcwlink1-new.xml Domain mcwlink1-new defined from mcwlink1-new.xml \[[email protected] ares\]# virsh start mcwlink1-new Domain mcwlink1-new started \[[email protected] ares\]# virsh console mcwlink1-new Connected to domain mcwlink1-new Escape character is \^
CentOS Linux 7 (Core)
Kernel 4.14.15-1.el7.elrepo.x86_64 on an x86_64
mcwlink1 login: root
Password:
Last login: Fri Jun 7 02:09:14 on ttyS0
root@mcwlink1 \~\]# cat mcw.txt mcwlink1 \[root@mcwlink1 \~\]# \[[email protected] ares\]# ls mcwlink1-new.xml mcwlink1.xml mcwlink2.xml mcwtest.xml \[[email protected] ares\]# cd /data/kvm/img/ \[[email protected] img\]# ls mcwlink1-new.qcow2 v009-servicetest012.qcow2 v024-infotest001.qcow2 vq22-cloudservice017.qcow2 vq39-cloudservice35.qcow2 mcwlink1.qcow2 v010-servicetest013.qcow2 v030-c73-bitest001.qcow2 vq23-cloudservice018.qcow2 vq40-cloudservice36.qcow2 mcwlink2.qcow2 然后用这个镜像,上传到openstack,启动实例,不过这里需要再配置下它的IP,我是设置的自动获取,然后重启网络,就有了openstack给它分配的IP了。