解决跨版本KVM镜像无法读取的问题 'image' uses a qcow2 feature which is not supported by this qemu version: QCOW version 3

之前在CentOS7机器上做了一个爬虫虚拟机的镜像模板,将镜像复制到CentOS6机器上发现无法正常运行。

一 、使用 virt-copy-in 命令的时候报错

# virt-copy-in -d wx-snap-vm08 /tmp/set_ip.sh /tmp/

libguestfs: error: /usr/libexec/qemu-kvm exited with error status 1.  
To see full error messages you may need to enable debugging.  
See http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs  
libguestfs: error: guestfs_launch failed.  
See http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs  
and/or run 'libguestfs-test-tool'.  

二、 添加 DEBUG

export LIBGUESTFS_DEBUG=1  
export LIBGUESTFS_TRACE=1  

三、 再次运行命令,查看具体报错信息

virt-copy-in -d wx-snap-vm08 /tmp/set_ip.sh /tmp/

qemu-kvm: -drive file=/data1/vm-images/wx-snap-vm08.qcow2,cache=writeback,format=qcow2,id=hd0,if=none: 'hd0' uses a qcow2 feature which is not supported by this qemu version: QCOW version 3  
qemu-kvm: -drive file=/data1/vm-images/wx-snap-vm08.qcow2,cache=writeback,format=qcow2,id=hd0,if=none: could not open disk image /data1/vm-images/wx-snap-vm08.qcow2: Operation not supported  

四、在 CentOS6 机器上查看镜像信息,发现报错

# /usr/libexec/qemu-kvm --version

QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2-2.479.el6_7.4), Copyright (c) 2003-2008 Fabrice Bellard  

# qemu-img info wx-snap-vm-demo.qcow2

'image' uses a qcow2 feature which is not supported by this qemu version: QCOW version 3  
Could not open 'wx-snap-vm-demo.qcow2': Operation not supported  

五、 在 CentOS7 源模板机器上查看镜像发现是正常的

# /usr/libexec/qemu-kvm --version

QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-105.el7_2.1), Copyright (c) 2003-2008 Fabrice Bellard  

# qemu-img info wx-snap-vm-demo.qcow2

image: wx-snap-vm-demo.qcow2  
file format: qcow2  
virtual size: 500G (536870912000 bytes)  
disk size: 22G  
cluster_size: 65536  
Format specific information:  
    compat: 1.1
    lazy refcounts: true

猜测是镜像版本支持的特性不同,造成在 CentOS6 机器上无法正常运行。

通过如下命令转化成低版本支持的 QCOW2

# qemu-img amend -f qcow2 -o compat=0.10 wx-snap-vm-demo.qcow2

# qemu-img info wx-snap-vm-demo.qcow2

image: wx-snap-vm-demo.qcow2  
file format: qcow2  
virtual size: 500G (536870912000 bytes)  
disk size: 22G  
cluster_size: 65536  
Format specific information:  
    compat: 0.10

六、 将转换过的镜像复制到 CentOS6 机器上再次测试,发现可以成功执行

# qemu-img info wx-snap-vm-demo.qcow2

image: wx-snap-vm-demo.qcow2  
file format: qcow2  
virtual size: 500G (536870912000 bytes)  
disk size: 22G  
cluster_size: 65536  

七、问题解决。 猜测通过升级 qemu 的版本也可以解决