{"id":285,"date":"2018-03-13T10:19:03","date_gmt":"2018-03-13T02:19:03","guid":{"rendered":"http:\/\/www.max-shu.com\/blog\/?p=285"},"modified":"2018-03-13T10:19:03","modified_gmt":"2018-03-13T02:19:03","slug":"qemu-img%e4%bd%bf%e7%94%a8%e5%b8%ae%e5%8a%a9","status":"publish","type":"post","link":"http:\/\/www.max-shu.com\/blog\/?p=285","title":{"rendered":"qemu-img\u4f7f\u7528\u5e2e\u52a9"},"content":{"rendered":"<div><b><span style=\"color: #ff0000;\">\u4f8b\u5b50\uff1a<\/span><\/b><\/div>\n<div># qemu-img info f16-x86_64-openstack-sda.qcow2<br \/>\nimage: f16-x86_64-openstack-sda.qcow2<br \/>\nfile format: qcow2<br \/>\nvirtual size:\u00a0<span style=\"color: #8600a4;\">9.8G<\/span>\u00a0(10486808576 bytes)<br \/>\ndisk size:\u00a0<span style=\"color: #ff0000;\">204M<\/span><br \/>\ncluster_size: 65536<\/div>\n<div><\/div>\n<div>\n<h1>qemu-img(1) &#8211; Linux man page<\/h1>\n<h2>Name<\/h2>\n<p>qemu-img\u00a0&#8211;\u00a0QEMU\u00a0disk image utility<\/p>\n<h2>Synopsis<\/h2>\n<p>usage:\u00a0qemu-img\u00a0command [command options]<\/p>\n<h2>Options<\/h2>\n<p>The following commands are supported:<\/p>\n<dl compact=\"compact\">\n<dt><b>check [-f<\/b>\u00a0<i>fmt<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dt><b>create [-f<\/b>\u00a0<i>fmt<\/i><b>] [-o<\/b>\u00a0<i>options<\/i><b>]<\/b>\u00a0<i>filename<\/i>\u00a0<b>[<\/b><i>size<\/i><b>]<\/b><\/dt>\n<dt><b>commit [-f<\/b>\u00a0<i>fmt<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dt><b>convert [-c] [-f<\/b>\u00a0<i>fmt<\/i><b>] [-O<\/b>\u00a0<i>output_fmt<\/i><b>] [-o<\/b>\u00a0<i>options<\/i><b>]<\/b>\u00a0<i>filename<\/i>\u00a0<b>[<\/b><i>filename2<\/i>\u00a0<b>[&#8230;]]<\/b>\u00a0<i>output_filename<\/i><\/dt>\n<dt><b>info\u00a0[-f<\/b>\u00a0<i>fmt<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dt><b>snapshot [-l | -a<\/b>\u00a0<i>snapshot<\/i>\u00a0<b>| -c<\/b>\u00a0<i>snapshot<\/i>\u00a0<b>| -d<\/b>\u00a0<i>snapshot<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dt><b>rebase [-f<\/b>\u00a0<i>fmt<\/i><b>] [-u] -b<\/b>\u00a0<i>backing_file<\/i>\u00a0<b>[-F<\/b>\u00a0<i>backing_fmt<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dt><b>resize<\/b>\u00a0<i>filename<\/i>\u00a0<b>[+ | -]<\/b><i>size<\/i><\/dt>\n<dt>Command parameters:<\/dt>\n<dt><i>filename<\/i><\/dt>\n<dd>\n<pre>is a disk image filename<\/pre>\n<\/dd>\n<dt><i>fmt<\/i><br \/>\nis the disk image format. It is guessed automatically in most cases. See below for a description of the supported disk formats.<\/dt>\n<dt><i>size<\/i><\/dt>\n<dd>is the disk image size in bytes. Optional suffixes\u00a0<tt>\"k\"<\/tt>\u00a0or\u00a0<tt>\"K\"<\/tt>\u00a0(kilobyte, 1024)\u00a0<tt>\"M\"<\/tt>\u00a0(megabyte, 1024k) and\u00a0<tt>\"G\"<\/tt>\u00a0(gigabyte, 1024M) and T (terabyte, 1024G) are supported.\u00a0<tt>\"b\"<\/tt>\u00a0is ignored.<\/dd>\n<dt><i>output_filename<\/i><\/dt>\n<dd>is the destination disk image filename<\/dd>\n<dt><i>output_fmt<\/i><\/dt>\n<dd>\n<pre>is the destination format<\/pre>\n<\/dd>\n<dt><i>options<\/i><\/dt>\n<dd>is a comma separated list of format specific options in a name=value format. Use\u00a0<tt>\"-o ?\"<\/tt>\u00a0for an overview of the options supported by the used format or see the format descriptions below for details.<\/dd>\n<dt><i>-c<\/i><br \/>\nindicates that target image must be compressed (qcow format only)<\/p>\n<p><i>-h<\/i><\/p>\n<p>with or without a command shows help and lists the supported formats<\/dt>\n<dt>Parameters to snapshot subcommand:<\/dt>\n<dt><b>snapshot<\/b><\/dt>\n<dd>is the name of the snapshot to create, apply or delete<\/dd>\n<dt><b>-a<\/b><br \/>\napplies a snapshot (revert disk to saved state)<\/p>\n<p><b>-c<\/b><\/p>\n<p>creates a snapshot<\/p>\n<p><b>-d<\/b><\/p>\n<p>deletes a snapshot<\/p>\n<p><b>-l<\/b><\/p>\n<p>lists all snapshots in the given image<\/dt>\n<dt>Command description:<\/dt>\n<dt><b>create [-f<\/b>\u00a0<i>fmt<\/i><b>] [-o<\/b>\u00a0<i>options<\/i><b>]<\/b>\u00a0<i>filename<\/i>\u00a0<b>[<\/b><i>size<\/i><b>]<\/b><\/dt>\n<dd>Create the new disk image\u00a0<i>filename<\/i>\u00a0of size\u00a0<i>size<\/i>\u00a0and format\u00a0<i>fmt<\/i>. Depending on the file format, you can add one or more\u00a0<i>options<\/i>\u00a0that enable additional features of this format.If the option\u00a0<i>backing_file<\/i>\u00a0is specified, then the image will record only the differences from\u00a0<i>backing_file<\/i>. No size needs to be specified in this case.\u00a0<i>backing_file<\/i>\u00a0will never be modified unless you use the\u00a0<tt>\"commit\"<\/tt>\u00a0monitor command (or\u00a0qemu-img\u00a0commit).<\/p>\n<p>The size can also be specified using the\u00a0<i>size<\/i>\u00a0option with\u00a0<tt>\"-o\"<\/tt>, it doesn&#8217;t need to be specified separately in this case.<\/dd>\n<dt><b>commit [-f<\/b>\u00a0<i>fmt<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dd>Commit the changes recorded in\u00a0<i>filename<\/i>\u00a0in its base image.<\/dd>\n<dt><b>convert [-c] [-f<\/b>\u00a0<i>fmt<\/i><b>] [-O<\/b>\u00a0<i>output_fmt<\/i><b>] [-o<\/b>\u00a0<i>options<\/i><b>]<\/b>\u00a0<i>filename<\/i>\u00a0<b>[<\/b><i>filename2<\/i>\u00a0<b>[&#8230;]]<\/b>\u00a0<i>output_filename<\/i><\/dt>\n<dd>Convert the disk image\u00a0<i>filename<\/i>\u00a0to disk image\u00a0<i>output_filename<\/i>\u00a0using format\u00a0<i>output_fmt<\/i>. It can be optionally compressed (<tt>\"-c\"<\/tt>\u00a0option) or use any format specific options like encryption (<tt>\"-o\"<\/tt>\u00a0option).Only the formats\u00a0<tt>\"qcow\"<\/tt>\u00a0and\u00a0<tt>\"qcow2\"<\/tt>\u00a0support compression. The compression is read-only. It means that if a compressed sector is rewritten, then it is rewritten as uncompressed data.<\/p>\n<p>Image conversion is also useful to get smaller image when using a growable format such as\u00a0<tt>\"qcow\"<\/tt>\u00a0or\u00a0<tt>\"cow\"<\/tt>: the empty sectors are detected and suppressed from the destination image.<\/p>\n<p>You can use the\u00a0<i>backing_file<\/i>\u00a0option to force the output image to be created as a copy on write image of the specified base image; the\u00a0<i>backing_file<\/i>\u00a0should have the same content as the input&#8217;s base image, however the path, image format, etc may differ.<\/dd>\n<dt><b>info\u00a0[-f<\/b>\u00a0<i>fmt<\/i><b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dd>Give information about the disk image\u00a0<i>filename<\/i>. Use it in particular to know the size reserved on disk which can be different from the displayed size. If\u00a0<small>VM<\/small>\u00a0snapshots are stored in the disk image, they are displayed too.<\/dd>\n<dt><b>snapshot [-l | -a<\/b>\u00a0<i>snapshot<\/i>\u00a0<b>| -c<\/b>\u00a0<i>snapshot<\/i>\u00a0<b>| -d<\/b>\u00a0<i>snapshot<\/i>\u00a0<b>]<\/b>\u00a0<i>filename<\/i><\/dt>\n<dd>List, apply, create or delete snapshots in image\u00a0<i>filename<\/i>.<\/dd>\n<dt><b>resize<\/b>\u00a0<i>filename<\/i>\u00a0<b>[+ | -]<\/b><i>size<\/i><\/dt>\n<dd>Change the disk image as if it had been created with\u00a0<i>size<\/i>.Before using this command to shrink a disk image, you\u00a0<small>MUST<\/small>\u00a0use file system and partitioning tools inside the\u00a0<small>VM<\/small>\u00a0to reduce allocated file systems and partition sizes accordingly. Failure to do so will result in data loss!<\/p>\n<p>After using this command to grow a disk image, you must use file system and partitioning tools inside the\u00a0<small>VM<\/small>\u00a0to actually begin using the new space on the device.<\/dd>\n<dt>Supported image file formats:<\/dt>\n<dt><b>raw<\/b><br \/>\nRaw disk image format (default). This format has the advantage of being simple and easily exportable to all other emulators. If your file system supports\u00a0<i>holes<\/i>\u00a0(for example in ext2 or ext3 on Linux or\u00a0<small>NTFS<\/small>\u00a0on Windows), then only the written sectors will reserve space. Use\u00a0<tt>\"qemu-img\u00a0info\"<\/tt>\u00a0to know the real size used by the image or\u00a0<tt>\"ls -ls\"<\/tt>\u00a0on Unix\/Linux.<\/dt>\n<dt><b>host_device<\/b><\/dt>\n<dd>Host device format. This format should be used instead of raw when converting to block devices or other devices where &#8220;holes&#8221; are not supported.<\/dd>\n<dt><b>qcow2<\/b><\/dt>\n<dd><small>QEMU<\/small>\u00a0image format, the most versatile format. Use it to have smaller images (useful if your filesystem does not supports holes, for example on Windows), optional\u00a0<small>AES<\/small>\u00a0encryption, zlib based compression and support of multiple\u00a0<small>VM<\/small>\u00a0snapshots.Supported options:<\/dd>\n<dd>&#8220;backing_file&#8221;<\/dd>\n<dd>File name of a base image (see\u00a0<b>create<\/b>\u00a0subcommand)<\/dd>\n<dd>&#8220;backing_fmt&#8221;<\/dd>\n<dd>Image format of the base image<\/dd>\n<dd>&#8220;encryption&#8221;<\/dd>\n<dd>If this option is set to\u00a0<tt>\"on\"<\/tt>, the image is encrypted.Encryption uses the\u00a0<small>AES<\/small>\u00a0format which is very secure (128 bit keys). Use a long password (16 characters) to get maximum protection.<\/dd>\n<dd>&#8220;cluster_size&#8221;<\/dd>\n<dd>Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster sizes can improve the image file size whereas larger cluster sizes generally provide better performance.<\/dd>\n<dd>&#8220;preallocation&#8221;<\/dd>\n<dd>Preallocation mode (allowed values: off, metadata). An image with preallocated metadata is initially larger but can improve performance when the image needs to grow.<\/dd>\n<dt><b>qcow<\/b><\/dt>\n<dd>Old\u00a0<small>QEMU<\/small>\u00a0image format. Left for compatibility.Supported options:<\/dd>\n<dd>&#8220;backing_file&#8221;<\/dd>\n<dd>File name of a base image (see\u00a0<b>create<\/b>\u00a0subcommand)<\/dd>\n<dd>&#8220;encryption&#8221;<\/dd>\n<dd>If this option is set to\u00a0<tt>\"on\"<\/tt>, the image is encrypted.<\/dd>\n<dt><b>cow<\/b><br \/>\nUser Mode Linux Copy On Write image format. Used to be the only growable image format in\u00a0<small>QEMU<\/small>\u00a0. It is supported only for compatibility with previous versions. It does not work on win32.<\/p>\n<p><b>vdi<\/b><\/p>\n<p>VirtualBox 1.1 compatible image format.<\/dt>\n<dt><b>vmdk<\/b><\/dt>\n<dd>VMware 3 and 4 compatible image format.Supported options:<\/dd>\n<dd>&#8220;backing_fmt&#8221;<\/dd>\n<dd>Image format of the base image<\/dd>\n<dd>&#8220;compat6&#8221;<\/dd>\n<dd>Create a\u00a0<small>VMDK<\/small>\u00a0version 6 image (instead of version 4)<\/dd>\n<dt><b>vpc<\/b><br \/>\nVirtualPC compatible image format (\u00a0<small>VHD<\/small>\u00a0).<\/dt>\n<dt><b>cloop<\/b><\/dt>\n<dd>Linux Compressed Loop image, useful only to reuse directly compressed CD-ROM images present for example in the Knoppix CD-ROMs.<\/dd>\n<\/dl>\n<h2>See Also<\/h2>\n<p>The\u00a0<small>HTML<\/small>\u00a0documentation of\u00a0<small>QEMU<\/small>\u00a0for more precise information and Linux user mode emulator invocation.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f8b\u5b50\uff1a # qemu-img info f16-x86_64-openstack-sda.qcow2 imag &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[227,218,228,229,151],"class_list":["post-285","post","type-post","status-publish","format-standard","hentry","category-4","tag-img","tag-qemu","tag-qemu-img","tag-229","tag-151"],"views":2107,"_links":{"self":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=285"}],"version-history":[{"count":1,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":286,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/285\/revisions\/286"}],"wp:attachment":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}