因为kvm虚拟机磁盘满,准备扩容磁盘,但用qemu-img命令执行扩容扩容的时候出现了下面的问题
- # qemu-img resize /data/AnolisOS.qcow2 +20G
- qemu-img: Could not open '/data/AnolisOS.qcow2': Could not read snapshots: File too large
然后发现虚拟机也启动不了了
- # virsh start AnolisOS
- 错误:开始域 AnolisOS 失败
- 错误:内部错误:qemu unexpectedly closed the monitor: 2022-09-05T08:57:21.971604Z qemu-kvm: -drive file=/data/AnolisOS.qcow2,format=qcow2,if=none,id=drive-virtio-disk0: could not open disk image /ssd/vm/host-38.AnolisOS.qcow2: Could not read snapshots: File too large
通过百度找到仅有的一篇,无头无尾 qemu-img报错 - 知了社区
果断挂梯子,Google之,资料多了些,好像是一个bug,有人已经遇到了 https://bugs.launchpad.net/qemu/+bug/1354167
2个解决方案,都要下载qemu源码,todd大神建议1.7.2版的
- # wget https://download.qemu.org/qemu-1.7.2.tar.bz2
- 。。。。
- # tar jxvf qemu-1.7.2.tar.bz2
1、参考百度来的方案使用test工具(bug回复中也有人回)
- # ./tests/qemu-iotests/qcow2.py /data/AnolisOS.qcow2 dump-header
- magic 0x514649fb
- version 3
- backing_file_offset 0x0
- backing_file_size 0x0
- cluster_bits 16
- size 21475270656
- crypt_method 0
- l1_size 62
- l1_table_offset 0x11a7c0000
- refcount_table_offset 0x10000
- refcount_table_clusters 1
- nb_snapshots 2
- snapshot_offset 0xb0000
- incompatible_features 0x0
- compatible_features 0x0
- autoclear_features 0x0
- refcount_order 4
- header_length 104
-
- # ./tests/qemu-iotests/qcow2.py /data/AnolisOS.qcow2 set-header nb_snapshots 0
- # ./tests/qemu-iotests/qcow2.py /data/AnolisOS.qcow2 set-header snapshot_offset 0x0
- # ./tests/qemu-iotests/qcow2.py /data/AnolisOS.qcow2 dump-header
- magic 0x514649fb
- version 3
- backing_file_offset 0x0
- backing_file_size 0x0
- cluster_bits 16
- size 21475270656
- crypt_method 0
- l1_size 62
- l1_table_offset 0x11a7c0000
- refcount_table_offset 0x10000
- refcount_table_clusters 1
- nb_snapshots 0
- snapshot_offset 0x0
- incompatible_features 0x0
- compatible_features 0x0
- autoclear_features 0x0
- refcount_order 4
- header_length 104
成功!
2、编译后使用编译后的执行文件转换(不要安装)
# ./configure && make
编译后执行
- # ./qemu-img convert /data/AnolisOS.qcow2 /data/AnolisOS.fixed.qcow2
- # mv /data/AnolisOS.qcow2 /data/AnolisOS.qcow2.bak && mv /data/AnolisOS.fixed.qcow2 /data/AnolisOS.qcow2
检查文件信息正常了,损害的时候info查看不了
- # qemu-img info /data/AnolisOS.qcow2
- image: /data/AnolisOS.qcow2
- file format: qcow2
- virtual size: 20G (21475270656 bytes)
- disk size: 25G
- cluster_size: 65536
- Format specific information:
- compat: 1.1
- lazy refcounts: false
之后扩容就正常了
- # qemu-img resize /data/AnolisOS.qcow2 +20G
- Image resized.