{"id":411,"date":"2012-10-09T10:55:32","date_gmt":"2012-10-09T10:55:32","guid":{"rendered":""},"modified":"2013-02-17T13:38:02","modified_gmt":"2013-02-17T05:38:02","slug":"kvm%e8%99%9a%e6%8b%9f%e6%9c%ba%e5%bf%ab%e7%85%a7%e5%a4%87%e4%bb%bd","status":"publish","type":"post","link":"https:\/\/ybzx.vip\/wp\/?p=411","title":{"rendered":"KVM\u865a\u62df\u673a\u5feb\u7167\u5907\u4efd"},"content":{"rendered":"<p>\u4e00\u3002\u786e\u8ba4\u865a\u62df\u673a\u955c\u50cf\u6587\u4ef6\u683c\u5f0f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&amp;#91;root@WWW.ESOJOURN.ORG vps&amp;#93;# qemu-img info centos1.img\r\nimage: centos1.img\r\nfile format: raw\r\nvirtual size: 200G (214748364800 bytes)\r\ndisk size: 6.5G\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#x5B;root@WWW.ESOJOURN.ORG vps]# qemu-img info centos1.imgimage: centos1.imgfile format: rawvirtual size: 200G (214748364800 bytes)disk size: 6.5G<\/pre>\n<p>RAW\u683c\u5f0f\u662f\u6700\u539f\u59cb\u7684\u955c\u50cf\u683c\u5f0f\uff0c\u597d\u5904\u662f\u901f\u5ea6\u5feb\u3002\u4f46\u4e0d\u652f\u6301\u5f88\u591a\u65b0\u7684\u529f\u80fd\u3002\u73b0\u5728qcow2\u683c\u5f0f\u6548\u7387\u6709\u5f88\u5927\u63d0\u5347\u4e86\uff0c\u800c\u4e14\u8fd8\u652f\u6301\u4e00\u4e9b\u65b0\u7684\u529f\u80fd<br \/>\n1 \u66f4\u5c0f\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5373\u4f7f\u662f\u4e0d\u652f\u6301holes\u7684\u6587\u4ef6\u7cfb\u7edf\u4e5f\u53ef\u4ee5\uff08\u8fd9\u4e0bdu -h\u548cls -lh\u770b\u5230\u7684\u5c31\u4e00\u6837\u4e86\uff09<br \/>\n2 Copy-on-write support, where the image only represents changes made to an underlying disk image\uff08\u8fd9\u4e2a\u7279\u6027SUN ZFS\u8868\u73b0\u7684\u6dcb\u6f13\u5c3d\u81f4\uff09<br \/>\n3 \u652f\u6301\u591a\u4e2asnapshot\uff0c\u5bf9\u5386\u53f2snapshot\u8fdb\u884c\u7ba1\u7406<br \/>\n4 \u652f\u6301zlib\u7684\u78c1\u76d8\u538b\u7f29<br \/>\n5 \u652f\u6301AES\u7684\u52a0\u5bc6<\/p>\n<p>\u89c1<a href=\"http:\/\/dingxuan.info\/blog\/post\/vm-image-formats-raw-qcow2-vmdk-vdi.php\" target=\"_blank\">\u300aqcow2\u3001raw\u3001vmdk\u7b49\u955c\u50cf\u683c\u5f0f\u300b<\/a>\u5bf9\u6bd4\u3002<!--more--><\/p>\n<p>\u4e8c\u3002\u60f3\u8981\u542f\u7528\u5feb\u7167\u529f\u80fd\uff0c\u9700\u8981\u5148\u8f6c\u6362\u955c\u50cf\u6587\u4ef6\u683c\u5f0f\u4e3aqcow2\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;root@WWW.ESOJOURN.ORG vps]# virsh shutdown esojourn.org\r\n\u5148\u5173\u6389VM\r\n&#x5B;root@WWW.ESOJOURN.ORG vps]# qemu-img convert -f raw -O qcow2 centos1.img centos1qcow2.img\r\n\u8f6c\u6362\u683c\u5f0f\r\n<\/pre>\n<p>\u4e09\u3002\u5e38\u7528\u5feb\u7167\u547d\u4ee4<br \/>\n\u8fd9\u91cc\u6709\u4e00\u4efdlibvirt\u5b98\u65b9\u7684\u547d\u4ee4\u6587\u6863\u3002\u5b8c\u6574\uff0c\u4f46\u8bf4\u660e\u4e0d\u8be6\u7ec6\uff1ahttp:\/\/wiki.libvirt.org\/page\/VM_lifecycle<\/p>\n<p>\u5177\u4f53\u793a\u4f8b\uff1a<\/p>\n<p>1. \u5217\u51fa\u5feb\u7167\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#x5B;root@WWW.ESOJOURN.ORG vps]# virsh snapshot-list CentOS1\r\n Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Creation Time\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 State\r\n------------------------------------------------------------\r\n centos1.snap1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02012-10-08 17:25:11 +0800 running\r\n snap2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02012-10-08 17:33:14 +0800 running\r\n snap3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02012-10-08 17:57:21 +0800 running\r\n<\/pre>\n<p>2. \u521b\u5efa\u5feb\u7167<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">virsh snapshot-create-as CentOS1 snap2\r\nvirsh snapshot-create-as --domain CentOS1 --name snap2 --description &quot;URL: www.esojourn.org&quot;\r\n\r\n3. \u67e5\u770b\u5feb\u7167\u914d\u7f6e\r\nvirsh snapshot-current CentOS1\r\n4. \u6062\u590d\u5feb\u7167\r\nvirsh snapshot-revert CentOS1 snap2\r\n5. \u5220\u9664\u5feb\u7167\r\nbirsh snapshot-delete CentOS1 snap2\r\n6. \u83b7\u53d6\u5e2e\u52a9\r\nvirsh help snapshot\r\n<\/pre>\n<p>\u56db\u3002\u5173\u4e8eqemu-img snapshot -c\u548csavevm<br \/>\n\u5f88\u591a\u4e92\u76f8\u6284\u88ad\u7684\u6559\u7a0b\u91cc\uff0c\u90fd\u63d0\u5230\u4e86\u4f7f\u7528qemu-img snapshot -c\u7684\u547d\u4ee4\u6765\u521b\u5efa\u5feb\u7167\u3002\u4f46\u6211\u81ea\u5df1\u6d4b\u8bd5\u7684\u7ed3\u679c \uff0c\u4e0d\u7ba1\u865a\u62df\u673a\u662f\u8fd0\u884c\u4e2d\uff0c\u8fd8\u662f\u5173\u95ed\u72b6\u6001\uff0c\u8fd9\u4e2a\u547d\u4ee4\u521b\u5efa\u7684\u5feb\u7167\u5b57\u8282\u90fd\u662f0\u3002\u4e5f\u5c31\u662f\u8bf4\u4ec0\u4e48\u4e5f\u6ca1\u4fdd\u5b58\u4e0b\u6765\u3002\u5bf9\u6b64\uff0c\u6211\u8fd8\u6ca1\u6709\u627e\u5230\u539f\u56e0\u3002\u4f46\u627e\u5230Red hat\u5458\u5de5Kashyap Chamarthy\u7684\u4e00\u7bc7\u6587\u7ae0\u3002\u6587\u7ae0\u91cc\u63d0\u5230virsh\u5728\u4e0d\u540c\u60c5\u51b5\u4e0b\uff0c\u4f1a\u8c03\u7528\u4e0d\u540c\u65b9\u5f0f\u6765\u4fdd\u5b58\u5feb\u7167\u3002\u5176\u4e2d\u81f3\u5c11\u5305\u62ec\u2018qemu-img snapshot -c\u2018\uff0cqemu\u7684 \u2018savevm\u2018\u548cqemu\u7684 \u2018snapshot_blkdev\u2018\u8fd9\u4e09\u79cd\u65b9\u5f0f\u3002\u6240\u4ee5\u770b\u8d77\u6765\u5feb\u7167\u4fdd\u5b58\uff0c\u8fd8\u662f\u4f7f\u7528virsh snapshot-create\u7684\u65b9\u5f0f\u6bd4\u8f83\u597d\u3002<\/p>\n<p>\u539f\u6587\u5f15\u7528<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nAlso, discussed with Eric, in what cases does virsh invoke Qemu\u2019s \u2018savevm\u2018 and \u2018qemu-img snapshot -c\u2018 commands while creating different types of snapshots discussed earlier above. Here is the outline:\r\n\r\n- it uses \u2018qemu-img snapshot -c\u2018 if the domain is offline and \u2013disk-only was not specified\r\n- it uses qemu\u2019s \u2018savevm\u2018 if the domain is online and \u2013disk-only was not specified\r\n- it uses qemu\u2019s \u2018snapshot_blkdev\u2018 if the domain is online and \u2013disk-only is specified\r\n\r\n<blockquote class=\"wp-embedded-content\" data-secret=\"HmZ40TJ72c\"><a href=\"https:\/\/kashyapc.wordpress.com\/2011\/10\/04\/snapshotting-with-libvirt-for-qcow2-images\/\">Snapshotting with libvirt for qcow2&nbsp;images<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;Snapshotting with libvirt for qcow2&nbsp;images&#8221; &#8212; Kashyap Chamarthy\" src=\"https:\/\/kashyapc.wordpress.com\/2011\/10\/04\/snapshotting-with-libvirt-for-qcow2-images\/embed\/#?secret=fqUCmQPeVM#?secret=HmZ40TJ72c\" data-secret=\"HmZ40TJ72c\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\r\n<\/pre>\n<p>qemu-img snapshot\u76f8\u5173\u547d\u4ee4\u683c\u5f0f\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">qemu-img snapshot -c snap1 centos1-qcow2.img\r\n\r\nqemu-img\u00a0\u00a0snapshot -l centos1-qcow2.img\r\n\r\nSnapshot list:\r\nID\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TAG\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 VM SIZE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0DATE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 VM CLOCK\r\n1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 snap1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a00\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02011-07-21 23:17:38\u00a0\u00a0 00:00:00.000\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6062\u590d\u5feb\u7167\uff1a\r\nqemu-img\u00a0\u00a0snapshot\u00a0\u00a0 -a\u00a0\u00a0 CentOS5.5_64bit_Qcow2_basesys.img\u00a0\u00a0\u00a0\u00a0CentOS5.5_64bit_Qcow2.img\r\n\r\n\u5176\u4ed6\u64cd\u4f5c\uff1a\r\n'snapshot' is the name of the snapshot to create, apply or delete\r\n'-a' applies a snapshot (revert disk to saved state)\r\n'-c' creates a snapshot\r\n'-d' deletes a snapshot\r\n'-l' lists all snapshots in the given image<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3002\u786e\u8ba4\u865a\u62df\u673a\u955c\u50cf\u6587\u4ef6\u683c\u5f0f &amp;#91;root@WWW.ESOJOURN.ORG vps&amp;#9 &hellip; <a href=\"https:\/\/ybzx.vip\/wp\/?p=411\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">KVM\u865a\u62df\u673a\u5feb\u7167\u5907\u4efd<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[78,112],"class_list":["post-411","post","type-post","status-publish","format-standard","hentry","category-network","tag-linux","tag-vm"],"_links":{"self":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=411"}],"version-history":[{"count":0,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/posts\/411\/revisions"}],"wp:attachment":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}