Qcow2扩展

最近研究openstack,了解了一下qcow2格式。

首先来说目前主要有哪些格式来作为虚拟机的镜像,以及各自优缺点:

Raw images

Pros

  • Simple to create
  • Can be manipulated using standard tools
  • Can be mounted directly via the loopback device

Cons

  • Poor performance when copying over the network

Discussion

With a strictly local installation, raw images are probably the best choice. They can be space efficient (if you create sparse images), and they are easy to manipulate. Unfortunately, sparse files only save space when on disk; when a tool needs to copy the file (for example, when you register a disk image with OpenNebula), the tool will need to read the "logical" size of the file. That is, if you create a 10G sparse image with only 1G of actual data, a copy operation will still need to read 10G of data.

While this behavior does not present problems for a running virtual machine instance, it makes the provisioning process frustrating due to the time it takes to copy the disk image.

简单来说raw用一个字概括就是裸,是一种“直读直写”的格式,所以性能还比较好,但是缺少了元数据区域的支持,容易导致文件系统和数据拷贝出错。由于原始,有很多原生的特性 ,支持转换成其它格式的虚拟机镜像,一般作为转换中间镜像,空间使用来看,类似于磁盘 ,不足是copy会比较消耗网络带宽和I/O。


QCOW2 images

Pros

  • Can be efficiently copied over the network

Cons

  • Requires special tools to manipulate
  • Can only be mounted using the qemu-nbd server

Discussion

QCOW2 images provide a key advantage over raw disk images: the format only stores data that has been written to the image. While this may sound similar to a sparse image, the practical impact is the the "logical" size of the file is the same as the physical size. For our example above, a 10G QCOW2 image with only 1G of data would only require reading/writing 1G of data when copying the image.

Because this substantially reduces the time required to provision new virtual machine instances, we have selected QCOW2 as the default image format.

Qcow2格式文件起始处有专门的区域存放元数据,支持一些高级特性,如加密,压缩和快照,以节省磁盘空间并保证数据安全。



Qcow2扩展

将qcow2原有文件10G空间增加2G为12G

1.关闭虚拟机

2. 创建一个空磁盘,大小为需要增加的磁盘大小2G:

qemu-img create -f raw adddisk.raw 2G

3.将要增加的源qcow2文件转换成raw格式:

qemu-img convert -f qcow2 debian-5.qcow2 -O raw debian5-convert.raw

4. 将空磁盘追加到源磁盘尾部:

cat adddisk.raw >> debian5-convert.raw

5.将转换后的磁盘转换回qcow2格式:

qemu-img convert -f raw debian5-convert.raw -O qcow2 debian5-convert-expanded.qcow2

6.重新开启虚拟机 将新文件debian5-convert-expanded.img挂载。 发现系统增加2G空间,然后可分区格式化挂载。


经测试,在IO测试中,qcow2读写性能都稍逊raw。但由于qcow2支持更小的存储空间,这大大减少所需的时间,从而提供新的虚拟机实例,而且稳定性,安全性相对较好,支持功能丰富。

转载于:https://my.oschina.net/davehe/blog/93787

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值