1QEMU-IMG(1)                          QEMU                          QEMU-IMG(1)
2
3
4

NAME

6       qemu-img - QEMU disk image utility
7

SYNOPSIS

9       qemu-img [standard options] command [command options]
10

DESCRIPTION

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  vir‐
16       tual machine or any other process; this may destroy the image. Also, be
17       aware that querying an image that is being modified by another  process
18       may encounter inconsistent state.
19

OPTIONS

21       Standard options:
22
23       -h, --help
24              Display this help and exit
25
26       -V, --version
27              Display version information and exit
28
29       -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE]
30              Specify tracing options.
31
32              [enable=]PATTERN
33                     Immediately  enable events matching PATTERN (either event
34                     name or a globbing pattern).  This option is only  avail‐
35                     able  if  QEMU  has been compiled with the simple, log or
36                     ftrace tracing backend.  To specify  multiple  events  or
37                     patterns, specify the -trace option multiple times.
38
39                     Use -trace help to print a list of names of trace points.
40
41              events=FILE
42                     Immediately  enable events listed in FILE.  The file must
43                     contain one event name (as listed in the trace-events-all
44                     file) per line; globbing patterns are accepted too.  This
45                     option is only available if QEMU has been  compiled  with
46                     the simple, log or ftrace tracing backend.
47
48              file=FILE
49                     Log output traces to FILE.  This option is only available
50                     if QEMU has been compiled with the simple  tracing  back‐
51                     end.
52
53       The following commands are supported:
54
55       amend [--object OBJECTDEF] [--image-opts] [-p] [-q] [-f FMT] [-t CACHE]
56       [--force] -o OPTIONS FILENAME
57
58       bench [-c COUNT] [-d DEPTH] [-f FMT]  [--flush-interval=FLUSH_INTERVAL]
59       [-i  AIO]  [-n]  [--no-drain]  [-o OFFSET] [--pattern=PATTERN] [-q] [-s
60       BUFFER_SIZE] [-S STEP_SIZE] [-t CACHE] [-w] [-U] FILENAME
61
62       bitmap (--merge SOURCE | --add | --remove | --clear | --enable | --dis‐
63       able)...  [-b  SOURCE_FILE  [-F SOURCE_FMT]] [-g GRANULARITY] [--object
64       OBJECTDEF] [--image-opts | -f FMT] FILENAME BITMAP
65
66       check [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [--output=OFMT]
67       [-r [leaks | all]] [-T SRC_CACHE] [-U] FILENAME
68
69       commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b
70       BASE] [-d] [-p] FILENAME
71
72       compare [--object OBJECTDEF]  [--image-opts]  [-f  FMT]  [-F  FMT]  [-T
73       SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2
74
75       convert   [--object   OBJECTDEF]  [--image-opts]  [--target-image-opts]
76       [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n]  [-f  FMT]
77       [-t  CACHE]  [-T  SRC_CACHE]  [-O  OUTPUT_FMT]  [-B  BACKING_FILE]  [-o
78       OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES]  [-W]
79       [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME
80
81       create  [--object  OBJECTDEF] [-q] [-f FMT] [-b BACKING_FILE] [-F BACK‐
82       ING_FMT] [-u] [-o OPTIONS] FILENAME [SIZE]
83
84       dd  [--image-opts]  [-U]  [-f  FMT]  [-O  OUTPUT_FMT]   [bs=BLOCK_SIZE]
85       [count=BLOCKS] [skip=BLOCKS] if=INPUT of=OUTPUT
86
87       info  [--object  OBJECTDEF]  [--image-opts]  [-f  FMT]  [--output=OFMT]
88       [--backing-chain] [-U] FILENAME
89
90       map [--object OBJECTDEF] [--image-opts] [-f  FMT]  [--start-offset=OFF‐
91       SET] [--max-length=LEN] [--output=OFMT] [-U] FILENAME
92
93       measure  [--output=OFMT]  [-O  OUTPUT_FMT]  [-o  OPTIONS]  [--size  N |
94       [--object OBJECTDEF] [--image-opts] [-f FMT] [-l SNAPSHOT_PARAM]  FILE‐
95       NAME]
96
97       snapshot  [--object  OBJECTDEF] [--image-opts] [-U] [-q] [-l | -a SNAP‐
98       SHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME
99
100       rebase [--object OBJECTDEF]  [--image-opts]  [-U]  [-q]  [-f  FMT]  [-t
101       CACHE]  [-T SRC_CACHE] [-p] [-u] -b BACKING_FILE [-F BACKING_FMT] FILE‐
102       NAME
103
104       resize  [--object  OBJECTDEF]  [--image-opts]  [-f  FMT]  [--prealloca‐
105       tion=PREALLOC] [-q] [--shrink] FILENAME [+ | -]SIZE
106
107       Command parameters:
108
109       FILENAME is a disk image filename.
110
111       FMT  is  the  disk  image  format.  It is guessed automatically in most
112       cases. See below for a description of the supported disk formats.
113
114       SIZE is the disk image size in bytes. Optional suffixes k or  K  (kilo‐
115       byte,  1024)  M  (megabyte,  1024k) and G (gigabyte, 1024M) and T (ter‐
116       abyte, 1024G) are supported.  b is ignored.
117
118       OUTPUT_FILENAME is the destination disk image filename.
119
120       OUTPUT_FMT is the destination format.
121
122       OPTIONS is a comma separated list  of  format  specific  options  in  a
123       name=value format. Use -o ? for an overview of the options supported by
124       the used format or see the format descriptions below for details.
125
126       SNAPSHOT_PARAM is param used for internal snapshot,  format  is  'snap‐
127       shot.id=[ID],snapshot.name=[NAME]' or '[ID_OR_NAME]'.
128
129       --object OBJECTDEF
130              is a QEMU user creatable object definition. See the qemu(1) man‐
131              ual page for a description of the object  properties.  The  most
132              common  object  type  is a secret, which is used to supply pass‐
133              words and/or encryption keys.
134
135       --image-opts
136              Indicates that the source FILENAME parameter  is  to  be  inter‐
137              preted  as  a  full  option  string,  not a plain filename. This
138              parameter is mutually exclusive with the -f parameter.
139
140       --target-image-opts
141              Indicates that the OUTPUT_FILENAME parameter(s) are to be inter‐
142              preted  as  a  full  option  string,  not a plain filename. This
143              parameter is mutually exclusive with the -O  parameters.  It  is
144              currently  required  to  also use the -n parameter to skip image
145              creation. This restriction may be relaxed in a future release.
146
147       --force-share (-U)
148              If specified, qemu-img will  open  the  image  in  shared  mode,
149              allowing  other  QEMU  processes  to  open it in write mode. For
150              example, this can be used to get  the  image  information  (with
151              'info'  subcommand)  when  the image is used by a running guest.
152              Note that this could produce  inconsistent  results  because  of
153              concurrent  metadata  changes,  etc. This option is only allowed
154              when opening images in read-only mode.
155
156       --backing-chain
157              Will enumerate information about backing files in a  disk  image
158              chain. Refer below for further description.
159
160       -c     Indicates  that  target  image  must  be compressed (qcow format
161              only).
162
163       -h     With or without a command, shows help and  lists  the  supported
164              formats.
165
166       -p     Display  progress  bar  (compare,  convert  and  rebase commands
167              only).  If the -p option is not used for a command that supports
168              it, the progress is reported when the process receives a SIGUSR1
169              or SIGINFO signal.
170
171       -q     Quiet mode - do not print any output (except errors). There's no
172              progress bar in case both -q and -p options are used.
173
174       -S SIZE
175              Indicates the consecutive number of bytes that must contain only
176              zeros for qemu-img to create a sparse image  during  conversion.
177              This value is rounded down to the nearest 512 bytes. You may use
178              the common size suffixes like k for kilobytes.
179
180       -t CACHE
181              Specifies the cache mode that should be used with the  (destina‐
182              tion)  file.  See  the  documentation  of  the emulator's -drive
183              cache=... option for allowed values.
184
185       -T SRC_CACHE
186              Specifies the cache mode that should be  used  with  the  source
187              file(s).   See   the  documentation  of  the  emulator's  -drive
188              cache=... option for allowed values.
189
190       Parameters to compare subcommand:
191
192       -f     First image format
193
194       -F     Second image format
195
196       -s     Strict mode - fail on different image size or sector allocation
197
198       Parameters to convert subcommand:
199
200       --bitmaps
201              Additionally copy all persistent bitmaps from the top  layer  of
202              the source
203
204       -n     Skip the creation of the target volume
205
206       -m     Number of parallel coroutines for the convert process
207
208       -W     Allow  out-of-order  writes  to  the  destination.  This  option
209              improves performance, but is only recommended  for  preallocated
210              devices like host devices or other raw block devices.
211
212       -C     Try  to  use  copy  offloading to move data from source image to
213              target. This may improve performance if the data is remote, such
214              as  with NFS or iSCSI backends, but will not automatically spar‐
215              sify zero sectors, and may result in a  fully  allocated  target
216              image  depending  on  the  host  support  for getting allocation
217              information.
218
219       --salvage
220              Try to ignore I/O errors when reading.   Unless  in  quiet  mode
221              (-q),  errors  will still be printed.  Areas that cannot be read
222              from the source will be treated as containing only zeroes.
223
224       --target-is-zero
225              Assume that reading the destination  image  will  always  return
226              zeros.  This  parameter is mutually exclusive with a destination
227              image that has a backing file. It is required to also use the -n
228              parameter to skip image creation.
229
230       Parameters to dd subcommand:
231
232       bs=BLOCK_SIZE
233              Defines the block size
234
235       count=BLOCKS
236              Sets the number of input blocks to copy
237
238       if=INPUT
239              Sets the input file
240
241       of=OUTPUT
242              Sets the output file
243
244       skip=BLOCKS
245              Sets the number of input blocks to skip
246
247       Parameters to snapshot subcommand:
248
249       snapshot
250              Is the name of the snapshot to create, apply or delete
251
252       -a     Applies a snapshot (revert disk to saved state)
253
254       -c     Creates a snapshot
255
256       -d     Deletes a snapshot
257
258       -l     Lists all snapshots in the given image
259
260       Command description:
261
262       amend [--object OBJECTDEF] [--image-opts] [-p] [-q] [-f FMT] [-t CACHE]
263       [--force] -o OPTIONS FILENAME
264              Amends the image format specific  OPTIONS  for  the  image  file
265              FILENAME. Not all file formats support this operation.
266
267              The  set  of  options  that  can be amended are dependent on the
268              image format, but note that amending the backing chain relation‐
269              ship should instead be performed with qemu-img rebase.
270
271              --force allows some unsafe operations. Currently for -f luks, it
272              allows to erase the last encryption key,  and  to  overwrite  an
273              active encryption key.
274
275       bench  [-c COUNT] [-d DEPTH] [-f FMT] [--flush-interval=FLUSH_INTERVAL]
276       [-i AIO] [-n] [--no-drain] [-o  OFFSET]  [--pattern=PATTERN]  [-q]  [-s
277       BUFFER_SIZE] [-S STEP_SIZE] [-t CACHE] [-w] [-U] FILENAME
278              Run a simple sequential I/O benchmark on the specified image. If
279              -w is specified, a write test is  performed,  otherwise  a  read
280              test is performed.
281
282              A  total  number  of  COUNT I/O requests is performed, each BUF‐
283              FER_SIZE bytes in size, and with DEPTH requests in parallel. The
284              first  request starts at the position given by OFFSET, each fol‐
285              lowing request increases the current position by  STEP_SIZE.  If
286              STEP_SIZE is not given, BUFFER_SIZE is used for its value.
287
288              If  FLUSH_INTERVAL  is  specified  for a write test, the request
289              queue is drained and a flush is issued  before  new  writes  are
290              made  whenever the number of remaining requests is a multiple of
291              FLUSH_INTERVAL. If additionally --no-drain is specified, a flush
292              is issued without draining the request queue first.
293
294              if  -i is specified, AIO option can be used to specify different
295              AIO backends: threads, native or io_uring.
296
297              If -n is specified, the native AIO backend is used if  possible.
298              On  Linux, this option only works if -t none or -t directsync is
299              specified as well.
300
301              For write tests, by default a buffer filled with zeros is  writ‐
302              ten.  This  can  be  overridden with a pattern byte specified by
303              PATTERN.
304
305       bitmap (--merge SOURCE | --add | --remove | --clear | --enable | --dis‐
306       able)...  [-b  SOURCE_FILE  [-F SOURCE_FMT]] [-g GRANULARITY] [--object
307       OBJECTDEF] [--image-opts | -f FMT] FILENAME BITMAP
308              Perform one or more modifications of the persistent bitmap  BIT‐
309              MAP in the disk image FILENAME.  The various modifications are:
310
311              --add to create BITMAP, enabled to record future edits.
312
313              --remove to remove BITMAP.
314
315              --clear to clear BITMAP.
316
317              --enable to change BITMAP to start recording future edits.
318
319              --disable to change BITMAP to stop recording future edits.
320
321              --merge to merge the contents of the SOURCE bitmap into BITMAP.
322
323              Additional options include -g which sets a non-default GRANULAR‐
324              ITY for --add, and -b and -F which select an alternative  source
325              file for all SOURCE bitmaps used by --merge.
326
327              To see what bitmaps are present in an image, use qemu-img info.
328
329       check [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [--output=OFMT]
330       [-r [leaks | all]] [-T SRC_CACHE] [-U] FILENAME
331              Perform a consistency check on the disk image FILENAME. The com‐
332              mand  can  output  in  the  format OFMT which is either human or
333              json.  The JSON output is an object of QAPI type ImageCheck.
334
335              If -r is specified, qemu-img tries to repair any inconsistencies
336              found  during  the  check.  -r leaks repairs only cluster leaks,
337              whereas -r all fixes all kinds of errors, with a higher risk  of
338              choosing  the  wrong  fix  or hiding corruption that has already
339              occurred.
340
341              Only the formats qcow2, qed and vdi support consistency checks.
342
343              In case the image does not have any inconsistencies, check exits
344              with  0.   Other  exit  codes indicate the kind of inconsistency
345              found or if another error occurred. The following  table  summa‐
346              rizes all exit codes of the check subcommand:
347
348              0      Check completed, the image is (now) consistent
349
350              1      Check not completed because of internal errors
351
352              2      Check completed, image is corrupted
353
354              3      Check  completed,  image  has leaked clusters, but is not
355                     corrupted
356
357              63     Checks are not supported by the image format
358
359              If -r is specified, exit  codes  representing  the  image  state
360              refer to the state after (the attempt at) repairing it. That is,
361              a successful -r all will yield the exit code 0, independently of
362              the image state before.
363
364       commit [--object OBJECTDEF] [--image-opts] [-q] [-f FMT] [-t CACHE] [-b
365       BASE] [-d] [-p] FILENAME
366              Commit the changes recorded in FILENAME in  its  base  image  or
367              backing file.  If the backing file is smaller than the snapshot,
368              then the backing file will be resized to be the same size as the
369              snapshot.  If the snapshot is smaller than the backing file, the
370              backing file will not be truncated.  If  you  want  the  backing
371              file  to  match the size of the smaller snapshot, you can safely
372              truncate it yourself once the commit operation successfully com‐
373              pletes.
374
375              The image FILENAME is emptied after the operation has succeeded.
376              If you do not need FILENAME afterwards and intend  to  drop  it,
377              you may skip emptying FILENAME by specifying the -d flag.
378
379              If  the  backing chain of the given image file FILENAME has more
380              than one layer, the backing file into which the changes will  be
381              committed  may  be  specified  as  BASE (which has to be part of
382              FILENAME's backing chain). If BASE is not specified, the immedi‐
383              ate  backing  file  of the top image (which is FILENAME) will be
384              used. Note that after a commit operation all images between BASE
385              and  the  top  image will be invalid and may return garbage data
386              when read. For this reason, -b implies -d (so that the top image
387              stays valid).
388
389       compare  [--object  OBJECTDEF]  [--image-opts]  [-f  FMT]  [-F FMT] [-T
390       SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2
391              Check if two images have  the  same  content.  You  can  compare
392              images with different format or settings.
393
394              The format is probed unless you specify it by -f (used for FILE‐
395              NAME1) and/or -F (used for FILENAME2) option.
396
397              By default, images with different size are considered  identical
398              if the larger image contains only unallocated and/or zeroed sec‐
399              tors in the area after the end of the other image. In  addition,
400              if  any  sector  is not allocated in one image and contains only
401              zero bytes in the second one, it is evaluated as equal. You  can
402              use  Strict  mode by specifying the -s option. When compare runs
403              in Strict mode, it fails in case image size differs or a  sector
404              is  allocated  in  one  image and is not allocated in the second
405              one.
406
407              By default, compare prints out a result  message.  This  message
408              displays  information  that both images are same or the position
409              of the first different byte. In  addition,  result  message  can
410              report different image size in case Strict mode is used.
411
412              Compare  exits with 0 in case the images are equal and with 1 in
413              case the images differ. Other exit codes mean an error  occurred
414              during  execution  and  standard  error output should contain an
415              error message.  The following table sumarizes all exit codes  of
416              the compare subcommand:
417
418              0      Images are identical
419
420              1      Images differ
421
422              2      Error on opening an image
423
424              3      Error on checking a sector allocation
425
426              4      Error on reading data
427
428       convert   [--object   OBJECTDEF]  [--image-opts]  [--target-image-opts]
429       [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n]  [-f  FMT]
430       [-t  CACHE]  [-T  SRC_CACHE]  [-O  OUTPUT_FMT]  [-B  BACKING_FILE]  [-o
431       OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-m NUM_COROUTINES]  [-W]
432       FILENAME [FILENAME2 [...]] OUTPUT_FILENAME
433              Convert  the disk image FILENAME or a snapshot SNAPSHOT_PARAM to
434              disk image OUTPUT_FILENAME using format OUTPUT_FMT.  It  can  be
435              optionally  compressed  (-c  option)  or use any format specific
436              options like encryption (-o option).
437
438              Only the formats qcow and qcow2 support  compression.  The  com‐
439              pression  is  read-only. It means that if a compressed sector is
440              rewritten, then it is rewritten as uncompressed data.
441
442              Image conversion is also useful to get smaller image when  using
443              a  growable  format such as qcow: the empty sectors are detected
444              and suppressed from the destination image.
445
446              SPARSE_SIZE indicates the consecutive number of bytes  (defaults
447              to  4k)  that  must  contain only zeros for qemu-img to create a
448              sparse image during conversion. If SPARSE_SIZE is 0, the  source
449              will  not  be  scanned  for unallocated or zero sectors, and the
450              destination image will always be fully allocated.
451
452              You can use the BACKING_FILE option to force the output image to
453              be created as a copy on write image of the specified base image;
454              the BACKING_FILE should have the same  content  as  the  input's
455              base image, however the path, image format, etc may differ.
456
457              If  a relative path name is given, the backing file is looked up
458              relative to the directory containing OUTPUT_FILENAME.
459
460              If the -n option is specified, the target volume  creation  will
461              be skipped. This is useful for formats such as rbd if the target
462              volume has already been created with site specific options  that
463              cannot be supplied through qemu-img.
464
465              Out  of  order  writes can be enabled with -W to improve perfor‐
466              mance.  This is only recommended for preallocated  devices  like
467              host devices or other raw block devices. Out of order write does
468              not work in combination with creating compressed images.
469
470              NUM_COROUTINES specifies how many coroutines  work  in  parallel
471              during the convert process (defaults to 8).
472
473       create  [--object  OBJECTDEF] [-q] [-f FMT] [-b BACKING_FILE] [-F BACK‐
474       ING_FMT] [-u] [-o OPTIONS] FILENAME [SIZE]
475              Create the new disk image FILENAME of size SIZE and format  FMT.
476              Depending  on  the  file format, you can add one or more OPTIONS
477              that enable additional features of this format.
478
479              If the option BACKING_FILE is specified,  then  the  image  will
480              record  only the differences from BACKING_FILE. No size needs to
481              be specified in this case. BACKING_FILE will never  be  modified
482              unless you use the commit monitor command (or qemu-img commit).
483
484              If  a relative path name is given, the backing file is looked up
485              relative to the directory containing FILENAME.
486
487              Note that a given backing file will be opened to check  that  it
488              is  valid. Use the -u option to enable unsafe backing file mode,
489              which means that the image will be created even if  the  associ‐
490              ated backing file cannot be opened. A matching backing file must
491              be created or additional options be used  to  make  the  backing
492              file  specification  valid when you want to use an image created
493              this way.
494
495              The size can also be specified using the SIZE option with -o, it
496              doesn't need to be specified separately in this case.
497
498       dd   [--image-opts]  [-U]  [-f  FMT]  [-O  OUTPUT_FMT]  [bs=BLOCK_SIZE]
499       [count=BLOCKS] [skip=BLOCKS] if=INPUT of=OUTPUT
500              dd copies from INPUT file to OUTPUT file converting it from  FMT
501              format to OUTPUT_FMT format.
502
503              The  data  is  by  default  read and written using blocks of 512
504              bytes  but  can  be  modified  by  specifying   BLOCK_SIZE.   If
505              count=BLOCKS is specified dd will stop reading input after read‐
506              ing BLOCKS input blocks.
507
508              The size syntax is similar to dd(1)'s size syntax.
509
510       info  [--object  OBJECTDEF]  [--image-opts]  [-f  FMT]  [--output=OFMT]
511       [--backing-chain] [-U] FILENAME
512              Give  information  about the disk image FILENAME. Use it in par‐
513              ticular to know the size reserved on disk which can be different
514              from  the displayed size. If VM snapshots are stored in the disk
515              image, they are displayed too.
516
517              If a disk image has a backing file chain, information about each
518              disk  image  in the chain can be recursively enumerated by using
519              the option --backing-chain.
520
521              For instance, if you have an image chain like:
522
523                 base.qcow2 <- snap1.qcow2 <- snap2.qcow2
524
525              To enumerate information about each  disk  image  in  the  above
526              chain, starting from top to base, do:
527
528                 qemu-img info --backing-chain snap2.qcow2
529
530              The  command can output in the format OFMT which is either human
531              or json.  The JSON output is an object of QAPI  type  ImageInfo;
532              with --backing-chain, it is an array of ImageInfo objects.
533
534              --output=human  reports  the  following  information  (for every
535              image in the chain):
536
537              image  The image file name
538
539              file format
540                     The image format
541
542              virtual size
543                     The size of the guest disk
544
545              disk size
546                     How much space the image file occupies on the  host  file
547                     system (may be shown as 0 if this information is unavail‐
548                     able, e.g. because there is no file system)
549
550              cluster_size
551                     Cluster size of the image format, if applicable
552
553              encrypted
554                     Whether the image is encrypted (only present if so)
555
556              cleanly shut down
557                     This is shown as no if the image is dirty and  will  have
558                     to be auto-repaired the next time it is opened in qemu.
559
560              backing file
561                     The backing file name, if present
562
563              backing file format
564                     The format of the backing file, if the image enforces it
565
566              Snapshot list
567                     A list of all internal snapshots
568
569              Format specific information
570                     Further  information whose structure depends on the image
571                     format.  This section is a textual representation of  the
572                     respective  ImageInfoSpecific* QAPI object (e.g. ImageIn‐
573                     foSpecificQCow2 for qcow2 images).
574
575       map [--object OBJECTDEF] [--image-opts] [-f  FMT]  [--start-offset=OFF‐
576       SET] [--max-length=LEN] [--output=OFMT] [-U] FILENAME
577              Dump  the metadata of image FILENAME and its backing file chain.
578              In particular, this commands dumps the allocation state of every
579              sector  of  FILENAME,  together with the topmost file that allo‐
580              cates it in the backing file chain.
581
582              Two option formats are possible.   The  default  format  (human)
583              only dumps known-nonzero areas of the file.  Known-zero parts of
584              the file are omitted altogether, and likewise for parts that are
585              not  allocated throughout the chain.  qemu-img output will iden‐
586              tify a file from where the data can be read, and the  offset  in
587              the  file.   Each line will include four fields, the first three
588              of which are hexadecimal numbers.  For example  the  first  line
589              of:
590
591                 Offset          Length          Mapped to       File
592                 0               0x20000         0x50000         /tmp/overlay.qcow2
593                 0x100000        0x10000         0x95380000      /tmp/backing.qcow2
594
595              means  that  0x20000  (131072) bytes starting at offset 0 in the
596              image are available in /tmp/overlay.qcow2 (opened in raw format)
597              starting  at  offset 0x50000 (327680).  Data that is compressed,
598              encrypted, or otherwise not available in raw format  will  cause
599              an  error  if  human format is in use.  Note that file names can
600              include newlines, thus it is not safe to parse this output  for‐
601              mat in scripts.
602
603              The alternative format json will return an array of dictionaries
604              in JSON format.  It will  include  similar  information  in  the
605              start,  length,  offset  fields; it will also include other more
606              specific information:
607
608              · whether the sectors contain actual data or not (boolean  field
609                data;  if  false, the sectors are either unallocated or stored
610                as optimized all-zero clusters);
611
612              · whether the data is known  to  read  as  zero  (boolean  field
613                zero);
614
615              · in  order  to  make  the  output  shorter,  the target file is
616                expressed as a depth; for example, a depth of 2 refers to  the
617                backing file of the backing file of FILENAME.
618
619              In  JSON  format,  the offset field is optional; it is absent in
620              cases where human format would omit the entry or  exit  with  an
621              error.   If  data  is false and the offset field is present, the
622              corresponding sectors in the file are not yet in use,  but  they
623              are preallocated.
624
625              For  more  information,  consult include/block/block.h in QEMU's
626              source code.
627
628       measure [--output=OFMT]  [-O  OUTPUT_FMT]  [-o  OPTIONS]  [--size  N  |
629       [--object  OBJECTDEF] [--image-opts] [-f FMT] [-l SNAPSHOT_PARAM] FILE‐
630       NAME]
631              Calculate the file size required for a new image.  This informa‐
632              tion  can  be used to size logical volumes or SAN LUNs appropri‐
633              ately for the image that will be placed  in  them.   The  values
634              reported  are  guaranteed  to  be large enough to fit the image.
635              The command can output in the format OFMT which is either  human
636              or  json.   The  JSON output is an object of QAPI type BlockMea‐
637              sureInfo.
638
639              If the size N is given then act as if creating a new empty image
640              file using qemu-img create.  If FILENAME is given then act as if
641              converting an existing image file using qemu-img  convert.   The
642              format  of  the new file is given by OUTPUT_FMT while the format
643              of an existing file is given by FMT.
644
645              A snapshot in an existing image can  be  specified  using  SNAP‐
646              SHOT_PARAM.
647
648              The following fields are reported:
649
650                 required size: 524288
651                 fully allocated size: 1074069504
652                 bitmaps size: 0
653
654              The  required size is the file size of the new image.  It may be
655              smaller than the virtual disk size if the image format  supports
656              compact representation.
657
658              The  fully allocated size is the file size of the new image once
659              data has been written to all sectors.  This is the maximum  size
660              that  the  image  file can occupy with the exception of internal
661              snapshots, dirty bitmaps, vmstate data, and other advanced image
662              format features.
663
664              The  bitmaps  size  is  the additional size required in order to
665              copy bitmaps from a source image in addition to the  guest-visi‐
666              ble  data;  the  line is omitted if either source or destination
667              lacks bitmap support, or 0 if bitmaps are supported but there is
668              nothing to copy.
669
670       snapshot  [--object  OBJECTDEF] [--image-opts] [-U] [-q] [-l | -a SNAP‐
671       SHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME
672              List, apply, create or delete snapshots in image FILENAME.
673
674       rebase [--object OBJECTDEF]  [--image-opts]  [-U]  [-q]  [-f  FMT]  [-t
675       CACHE]  [-T SRC_CACHE] [-p] [-u] -b BACKING_FILE [-F BACKING_FMT] FILE‐
676       NAME
677              Changes the backing file of an image. Only the formats qcow2 and
678              qed support changing the backing file.
679
680              The  backing  file  is changed to BACKING_FILE and (if the image
681              format of FILENAME supports this) the  backing  file  format  is
682              changed  to BACKING_FMT. If BACKING_FILE is specified as "" (the
683              empty string), then the image is rebased onto  no  backing  file
684              (i.e. it will exist independently of any backing file).
685
686              If  a relative path name is given, the backing file is looked up
687              relative to the directory containing FILENAME.
688
689              CACHE specifies the cache mode to be used for FILENAME,  whereas
690              SRC_CACHE specifies the cache mode for reading backing files.
691
692              There are two different modes in which rebase can operate:
693
694              Safe mode
695                     This is the default mode and performs a real rebase oper‐
696                     ation. The new backing file may differ from the  old  one
697                     and  qemu-img  rebase  will  take  care  of  keeping  the
698                     guest-visible content of FILENAME unchanged.
699
700                     In order  to  achieve  this,  any  clusters  that  differ
701                     between BACKING_FILE and the old backing file of FILENAME
702                     are merged into FILENAME  before  actually  changing  the
703                     backing file.
704
705                     Note that the safe mode is an expensive operation, compa‐
706                     rable to converting an image. It only works  if  the  old
707                     backing file still exists.
708
709              Unsafe mode
710                     qemu-img uses the unsafe mode if -u is specified. In this
711                     mode, only the backing file name and format  of  FILENAME
712                     is  changed  without any checks on the file contents. The
713                     user must take care of specifying the correct new backing
714                     file,  or  the guest-visible content of the image will be
715                     corrupted.
716
717                     This mode is useful for renaming or  moving  the  backing
718                     file to somewhere else.  It can be used without an acces‐
719                     sible old backing file, i.e. you can use  it  to  fix  an
720                     image whose backing file has already been moved/renamed.
721
722              You  can  use  rebase  to perform a "diff" operation on two disk
723              images.  This can be useful when you have  copied  or  cloned  a
724              guest, and you want to get back to a thin image on top of a tem‐
725              plate or base image.
726
727              Say that base.img has been cloned as modified.img by copying it,
728              and  that  the  modified.img guest has run so there are now some
729              changes compared to base.img.  To construct a thin image  called
730              diff.qcow2 that contains just the differences, do:
731
732                 qemu-img create -f qcow2 -b modified.img diff.qcow2
733                 qemu-img rebase -b base.img diff.qcow2
734
735              At  this  point, modified.img can be discarded, since base.img +
736              diff.qcow2 contains the same information.
737
738       resize  [--object  OBJECTDEF]  [--image-opts]  [-f  FMT]  [--prealloca‐
739       tion=PREALLOC] [-q] [--shrink] FILENAME [+ | -]SIZE
740              Change the disk image as if it had been created with SIZE.
741
742              Before  using  this command to shrink a disk image, you MUST use
743              file system and partitioning tools inside the VM to reduce allo‐
744              cated  file systems and partition sizes accordingly.  Failure to
745              do so will result in data loss!
746
747              When shrinking images, the --shrink option must be  given.  This
748              informs  qemu-img  that  the  user acknowledges all loss of data
749              beyond the truncated image's end.
750
751              After using this command to grow a disk image, you must use file
752              system  and  partitioning  tools inside the VM to actually begin
753              using the new space on the device.
754
755              When growing an image, the --preallocation option may be used to
756              specify how the additional image area should be allocated on the
757              host.  See the format description in  the  Notes  section  which
758              values  are  allowed.   Using this option may result in slightly
759              more data being allocated than necessary.
760

NOTES

762       Supported image file formats:
763
764       raw
765          Raw disk image format (default). This format has  the  advantage  of
766          being  simple  and easily exportable to all other emulators. If your
767          file system supports holes (for example in ext2 or ext3 on Linux  or
768          NTFS  on Windows), then only the written sectors will reserve space.
769          Use qemu-img info to know the real size used by the image or ls  -ls
770          on Unix/Linux.
771
772          Supported options:
773
774          preallocation
775                 Preallocation mode (allowed values: off, falloc, full).  fal‐
776                 loc mode preallocates space for image by calling posix_fallo‐
777                 cate().   full  mode  preallocates space for image by writing
778                 data to underlying storage.  This data  may  or  may  not  be
779                 zero, depending on the storage location.
780
781       qcow2
782          QEMU image format, the most versatile format. Use it to have smaller
783          images (useful if your filesystem does not supports holes, for exam‐
784          ple on Windows), optional AES encryption, zlib based compression and
785          support of multiple VM snapshots.
786
787          Supported options:
788
789          compat Determines the qcow2 version to  use.  compat=0.10  uses  the
790                 traditional  image  format that can be read by any QEMU since
791                 0.10.  compat=1.1 enables image format extensions  that  only
792                 QEMU  1.1 and newer understand (this is the default). Amongst
793                 others, this includes zero clusters,  which  allow  efficient
794                 copy-on-read for sparse images.
795
796          backing_file
797                 File name of a base image (see create subcommand)
798
799          backing_fmt
800                 Image format of the base image
801
802          encryption
803                 If  this  option  is  set  to on, the image is encrypted with
804                 128-bit AES-CBC.
805
806                 The use of encryption in qcow and qcow2 images is  considered
807                 to be flawed by modern cryptography standards, suffering from
808                 a number of design problems:
809
810                 · The AES-CBC cipher is used with predictable  initialization
811                   vectors  based on the sector number. This makes it vulnera‐
812                   ble to chosen plaintext attacks which can reveal the  exis‐
813                   tence of encrypted data.
814
815                 · The user passphrase is directly used as the encryption key.
816                   A poorly chosen or short  passphrase  will  compromise  the
817                   security of the encryption.
818
819                 · In  the  event of the passphrase being compromised there is
820                   no way to change the passphrase to protect data in any qcow
821                   images. The files must be cloned, using a different encryp‐
822                   tion passphrase in the new file.  The  original  file  must
823                   then  be securely erased using a program like shred, though
824                   even this is ineffective with many modern storage technolo‐
825                   gies.
826
827                 · Initialization vectors used to encrypt sectors are based on
828                   the guest virtual sector number, instead of the host physi‐
829                   cal  sector.  When a disk image has multiple internal snap‐
830                   shots this means that data in multiple physical sectors  is
831                   encrypted with the same initialization vector. With the CBC
832                   mode, this opens the possibility of watermarking attacks if
833                   the  attack can collect multiple sectors encrypted with the
834                   same IV and some predictable data.  Having  multiple  qcow2
835                   images  with the same passphrase also exposes this weakness
836                   since the passphrase is directly used as the key.
837
838                 Use of qcow / qcow2 encryption is thus strongly  discouraged.
839                 Users  are recommended to use an alternative encryption tech‐
840                 nology such as the Linux dm-crypt / LUKS system.
841
842          cluster_size
843                 Changes the qcow2 cluster size (must be between 512 and  2M).
844                 Smaller cluster sizes can improve the image file size whereas
845                 larger cluster sizes generally provide better performance.
846
847          preallocation
848                 Preallocation mode (allowed values:  off,  metadata,  falloc,
849                 full).  An  image  with  preallocated  metadata  is initially
850                 larger but can improve performance when the  image  needs  to
851                 grow.  falloc  and  full  preallocations  are  like  the same
852                 options of raw format, but sets up metadata also.
853
854          lazy_refcounts
855                 If this option is set to  on,  reference  count  updates  are
856                 postponed  with the goal of avoiding metadata I/O and improv‐
857                 ing  performance.  This  is  particularly  interesting   with
858                 cache=writethrough  which doesn't batch metadata updates. The
859                 tradeoff is that after a  host  crash,  the  reference  count
860                 tables  must be rebuilt, i.e. on the next open an (automatic)
861                 qemu-img check -r all is required, which may take some time.
862
863                 This option can only be enabled if compat=1.1 is specified.
864
865          nocow  If this option is set to on, it will  turn  off  COW  of  the
866                 file.  It's only valid on btrfs, no effect on other file sys‐
867                 tems.
868
869                 Btrfs has low performance when hosting a VM image file,  even
870                 more  when  the guest on the VM also using btrfs as file sys‐
871                 tem. Turning off COW is a way to mitigate  this  bad  perfor‐
872                 mance. Generally there are two ways to turn off COW on btrfs:
873
874                 · Disable  it by mounting with nodatacow, then all newly cre‐
875                   ated files will be NOCOW
876
877                 · For an empty file, add the  NOCOW  file  attribute.  That's
878                   what this option does.
879
880                 Note:  this  option  is  only valid to new or empty files. If
881                 there is an existing file which is COW and  has  data  blocks
882                 already, it couldn't be changed to NOCOW by setting nocow=on.
883                 One can issue lsattr filename to check if the NOCOW  flag  is
884                 set or not (Capital 'C' is NOCOW flag).
885
886       Other
887          QEMU  also supports various other image file formats for compatibil‐
888          ity with older QEMU versions or other hypervisors,  including  VMDK,
889          VDI,  VHD  (vpc),  VHDX, qcow1 and QED. For a full list of supported
890          formats see qemu-img --help.  For a  more  detailed  description  of
891          these formats, see the QEMU block drivers reference documentation.
892
893          The  main  purpose  of  the block drivers for these formats is image
894          conversion.  For running VMs, it is recommended to convert the  disk
895          images to either raw or qcow2 in order to achieve good performance.
896

AUTHOR

898       Fabrice Bellard
899
901       2021, The QEMU Project Developers
902
903
904
905
9065.1.0                            Jan 11, 2021                      QEMU-IMG(1)
Impressum