ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux操作系统自动部署--镜像格式

2020-07-11 13:06:11  阅读:278  来源: 互联网

标签:操作系统 min qcow2 image Linux raw 格式 镜像


qcow2、raw、vmdk等镜像格式

目前主要有那些格式来作为虚拟机的镜像:
raw
(default) the raw format is a plain binary image of the disc image, and is very portable. On filesystems that support sparse files, images in this format only use the space actually used by the data recorded in them.
老牌的格式了,用一个字来说就是裸,也就是赤裸裸,你随便dd一个file就模拟了一个raw格式的镜像。由于裸的彻底,性能上来说的话还是不错的。目前来看,KVM和XEN默认的格式好像还是这个格式。因为其原始,有很多原生的特性,例如直接挂载也是一件简单的事情。
裸的好处还有就是简单,支持转换成其它格式的虚拟机镜像对裸露的它来说还是很简单的(如果其它格式需要转换,有时候还是需要它做为中间格式),空间使用来看,这个很像磁盘,使用多少就是多少(du -h看到的大小就是使用大小),但如果你要把整块磁盘都拿走的话得全盘拿了(copy镜像的时候),会比较消耗网络带宽和I/O。接下来还有个有趣的问题,如果那天你的硬盘用着用着不够用了,你咋办,在买一块盘。但raw格式的就比较犀利了,可以在原来的盘上追加空间:
dd if=/dev/zero of=zeros.raw bs=1024k count=4096(先创建4G的空间)
cat foresight.img zeros.raw > new-foresight.img(追加到原有的镜像之后)
当然,好东西是吹出来的,谁用谁知道,还是有挺多问题的。由于原生的裸格式,不支持snapshot也是很正常的。传说有朋友用版本管理软件对raw格式的文件做版本管理从而达到snapshot的能力,估计可行,但没试过,这里也不妄加评论。但如果你使用LVM的裸设备,那就另当别论。说到LVM还是十分的犀利的,当年用LVM做虚拟机的镜像,那性能杠杠的。而且现在好多兄弟用虚拟化都采用LVM来做的。在LVM上做了很多的优化,国外听说也有朋友在LVM增量备份方面做了很多的工作。目前来LVM的snapshot、性能、可扩展性方面都还是有相当的效果的。目前来看的话,备份的话也问题不大。就是在虚拟机迁移方面还是有很大的限制。但目前虚拟化的现状来看,真正需要热迁移的情况目前需求还不是是否的强烈。虽然使用LVM做虚拟机镜像的相关公开资料比较少,但目前来看牺牲一点灵活性,换取性能和便于管理还是不错的选择。

对于LVM相关的特性及使用可以参考如下链接:

http://www.ibm.com/developerworks/linux/library/l-lvm2/index.html

cow
copy-on-write format, supported for historical reasons only and not available to QEMU on Windows
曾经qemu的写时拷贝的镜像格式,目前由于历史遗留原因不支持窗口模式。从某种意义上来说是个弃婴,还没得它成熟就死在腹中,后来被qcow格式所取代。

qcow
the old QEMU copy-on-write format, supported for historical reasons and superseded by qcow2

一代的qemu的cow格式,刚刚出现的时候有比较好的特性,但其性能和raw格式对比还是有很大的差距,目前已经被新版本的qcow2取代。其性能可以查看如下链接:
http://www.linux-kvm.org/page/Qcow2

qcow2
QEMU copy-on-write format with a range of special features, including the ability to take multiple snapshots, smaller images on filesystems that don’t support sparse files, optional AES encryption, and optional zlib compression
现在比较主流的一种虚拟化镜像格式,经过一代的优化,目前qcow2的性能上接近raw裸格式的性能,这个也算是redhat的官方渠道了,哈哈,希望有朋友能拍他们砖:

https://fedoraproject.org/wiki/Features/KVM_qcow2_Performance

对于qcow2的格式,几点还是比较突出的,qcow2的snapshot,可以在镜像上做N多个快照:

  • 更小的存储空间,即使是不支持holes的文件系统也可以(这下du -h和ls -lh看到的就一样了)
  • Copy-on-write support, where the image only represents changes made to an underlying disk image(这个特性SUN ZFS表现的淋漓尽致)
  • 支持多个snapshot,对历史snapshot进行管理
  • 支持zlib的磁盘压缩
  • 支持AES的加密

vmdk 
VMware 3 & 4, or 6 image format, for exchanging images with that product
VMware的格式,这个格式说的蛋疼一点就有点牛X,原本VMware就是做虚拟化起家,自己做了一个集群的VMDK的pool,做了自己的虚拟机镜像格式。又拉着一些公司搞了一个OVF的统一封包。从性能和功能上来说,vmdk应该算最出色的,由于vmdk结合了VMware的很多能力,目前来看,KVM和XEN使用这种格式的情况不是太多。但就VMware的Esxi来看,它的稳定性和各方面的能力还是可圈可点。

vdi
VirtualBox 1.1 compatible image format, for exchanging images with VirtualBox.
SUN收购了VirtualBox,Oracle又收购了SUN,这么说呢,vdi也算虚拟化这方面的一朵奇葩,可惜的是入主的两家公司。SUN太专注于技术(可以说是IT技术最前端也不为过),Oracle又是开源杀手(mysql的没落)。单纯从能力上来说vdi在VirtualBox上的表现还是不错的。也是不错的workstation级别的产品。

说了这么多虚拟机镜像格式,这么多虚拟化,做云计算的伤不起呀,得为长期发展考虑,也有朋友对镜像的转换做了很多事情,简单看看几种镜像的转化:

VMDK–>qcow2:

kevin@kevin:~# qemu-img convert -f vmdk -O qcow2 SLES11SP1-single.vmdk SLES11SP1-single.img

http://www.ibm.com/developerworks/cn/linux/l-cn-mgrtvm3/index.html

qcow2–>raw:

kevin@kevin:~$ qemu-img convert -O qcow2 image-raw.raw image-raw-converted.qcow

 

ova转ovf

ovftool --lax Centos6.6-lamp.ova Centos6.6-lamp.ovf
ovftool --overwrite --shaAlgorithm=sha1 --lax Centos6.6-lamp.ova Centos6.6-lamp.ovf

修改.ovf文件,将
<vssd:VirtualSystemType>virtualbox-2.2</vssd:VirtualSystemType>
修改为
<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>

修改mf文件的sha1
echo sha1(file_get_contents('xxx.mf'))

================= End

 

qcow2 Performance status

Growing images (IDE)

An image format like qcow2 has the largest overhead compared to raw images when it needs grow the image, i.e. allocate new clusters. One scenario where you constantly get this worst case is the installation of an OS to an empty qcow2 image. Therefore installations are a good test to see if we get reasonable performance in this case.

The following table shows the installation times for a minimal RHEL 5.3 VM with old and new qcow2 drivers, and for comparison raw images. The installation was done with all three different cache settings. The VMs used IDE disks.

cache =offwritethroughwriteback
Old qcow2 (0.10.5) 16:52 min 28:58 min 6:02 min
New qcow2 (0.11.0-rc1) 5:44 min 9:18 min 6:11 min
raw 5:41 min 7:24 min 6:03 min

Growing images (virtio)

This is the same test as above, with IDE replaced by virtio.

cache =offwriteback
Old qcow2 (0.10.5) 31:09 min 8:00 min
New qcow2 (0.11.0-rc1) 18:35 min 8:41 min
raw 8:48 min 7:51 min

Using allocated images

The above numbers are important for installation and running a freshly installed VM. After a certain time, accesses to the disk only touch already allocated clusters of the disk image.

For the following bonnie++ test results, the disk image have been completely allocated, then an ext2 file system has been created and bonnie++ was run on it. The test was run with the following qemu command line:

$ qemu-system-x86_64 -drive file=systen.img,if=ide -drive file=scratch.qcow2,if=virtio,cache=off -m 768

In the guest:

# dd if=/dev/zero of=/dev/vda bs=1M
# mke2fs /dev/vda
# mount /dev/vda /mnt
# bonnie++ -b -u root -d /mnt

In addition to the qcow2 and raw numbers, both for virtio and IDE, the test results contain a test with qcow2 and IDE in qemu-kvm 0.10.5, referred to as "qcow2 old IDE".

Version 1.03e       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
qcow2 IDE     1472M 38232  46 36762   3 16095   4 43605  64 32968   3 112.4   2
qcow2 virtio  1472M 37644  49 37606   3 20626   5 43612  64 46813   7 110.9   1
raw IDE       1472M 37432  44 36824   3 15037   4 43167  71 35088   3 113.2   2
raw virtio    1472M 28301  39 30347   5 19738   5 41751  65 43537   7 109.4   1
qcow2 old IDE 1472M 20777  26 21894   2  9257   2 36482  60 30461   2  67.4   0


                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
qcow2 IDE        16   296  29 +++++ +++   594  16   276  29 +++++ +++   537  18
qcow2 virtio     16   303  22 +++++ +++   609  14   323  24 +++++ +++   589  20
raw IDE          16   288  28 +++++ +++   550  15   272  27 +++++ +++   525  18
raw virtio       16   344  47 +++++ +++   656  57   324  47 +++++ +++   604  60
qcow2 old IDE    16    83  22 +++++ +++   121  14    84  22 +++++ +++   280  15

 

标签:操作系统,min,qcow2,image,Linux,raw,格式,镜像
来源: https://www.cnblogs.com/zhangxinglong/p/13283190.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有