One, qemu-img create a mirrored file
Create a RAW format mirror file (the format is created by default)
code is as follows |
copy code |
yang@yang-acer:/opt/test$ sudo qemu-img create/opt/img/test-raw.img 1G Formatting '/opt/img/test-raw.img ', Fmt=raw size=1073741824 Create normal qcow2 format mirrored file yang@yang-acer:/opt/test$ sudo qemu-img create-f qcow2 /opt/img/test.qcow2 1G Formatting '/opt/img/test.qcow2 ', Fmt=qcow2 size= 1073741824 encryption=off cluster_size=65536 lazy_refcounts=off Create a qcow2 format mirror file for the pre-allocation metadata option yang@yang-acer:/ opt/test$ sudo qemu-img create-f qcow2-o preallocation=metadata/opt/img/test-metadata.qcow2 1G Formatting '/opt/im G/test-metadata.qcow2 ', Fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 preallocation= ' metadata ' lazy_ Refcounts=off |
Note: Here is the name of the pre-allocation metadata, I do not know if there is a problem. Just want to be able to easily understand and distinguish.
Comparison of two or 3 mirrored files
We've created three mirrored files in three ways, and we'll look at the differences by LS-L, stat, qemu-img info, du four ways:
The results given by ls-l
The code is as follows |
Copy Code |
yang@yang-acer:/opt/img$ LL -rw-r--r--1 root root 1074135040 May 15:52 test-metadata.qcow2 -rw-r--r--1 root root 197120 May 15:52 test.qcow2 -rw-r--r--1 root root 1073741824 May 15:52 test-raw.img
|
Ls-l the results show that the QCOW2 format of the pre-allocated metadata image files and raw format of the mirror files occupied by the approximate size, is basically 1G, while the normal format of the Qcow2 mirror file size only about 190K.
The results given by stat
yang@yang-acer:/opt/img$ Stat Test-metadata.qcow2
File: "Test-metadata.qcow2"
Size: 1074135040 Block: 664 IO block: 4096 normal files
Equipment: 808h/2056d inode:530343 Hard Link: 1
Permissions: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Recent visits: 2014-05-23 15:52:36.179523406 +0800
Last change: 2014-05-23 15:52:36.179523406 +0800
Last modified: 2014-05-23 15:52:36.179523406 +0800
Creation Time:-
yang@yang-acer:/opt/img$ Stat test-raw.img
File: "Test-raw.img"
Size: 1073741824 Block: 0 IO block: 4096 normal files
Equipment: 808h/2056d inode:530341 Hard Link: 1
Permissions: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Recent visits: 2014-05-23 15:52:17.915523541 +0800
Last change: 2014-05-23 15:52:17.915523541 +0800
Last modified: 2014-05-23 15:52:17.915523541 +0800
Creation Time:-
yang@yang-acer:/opt/img$ Stat Test.qcow2
File: "Test.qcow2"
Size: 197120 Block: 392 IO block: 4096 normal files
Equipment: 808h/2056d inode:530342 Hard Link: 1
Permissions: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Recent visits: 2014-05-23 15:52:27.943523467 +0800
Last change: 2014-05-23 15:52:27.943523467 +0800
Last modified: 2014-05-23 15:52:27.943523467 +0800
Creation Time:-
Stat gives a more detailed result, where the file size is consistent with the ls-l results.
QEMU-IMG Info gives the results
code is as follows |
copy code |
yang@yang-acer :/opt/img$ qemu-img Info test-metadata.qcow2 Image:test-metadata.qcow2 File format:qcow2 Virtual size:1.0g (1073741824 bytes) Disk size:332k cluster_size:65536 Format Specific information: compat:1.1 ; lazy Refcounts:false yang@yang-acer:/opt/img$ qemu-img info test-raw.img Image:test-raw.img File Format:raw Virtual size:1.0g (1073741824 bytes) Disk size:0 yang@yang-acer:/opt/img$ qemu-img Info tes T.qcow2 Image:test.qcow2 File format:qcow2 Virtual size:1.0g (1073741824 bytes) Disk size:196k CLU ster_size:65536 Format Specific information: compat:1.1 Lazy Refcounts:false Qemu-img Info |
Given the result, there are two indicators that I turn to, one is virtual size and one is disk size. The former is the size of the parameter values after the qemu-img create, the three are 1G, and the results of the latter are consistent with those of Du file-sh.
Results of Du:
The code is as follows |
Copy Code |
Yang@yang-acer:/opt/img$du Test-metadata.qcow2-sh 332K Test-metadata.qcow2 Yang@yang-acer:/opt/img$du Test-raw.img-sh 0 test-raw.img Yang@yang-acer:/opt/img$du Test.qcow2-sh 196K Test.qcow2
|
According to the above results to speculate that the image of the QCOW2 format for creating the preconfigured metadata should be a reference to some of the features of the original RAW image file to speed up reading and writing optimization, the principle of raw, as in advance to empty data to occupy the space, rather than like the ordinary qcow2 format, on-demand increments. And above whether the raw format or qcow2 the way of pre-allocation metadata will not directly 1G of space completely occupied, to host the I node occupancy is also no effect, this can be created and deleted through the file Df-hl and df-i results to test.
Third, the document after the mirror contrast
The test result above is the contrast of the empty file, and after the same system is installed by default on the mirror, I again compare the three.
TEST-RAW.IMG: Original Raw mirror with CentOS 6 system installed on it
Test-centos.qcow2: For TEST-RAW.IMG, the IMG image after conversion via qemu-img convert-f raw-o qcow2 test-raw.img command
Centos.img: IMG For qcow2 format of pre-allocated metadata, and install CENTOS6 system on top of it
Results of Ls-l:
The code is as follows |
Copy Code |
yang@yang-acer:/opt$ LL -rw-r--r--1 root root 21478375424 May 18:03 centos.img -rw-r--r--1 root root 2004942848 May 18:25 test-centos.qcow2 -rw-r--r--1 root root 21474836480 May 18:12 test-raw.img
|
As was the case before the installation of the system, the Qcow2-format mirrored files in the pre-allocated metadata and mirrored files in RAW format are in the same size as the Test-centos.qcow2 ls-l and the actual du results. Because the size of the stat is consistent with the size of the ls-l, this is no longer listed.
Results of qemu-img Info:
code is as follows |
copy code |
yang@yang-acer:/opt$ qemu-img Info Test-centos.qcow2 Image:test-centos.qcow2 File Format:qcow2 Virtual size:20g (21474836480 bytes) Disk size:1.9g cluster_size:65536 Format Specific information: compat:1.1 Lazy Refcounts:false yang@yang-acer:/opt$ qemu-img Info test-raw.img Image:test-raw.img File Format:raw Virtual size:20g (21474836480 bytes) Disk size:2.3g yang@yang-acer:/opt$ qemu-img Info centos.img Image:centos.img File Format:qcow2 Virtual size:20g (21474836480 bytes) Disk size:2.3g cluster_size:65536 Format Specific information: compat:1.1 Lazy Refcounts:false
|
This gives the actual size and the size of the before, and after the system is installed, the QCOW2 format of the pre-allocated metadata is in the same size as the mirrored file in RAW format.
Results of the Du
The code is as follows |
Copy Code |
Yang@yang-acer:/opt$ du Test-centos.qcow2-sh 1.9G Test-centos.qcow2 Yang@yang-acer:/opt$ du Test-raw.img-sh 2.3G test-raw.img Yang@yang-acer:/opt$ du Centos.img-sh 2.4G centos.img
|
Iv. Summary
The above test results help to understand the following two advantages:
1, the use of pre-allocation, you can directly step through the KVM guest host QCOW2 Mirror format host installation, and do not need to be like before the conversion of the installed.
2, using the pre-allocation, can speed up the qcow2 format of the KVM guest host read and write speed (although the test results here does not involve specific speed test, said a bit far-fetched).
If you are interested, you can then perform a performance test on the basis of the third step above to verify the performance impact of the pre allocation.