1QEMU-IMG(1) QEMU-IMG(1)
2
3
4
6 qemu-img - QEMU disk image utility
7
9 usage: qemu-img command [command options]
10
12 qemu-img allows you to create, convert and modify images offline. It
13 can handle all image formats supported by QEMU.
14
15 Warning: Never use qemu-img to modify images in use by a running
16 virtual machine or any other process; this may destroy the image. Also,
17 be aware that querying an image that is being modified by another
18 process may encounter inconsistent state.
19
21 The following commands are supported:
22
23 check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache]
24 filename
25 create [-q] [-f fmt] [-o options] filename [size]
26 commit [-q] [-f fmt] [-t cache] filename
27 compare [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1
28 filename2
29 convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O
30 output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename
31 [filename2 [...]] output_filename
32 info [-f fmt] [--output=ofmt] [--backing-chain] filename
33 map [-f fmt] [--output=ofmt] filename
34 snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename
35 rebase [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b
36 backing_file [-F backing_fmt] filename
37 resize [-q] filename [+ | -]size
38 amend [-q] [-f fmt] [-t cache] -o options filename
39
40 Command parameters:
41
42 filename
43 is a disk image filename
44
45 fmt is the disk image format. It is guessed automatically in most
46 cases. See below for a description of the supported disk formats.
47
48 --backing-chain
49 will enumerate information about backing files in a disk image
50 chain. Refer below for further description.
51
52 size
53 is the disk image size in bytes. Optional suffixes "k" or "K"
54 (kilobyte, 1024) "M" (megabyte, 1024k) and "G" (gigabyte, 1024M)
55 and T (terabyte, 1024G) are supported. "b" is ignored.
56
57 output_filename
58 is the destination disk image filename
59
60 output_fmt
61 is the destination format
62
63 options
64 is a comma separated list of format specific options in a
65 name=value format. Use "-o ?" for an overview of the options
66 supported by the used format or see the format descriptions below
67 for details.
68
69 -c indicates that target image must be compressed (qcow format only)
70
71 -h with or without a command shows help and lists the supported
72 formats
73
74 -p display progress bar (compare, convert and rebase commands only).
75 If the -p option is not used for a command that supports it, the
76 progress is reported when the process receives a "SIGUSR1" signal.
77
78 -q Quiet mode - do not print any output (except errors). There's no
79 progress bar in case both -q and -p options are used.
80
81 -S size
82 indicates the consecutive number of bytes that must contain only
83 zeros for qemu-img to create a sparse image during conversion. This
84 value is rounded down to the nearest 512 bytes. You may use the
85 common size suffixes like "k" for kilobytes.
86
87 -t cache
88 specifies the cache mode that should be used with the (destination)
89 file. See the documentation of the emulator's "-drive cache=..."
90 option for allowed values.
91
92 -T src_cache
93 specifies the cache mode that should be used with the source
94 file(s). See the documentation of the emulator's "-drive cache=..."
95 option for allowed values.
96
97 Parameters to snapshot subcommand:
98
99 snapshot
100 is the name of the snapshot to create, apply or delete
101
102 -a applies a snapshot (revert disk to saved state)
103
104 -c creates a snapshot
105
106 -d deletes a snapshot
107
108 -l lists all snapshots in the given image
109
110 Parameters to compare subcommand:
111
112 -f First image format
113
114 -F Second image format
115
116 -s Strict mode - fail on on different image size or sector allocation
117
118 Parameters to convert subcommand:
119
120 -n Skip the creation of the target volume
121
122 Command description:
123
124 check [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache]
125 filename
126 Perform a consistency check on the disk image filename. The command
127 can output in the format ofmt which is either "human" or "json".
128
129 If "-r" is specified, qemu-img tries to repair any inconsistencies
130 found during the check. "-r leaks" repairs only cluster leaks,
131 whereas "-r all" fixes all kinds of errors, with a higher risk of
132 choosing the wrong fix or hiding corruption that has already
133 occurred.
134
135 Only the formats "qcow2", "qed" and "vdi" support consistency
136 checks.
137
138 create [-f fmt] [-o options] filename [size]
139 Create the new disk image filename of size size and format fmt.
140 Depending on the file format, you can add one or more options that
141 enable additional features of this format.
142
143 If the option backing_file is specified, then the image will record
144 only the differences from backing_file. No size needs to be
145 specified in this case. backing_file will never be modified unless
146 you use the "commit" monitor command (or qemu-img commit).
147
148 The size can also be specified using the size option with "-o", it
149 doesn't need to be specified separately in this case.
150
151 commit [-f fmt] [-t cache] filename
152 Commit the changes recorded in filename in its base image or
153 backing file. If the backing file is smaller than the snapshot,
154 then the backing file will be resized to be the same size as the
155 snapshot. If the snapshot is smaller than the backing file, the
156 backing file will not be truncated. If you want the backing file
157 to match the size of the smaller snapshot, you can safely truncate
158 it yourself once the commit operation successfully completes.
159
160 compare [-f fmt] [-F fmt] [-T src_cache] [-p] [-s] [-q] filename1
161 filename2
162 Check if two images have the same content. You can compare images
163 with different format or settings.
164
165 The format is probed unless you specify it by -f (used for
166 filename1) and/or -F (used for filename2) option.
167
168 By default, images with different size are considered identical if
169 the larger image contains only unallocated and/or zeroed sectors in
170 the area after the end of the other image. In addition, if any
171 sector is not allocated in one image and contains only zero bytes
172 in the second one, it is evaluated as equal. You can use Strict
173 mode by specifying the -s option. When compare runs in Strict mode,
174 it fails in case image size differs or a sector is allocated in one
175 image and is not allocated in the second one.
176
177 By default, compare prints out a result message. This message
178 displays information that both images are same or the position of
179 the first different byte. In addition, result message can report
180 different image size in case Strict mode is used.
181
182 Compare exits with 0 in case the images are equal and with 1 in
183 case the images differ. Other exit codes mean an error occurred
184 during execution and standard error output should contain an error
185 message. The following table sumarizes all exit codes of the
186 compare subcommand:
187
188 0 Images are identical
189
190 1 Images differ
191
192 2 Error on opening an image
193
194 3 Error on checking a sector allocation
195
196 4 Error on reading data
197
198 convert [-c] [-p] [-n] [-f fmt] [-t cache] [-T src_cache] [-O
199 output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename
200 [filename2 [...]] output_filename
201 Convert the disk image filename or a snapshot snapshot_name to disk
202 image output_filename using format output_fmt. It can be optionally
203 compressed ("-c" option) or use any format specific options like
204 encryption ("-o" option).
205
206 Only the formats "qcow" and "qcow2" support compression. The
207 compression is read-only. It means that if a compressed sector is
208 rewritten, then it is rewritten as uncompressed data.
209
210 Image conversion is also useful to get smaller image when using a
211 growable format such as "qcow": the empty sectors are detected and
212 suppressed from the destination image.
213
214 sparse_size indicates the consecutive number of bytes (defaults to
215 4k) that must contain only zeros for qemu-img to create a sparse
216 image during conversion. If sparse_size is 0, the source will not
217 be scanned for unallocated or zero sectors, and the destination
218 image will always be fully allocated.
219
220 You can use the backing_file option to force the output image to be
221 created as a copy on write image of the specified base image; the
222 backing_file should have the same content as the input's base
223 image, however the path, image format, etc may differ.
224
225 If the "-n" option is specified, the target volume creation will be
226 skipped. This is useful for formats such as "rbd" if the target
227 volume has already been created with site specific options that
228 cannot be supplied through qemu-img.
229
230 info [-f fmt] [--output=ofmt] [--backing-chain] filename
231 Give information about the disk image filename. Use it in
232 particular to know the size reserved on disk which can be different
233 from the displayed size. If VM snapshots are stored in the disk
234 image, they are displayed too. The command can output in the format
235 ofmt which is either "human" or "json".
236
237 If a disk image has a backing file chain, information about each
238 disk image in the chain can be recursively enumerated by using the
239 option "--backing-chain".
240
241 For instance, if you have an image chain like:
242
243 base.qcow2 <- snap1.qcow2 <- snap2.qcow2
244
245 To enumerate information about each disk image in the above chain,
246 starting from top to base, do:
247
248 qemu-img info --backing-chain snap2.qcow2
249
250 map [-f fmt] [--output=ofmt] filename
251 Dump the metadata of image filename and its backing file chain. In
252 particular, this commands dumps the allocation state of every
253 sector of filename, together with the topmost file that allocates
254 it in the backing file chain.
255
256 Two option formats are possible. The default format ("human") only
257 dumps known-nonzero areas of the file. Known-zero parts of the
258 file are omitted altogether, and likewise for parts that are not
259 allocated throughout the chain. qemu-img output will identify a
260 file from where the data can be read, and the offset in the file.
261 Each line will include four fields, the first three of which are
262 hexadecimal numbers. For example the first line of:
263
264 Offset Length Mapped to File
265 0 0x20000 0x50000 /tmp/overlay.qcow2
266 0x100000 0x10000 0x95380000 /tmp/backing.qcow2
267
268 means that 0x20000 (131072) bytes starting at offset 0 in the image
269 are available in /tmp/overlay.qcow2 (opened in "raw" format)
270 starting at offset 0x50000 (327680). Data that is compressed,
271 encrypted, or otherwise not available in raw format will cause an
272 error if "human" format is in use. Note that file names can
273 include newlines, thus it is not safe to parse this output format
274 in scripts.
275
276 The alternative format "json" will return an array of dictionaries
277 in JSON format. It will include similar information in the
278 "start", "length", "offset" fields; it will also include other more
279 specific information:
280
281 - whether the sectors contain actual data or not (boolean field
282 "data"; if false, the sectors are either unallocated or stored
283 as optimized all-zero clusters);
284
285 - whether the data is known to read as zero (boolean field
286 "zero");
287
288 - in order to make the output shorter, the target file is
289 expressed as a "depth"; for example, a depth of 2 refers to the
290 backing file of the backing file of filename.
291
292 In JSON format, the "offset" field is optional; it is absent in
293 cases where "human" format would omit the entry or exit with an
294 error. If "data" is false and the "offset" field is present, the
295 corresponding sectors in the file are not yet in use, but they are
296 preallocated.
297
298 For more information, consult include/block/block.h in QEMU's
299 source code.
300
301 snapshot [-l | -a snapshot | -c snapshot | -d snapshot ] filename
302 List, apply, create or delete snapshots in image filename.
303
304 rebase [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F
305 backing_fmt] filename
306 Changes the backing file of an image. Only the formats "qcow2" and
307 "qed" support changing the backing file.
308
309 The backing file is changed to backing_file and (if the image
310 format of filename supports this) the backing file format is
311 changed to backing_fmt. If backing_file is specified as "" (the
312 empty string), then the image is rebased onto no backing file (i.e.
313 it will exist independently of any backing file).
314
315 cache specifies the cache mode to be used for filename, whereas
316 src_cache specifies the cache mode for reading backing files.
317
318 There are two different modes in which "rebase" can operate:
319
320 Safe mode
321 This is the default mode and performs a real rebase operation.
322 The new backing file may differ from the old one and qemu-img
323 rebase will take care of keeping the guest-visible content of
324 filename unchanged.
325
326 In order to achieve this, any clusters that differ between
327 backing_file and the old backing file of filename are merged
328 into filename before actually changing the backing file.
329
330 Note that the safe mode is an expensive operation, comparable
331 to converting an image. It only works if the old backing file
332 still exists.
333
334 Unsafe mode
335 qemu-img uses the unsafe mode if "-u" is specified. In this
336 mode, only the backing file name and format of filename is
337 changed without any checks on the file contents. The user must
338 take care of specifying the correct new backing file, or the
339 guest-visible content of the image will be corrupted.
340
341 This mode is useful for renaming or moving the backing file to
342 somewhere else. It can be used without an accessible old
343 backing file, i.e. you can use it to fix an image whose backing
344 file has already been moved/renamed.
345
346 You can use "rebase" to perform a "diff" operation on two disk
347 images. This can be useful when you have copied or cloned a guest,
348 and you want to get back to a thin image on top of a template or
349 base image.
350
351 Say that "base.img" has been cloned as "modified.img" by copying
352 it, and that the "modified.img" guest has run so there are now some
353 changes compared to "base.img". To construct a thin image called
354 "diff.qcow2" that contains just the differences, do:
355
356 qemu-img create -f qcow2 -b modified.img diff.qcow2
357 qemu-img rebase -b base.img diff.qcow2
358
359 At this point, "modified.img" can be discarded, since "base.img +
360 diff.qcow2" contains the same information.
361
362 resize filename [+ | -]size
363 Change the disk image as if it had been created with size.
364
365 Before using this command to shrink a disk image, you MUST use file
366 system and partitioning tools inside the VM to reduce allocated
367 file systems and partition sizes accordingly. Failure to do so
368 will result in data loss!
369
370 After using this command to grow a disk image, you must use file
371 system and partitioning tools inside the VM to actually begin using
372 the new space on the device.
373
374 amend [-f fmt] [-t cache] -o options filename
375 Amends the image format specific options for the image file
376 filename. Not all file formats support this operation.
377
379 Supported image file formats:
380
381 raw Raw disk image format (default). This format has the advantage of
382 being simple and easily exportable to all other emulators. If your
383 file system supports holes (for example in ext2 or ext3 on Linux or
384 NTFS on Windows), then only the written sectors will reserve space.
385 Use "qemu-img info" to know the real size used by the image or "ls
386 -ls" on Unix/Linux.
387
388 Supported options:
389
390 "preallocation"
391 Preallocation mode (allowed values: "off", "falloc", "full").
392 "falloc" mode preallocates space for image by calling
393 posix_fallocate(). "full" mode preallocates space for image by
394 writing zeros to underlying storage.
395
396 qcow2
397 QEMU image format, the most versatile format. Use it to have
398 smaller images (useful if your filesystem does not supports holes,
399 for example on Windows), optional AES encryption, zlib based
400 compression and support of multiple VM snapshots.
401
402 Supported options:
403
404 "compat"
405 Determines the qcow2 version to use. "compat=0.10" uses the
406 traditional image format that can be read by any QEMU since
407 0.10. "compat=1.1" enables image format extensions that only
408 QEMU 1.1 and newer understand (this is the default). Amongst
409 others, this includes zero clusters, which allow efficient
410 copy-on-read for sparse images.
411
412 "backing_file"
413 File name of a base image (see create subcommand)
414
415 "backing_fmt"
416 Image format of the base image
417
418 "encryption"
419 If this option is set to "on", the image is encrypted.
420
421 Encryption uses the AES format which is very secure (128 bit
422 keys). Use a long password (16 characters) to get maximum
423 protection.
424
425 "cluster_size"
426 Changes the qcow2 cluster size (must be between 512 and 2M).
427 Smaller cluster sizes can improve the image file size whereas
428 larger cluster sizes generally provide better performance.
429
430 "preallocation"
431 Preallocation mode (allowed values: "off", "metadata",
432 "falloc", "full"). An image with preallocated metadata is
433 initially larger but can improve performance when the image
434 needs to grow. "falloc" and "full" preallocations are like the
435 same options of "raw" format, but sets up metadata also.
436
437 "lazy_refcounts"
438 If this option is set to "on", reference count updates are
439 postponed with the goal of avoiding metadata I/O and improving
440 performance. This is particularly interesting with
441 cache=writethrough which doesn't batch metadata updates. The
442 tradeoff is that after a host crash, the reference count tables
443 must be rebuilt, i.e. on the next open an (automatic) "qemu-img
444 check -r all" is required, which may take some time.
445
446 This option can only be enabled if "compat=1.1" is specified.
447
448 Other
449 QEMU also supports various other image file formats for
450 compatibility with older QEMU versions or other hypervisors,
451 including VMDK, VDI, VHD (vpc), VHDX, qcow1 and QED. For a full
452 list of supported formats see "qemu-img --help". For a more
453 detailed description of these formats, see the QEMU Emulation User
454 Documentation.
455
456 The main purpose of the block drivers for these formats is image
457 conversion. For running VMs, it is recommended to convert the disk
458 images to either raw or qcow2 in order to achieve good performance.
459
461 The HTML documentation of QEMU for more precise information and Linux
462 user mode emulator invocation.
463
465 Fabrice Bellard
466
467
468
469 2019-05-14 QEMU-IMG(1)