1QEMU-BLOCK-DRIVERS(7) QEMU QEMU-BLOCK-DRIVERS(7)
2
3
4
6 qemu-block-drivers - QEMU block drivers reference
7
9 QEMU block driver reference manual
10
12 Disk image file formats
13 QEMU supports many image file formats that can be used with VMs as well
14 as with any of the tools (like qemu-img). This includes the preferred
15 formats raw and qcow2 as well as formats that are supported for compat‐
16 ibility with older QEMU versions or other hypervisors.
17
18 Depending on the image format, different options can be passed to
19 qemu-img create and qemu-img convert using the -o option. This section
20 describes each format and the options that are supported for it.
21
22 raw Raw disk image format. This format has the advantage of being
23 simple and easily exportable to all other emulators. If your
24 file system supports holes (for example in ext2 or ext3 on Linux
25 or NTFS on Windows), then only the written sectors will reserve
26 space. Use qemu-img info to know the real size used by the image
27 or ls -ls on Unix/Linux.
28
29 Supported options:
30
31 preallocation
32 Preallocation mode (allowed values: off, falloc, full).
33 falloc mode preallocates space for image by calling
34 posix_fallocate(). full mode preallocates space for image
35 by writing data to underlying storage. This data may or
36 may not be zero, depending on the storage location.
37
38 qcow2 QEMU image format, the most versatile format. Use it to have
39 smaller images (useful if your filesystem does not supports
40 holes, for example on Windows), zlib based compression and sup‐
41 port of multiple VM snapshots.
42
43 Supported options:
44
45 compat Determines the qcow2 version to use. compat=0.10 uses the
46 traditional image format that can be read by any QEMU
47 since 0.10. compat=1.1 enables image format extensions
48 that only QEMU 1.1 and newer understand (this is the de‐
49 fault). Amongst others, this includes zero clusters,
50 which allow efficient copy-on-read for sparse images.
51
52 backing_file
53 File name of a base image (see create subcommand)
54
55 backing_fmt
56 Image format of the base image
57
58 encryption
59 This option is deprecated and equivalent to encrypt.for‐
60 mat=aes
61
62 encrypt.format
63 If this is set to luks, it requests that the qcow2 pay‐
64 load (not qcow2 header) be encrypted using the LUKS for‐
65 mat. The passphrase to use to unlock the LUKS key slot is
66 given by the encrypt.key-secret parameter. LUKS encryp‐
67 tion parameters can be tuned with the other encrypt.* pa‐
68 rameters.
69
70 If this is set to aes, the image is encrypted with
71 128-bit AES-CBC. The encryption key is given by the en‐
72 crypt.key-secret parameter. This encryption format is
73 considered to be flawed by modern cryptography standards,
74 suffering from a number of design problems:
75
76 • The AES-CBC cipher is used with predictable initializa‐
77 tion vectors based on the sector number. This makes it
78 vulnerable to chosen plaintext attacks which can reveal
79 the existence of encrypted data.
80
81 • The user passphrase is directly used as the encryption
82 key. A poorly chosen or short passphrase will compro‐
83 mise the security of the encryption.
84
85 • In the event of the passphrase being compromised there
86 is no way to change the passphrase to protect data in
87 any qcow images. The files must be cloned, using a dif‐
88 ferent encryption passphrase in the new file. The orig‐
89 inal file must then be securely erased using a program
90 like shred, though even this is ineffective with many
91 modern storage technologies.
92
93 The use of this is no longer supported in system emula‐
94 tors. Support only remains in the command line utilities,
95 for the purposes of data liberation and interoperability
96 with old versions of QEMU. The luks format should be used
97 instead.
98
99 encrypt.key-secret
100 Provides the ID of a secret object that contains the
101 passphrase (encrypt.format=luks) or encryption key (en‐
102 crypt.format=aes).
103
104 encrypt.cipher-alg
105 Name of the cipher algorithm and key length. Currently
106 defaults to aes-256. Only used when encrypt.format=luks.
107
108 encrypt.cipher-mode
109 Name of the encryption mode to use. Currently defaults to
110 xts. Only used when encrypt.format=luks.
111
112 encrypt.ivgen-alg
113 Name of the initialization vector generator algorithm.
114 Currently defaults to plain64. Only used when en‐
115 crypt.format=luks.
116
117 encrypt.ivgen-hash-alg
118 Name of the hash algorithm to use with the initialization
119 vector generator (if required). Defaults to sha256. Only
120 used when encrypt.format=luks.
121
122 encrypt.hash-alg
123 Name of the hash algorithm to use for PBKDF algorithm De‐
124 faults to sha256. Only used when encrypt.format=luks.
125
126 encrypt.iter-time
127 Amount of time, in milliseconds, to use for PBKDF algo‐
128 rithm per key slot. Defaults to 2000. Only used when en‐
129 crypt.format=luks.
130
131 cluster_size
132 Changes the qcow2 cluster size (must be between 512 and
133 2M). Smaller cluster sizes can improve the image file
134 size whereas larger cluster sizes generally provide bet‐
135 ter performance.
136
137 preallocation
138 Preallocation mode (allowed values: off, metadata, fal‐
139 loc, full). An image with preallocated metadata is ini‐
140 tially larger but can improve performance when the image
141 needs to grow. falloc and full preallocations are like
142 the same options of raw format, but sets up metadata
143 also.
144
145 lazy_refcounts
146 If this option is set to on, reference count updates are
147 postponed with the goal of avoiding metadata I/O and im‐
148 proving performance. This is particularly interesting
149 with cache=writethrough which doesn't batch metadata up‐
150 dates. The tradeoff is that after a host crash, the ref‐
151 erence count tables must be rebuilt, i.e. on the next
152 open an (automatic) qemu-img check -r all is required,
153 which may take some time.
154
155 This option can only be enabled if compat=1.1 is speci‐
156 fied.
157
158 nocow If this option is set to on, it will turn off COW of the
159 file. It's only valid on btrfs, no effect on other file
160 systems.
161
162 Btrfs has low performance when hosting a VM image file,
163 even more when the guest on the VM also using btrfs as
164 file system. Turning off COW is a way to mitigate this
165 bad performance. Generally there are two ways to turn off
166 COW on btrfs:
167
168 • Disable it by mounting with nodatacow, then all newly
169 created files will be NOCOW.
170
171 • For an empty file, add the NOCOW file attribute. That's
172 what this option does.
173
174 Note: this option is only valid to new or empty files. If
175 there is an existing file which is COW and has data
176 blocks already, it couldn't be changed to NOCOW by set‐
177 ting nocow=on. One can issue lsattr filename to check if
178 the NOCOW flag is set or not (Capital 'C' is NOCOW flag).
179
180 qed Old QEMU image format with support for backing files and compact
181 image files (when your filesystem or transport medium does not
182 support holes).
183
184 When converting QED images to qcow2, you might want to consider
185 using the lazy_refcounts=on option to get a more QED-like behav‐
186 iour.
187
188 Supported options:
189
190 backing_file
191 File name of a base image (see create subcommand).
192
193 backing_fmt
194 Image file format of backing file (optional). Useful if
195 the format cannot be autodetected because it has no
196 header, like some vhd/vpc files.
197
198 cluster_size
199 Changes the cluster size (must be power-of-2 between 4K
200 and 64K). Smaller cluster sizes can improve the image
201 file size whereas larger cluster sizes generally provide
202 better performance.
203
204 table_size
205 Changes the number of clusters per L1/L2 table (must be
206 power-of-2 between 1 and 16). There is normally no need
207 to change this value but this option can between used for
208 performance benchmarking.
209
210 qcow Old QEMU image format with support for backing files, compact
211 image files, encryption and compression.
212
213 Supported options:
214
215 backing_file
216 File name of a base image (see create subcommand)
217
218 encryption
219 This option is deprecated and equivalent to en‐
220 crypt.format=aes
221
222 encrypt.format
223 If this is set to aes, the image is encrypted with
224 128-bit AES-CBC. The encryption key is given by the
225 encrypt.key-secret parameter. This encryption format
226 is considered to be flawed by modern cryptography
227 standards, suffering from a number of design problems
228 enumerated previously against the qcow2 image format.
229
230 The use of this is no longer supported in system emu‐
231 lators. Support only remains in the command line util‐
232 ities, for the purposes of data liberation and inter‐
233 operability with old versions of QEMU.
234
235 Users requiring native encryption should use the qcow2
236 format instead with encrypt.format=luks.
237
238 encrypt.key-secret
239 Provides the ID of a secret object that contains the
240 encryption key (encrypt.format=aes).
241
242 luks LUKS v1 encryption format, compatible with Linux dm-crypt/crypt‐
243 setup
244
245 Supported options:
246
247 key-secret
248 Provides the ID of a secret object that contains the
249 passphrase.
250
251 cipher-alg
252 Name of the cipher algorithm and key length. Currently
253 defaults to aes-256.
254
255 cipher-mode
256 Name of the encryption mode to use. Currently defaults to
257 xts.
258
259 ivgen-alg
260 Name of the initialization vector generator algorithm.
261 Currently defaults to plain64.
262
263 ivgen-hash-alg
264 Name of the hash algorithm to use with the initialization
265 vector generator (if required). Defaults to sha256.
266
267 hash-alg
268 Name of the hash algorithm to use for PBKDF algorithm De‐
269 faults to sha256.
270
271 iter-time
272 Amount of time, in milliseconds, to use for PBKDF algo‐
273 rithm per key slot. Defaults to 2000.
274
275 vdi VirtualBox 1.1 compatible image format.
276
277 Supported options:
278
279 static If this option is set to on, the image is created with
280 metadata preallocation.
281
282 vmdk VMware 3 and 4 compatible image format.
283
284 Supported options:
285
286 backing_file
287 File name of a base image (see create subcommand).
288
289 compat6
290 Create a VMDK version 6 image (instead of version 4)
291
292 hwversion
293 Specify vmdk virtual hardware version. Compat6 flag can‐
294 not be enabled if hwversion is specified.
295
296 subformat
297 Specifies which VMDK subformat to use. Valid options are
298 monolithicSparse (default), monolithicFlat, twoGbMaxEx‐
299 tentSparse, twoGbMaxExtentFlat and streamOptimized.
300
301 vpc VirtualPC compatible image format (VHD).
302
303 Supported options:
304
305 subformat
306 Specifies which VHD subformat to use. Valid options are
307 dynamic (default) and fixed.
308
309 VHDX Hyper-V compatible image format (VHDX).
310
311 Supported options:
312
313 subformat
314 Specifies which VHDX subformat to use. Valid options are
315 dynamic (default) and fixed.
316
317 block_state_zero
318 Force use of payload blocks of type 'ZERO'. Can
319 be set to on (default) or off. When set to off,
320 new blocks will be created as PAY‐
321 LOAD_BLOCK_NOT_PRESENT, which means parsers are
322 free to return arbitrary data for those blocks.
323 Do not set to off when using qemu-img convert with
324 subformat=dynamic.
325
326 block_size
327 Block size; min 1 MB, max 256 MB. 0 means
328 auto-calculate based on image size.
329
330 log_size
331 Log size; min 1 MB.
332
333 Read-only formats
334 More disk image file formats are supported in a read-only mode.
335
336 bochs Bochs images of growing type.
337
338 cloop Linux Compressed Loop image, useful only to reuse directly com‐
339 pressed CD-ROM images present for example in the Knoppix
340 CD-ROMs.
341
342 dmg Apple disk image.
343
344 parallels
345 Parallels disk image format.
346
347 Using host drives
348 In addition to disk image files, QEMU can directly access host devices.
349 We describe here the usage for QEMU version >= 0.8.3.
350
351 Linux
352 On Linux, you can directly use the host device filename instead of a
353 disk image filename provided you have enough privileges to access it.
354 For example, use /dev/cdrom to access to the CDROM.
355
356 CD You can specify a CDROM device even if no CDROM is loaded. QEMU
357 has specific code to detect CDROM insertion or removal. CDROM
358 ejection by the guest OS is supported. Currently only data CDs
359 are supported.
360
361 Floppy You can specify a floppy device even if no floppy is loaded.
362 Floppy removal is currently not detected accurately (if you
363 change floppy without doing floppy access while the floppy is
364 not loaded, the guest OS will think that the same floppy is
365 loaded). Use of the host's floppy device is deprecated, and
366 support for it will be removed in a future release.
367
368 Hard disks
369 Hard disks can be used. Normally you must specify the whole disk
370 (/dev/hdb instead of /dev/hdb1) so that the guest OS can see it
371 as a partitioned disk. WARNING: unless you know what you do, it
372 is better to only make READ-ONLY accesses to the hard disk oth‐
373 erwise you may corrupt your host data (use the -snapshot command
374 line option or modify the device permissions accordingly).
375
376 Zoned block devices
377 Zoned block devices can be passed through to the guest if the
378 emulated storage controller supports zoned storage. Use --block‐
379 dev host_device, node-name=drive0,filename=/dev/nullb0,cache.di‐
380 rect=on to pass through /dev/nullb0 as drive0.
381
382 Windows
383 CD The preferred syntax is the drive letter (e.g. d:). The alter‐
384 nate syntax \\.\d: is supported. /dev/cdrom is supported as an
385 alias to the first CDROM drive.
386
387 Currently there is no specific code to handle removable media,
388 so it is better to use the change or eject monitor commands to
389 change or eject media.
390
391 Hard disks
392 Hard disks can be used with the syntax: \\.\PhysicalDriveN where
393 N is the drive number (0 is the first hard disk).
394
395 WARNING: unless you know what you do, it is better to only make
396 READ-ONLY accesses to the hard disk otherwise you may corrupt
397 your host data (use the -snapshot command line so that the modi‐
398 fications are written in a temporary file).
399
400 Mac OS X
401 /dev/cdrom is an alias to the first CDROM.
402
403 Currently there is no specific code to handle removable media, so it is
404 better to use the change or eject monitor commands to change or eject
405 media.
406
407 Virtual FAT disk images
408 QEMU can automatically create a virtual FAT disk image from a directory
409 tree. In order to use it, just type:
410
411 qemu-system-x86_64 linux.img -hdb fat:/my_directory
412
413 Then you access access to all the files in the /my_directory directory
414 without having to copy them in a disk image or to export them via SAMBA
415 or NFS. The default access is read-only.
416
417 Floppies can be emulated with the :floppy: option:
418
419 qemu-system-x86_64 linux.img -fda fat:floppy:/my_directory
420
421 A read/write support is available for testing (beta stage) with the
422 :rw: option:
423
424 qemu-system-x86_64 linux.img -fda fat:floppy:rw:/my_directory
425
426 What you should never do:
427
428 • use non-ASCII filenames
429
430 • use "-snapshot" together with ":rw:"
431
432 • expect it to work when loadvm'ing
433
434 • write to the FAT directory on the host system while accessing it with
435 the guest system
436
437 NBD access
438 QEMU can access directly to block device exported using the Network
439 Block Device protocol.
440
441 qemu-system-x86_64 linux.img -hdb nbd://my_nbd_server.mydomain.org:1024/
442
443 If the NBD server is located on the same host, you can use an unix
444 socket instead of an inet socket:
445
446 qemu-system-x86_64 linux.img -hdb nbd+unix://?socket=/tmp/my_socket
447
448 In this case, the block device must be exported using qemu-nbd:
449
450 qemu-nbd --socket=/tmp/my_socket my_disk.qcow2
451
452 The use of qemu-nbd allows sharing of a disk between several guests:
453
454 qemu-nbd --socket=/tmp/my_socket --share=2 my_disk.qcow2
455
456 and then you can use it with two guests:
457
458 qemu-system-x86_64 linux1.img -hdb nbd+unix://?socket=/tmp/my_socket
459 qemu-system-x86_64 linux2.img -hdb nbd+unix://?socket=/tmp/my_socket
460
461 If the nbd-server uses named exports (supported since NBD 2.9.18, or
462 with QEMU's own embedded NBD server), you must specify an export name
463 in the URI:
464
465 qemu-system-x86_64 -cdrom nbd://localhost/debian-500-ppc-netinst
466 qemu-system-x86_64 -cdrom nbd://localhost/openSUSE-11.1-ppc-netinst
467
468 The URI syntax for NBD is supported since QEMU 1.3. An alternative
469 syntax is also available. Here are some example of the older syntax:
470
471 qemu-system-x86_64 linux.img -hdb nbd:my_nbd_server.mydomain.org:1024
472 qemu-system-x86_64 linux2.img -hdb nbd:unix:/tmp/my_socket
473 qemu-system-x86_64 -cdrom nbd:localhost:10809:exportname=debian-500-ppc-netinst
474
475 iSCSI LUNs
476 iSCSI is a popular protocol used to access SCSI devices across a com‐
477 puter network.
478
479 There are two different ways iSCSI devices can be used by QEMU.
480
481 The first method is to mount the iSCSI LUN on the host, and make it ap‐
482 pear as any other ordinary SCSI device on the host and then to access
483 this device as a /dev/sd device from QEMU. How to do this differs be‐
484 tween host OSes.
485
486 The second method involves using the iSCSI initiator that is built into
487 QEMU. This provides a mechanism that works the same way regardless of
488 which host OS you are running QEMU on. This section will describe this
489 second method of using iSCSI together with QEMU.
490
491 In QEMU, iSCSI devices are described using special iSCSI URLs. URL syn‐
492 tax:
493
494 iscsi://[<username>[%<password>]@]<host>[:<port>]/<target-iqn-name>/<lun>
495
496 Username and password are optional and only used if your target is set
497 up using CHAP authentication for access control. Alternatively the
498 username and password can also be set via environment variables to have
499 these not show up in the process list:
500
501 export LIBISCSI_CHAP_USERNAME=<username>
502 export LIBISCSI_CHAP_PASSWORD=<password>
503 iscsi://<host>/<target-iqn-name>/<lun>
504
505 Various session related parameters can be set via special options, ei‐
506 ther in a configuration file provided via '-readconfig' or directly on
507 the command line.
508
509 If the initiator-name is not specified qemu will use a default name of
510 'iqn.2008-11.org.linux-kvm[:<uuid>'] where <uuid> is the UUID of the
511 virtual machine. If the UUID is not specified qemu will use
512 'iqn.2008-11.org.linux-kvm[:<name>'] where <name> is the name of the
513 virtual machine.
514
515 Setting a specific initiator name to use when logging in to the target:
516
517 -iscsi initiator-name=iqn.qemu.test:my-initiator
518
519 Controlling which type of header digest to negotiate with the target:
520
521 -iscsi header-digest=CRC32C|CRC32C-NONE|NONE-CRC32C|NONE
522
523 These can also be set via a configuration file:
524
525 [iscsi]
526 user = "CHAP username"
527 password = "CHAP password"
528 initiator-name = "iqn.qemu.test:my-initiator"
529 # header digest is one of CRC32C|CRC32C-NONE|NONE-CRC32C|NONE
530 header-digest = "CRC32C"
531
532 Setting the target name allows different options for different targets:
533
534 [iscsi "iqn.target.name"]
535 user = "CHAP username"
536 password = "CHAP password"
537 initiator-name = "iqn.qemu.test:my-initiator"
538 # header digest is one of CRC32C|CRC32C-NONE|NONE-CRC32C|NONE
539 header-digest = "CRC32C"
540
541 How to use a configuration file to set iSCSI configuration options:
542
543 cat >iscsi.conf <<EOF
544 [iscsi]
545 user = "me"
546 password = "my password"
547 initiator-name = "iqn.qemu.test:my-initiator"
548 header-digest = "CRC32C"
549 EOF
550
551 qemu-system-x86_64 -drive file=iscsi://127.0.0.1/iqn.qemu.test/1 \
552 -readconfig iscsi.conf
553
554 How to set up a simple iSCSI target on loopback and access it via QEMU:
555 this example shows how to set up an iSCSI target with one CDROM and one
556 DISK using the Linux STGT software target. This target is available on
557 Red Hat based systems as the package 'scsi-target-utils'.
558
559 tgtd --iscsi portal=127.0.0.1:3260
560 tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.qemu.test
561 tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 \
562 -b /IMAGES/disk.img --device-type=disk
563 tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 \
564 -b /IMAGES/cd.iso --device-type=cd
565 tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
566
567 qemu-system-x86_64 -iscsi initiator-name=iqn.qemu.test:my-initiator \
568 -boot d -drive file=iscsi://127.0.0.1/iqn.qemu.test/1 \
569 -cdrom iscsi://127.0.0.1/iqn.qemu.test/2
570
571 GlusterFS disk images
572 GlusterFS is a user space distributed file system.
573
574 You can boot from the GlusterFS disk image with the command:
575
576 URI:
577
578 qemu-system-x86_64 -drive file=gluster[+TYPE]://[HOST}[:PORT]]/VOLUME/PATH
579 [?socket=...][,file.debug=9][,file.logfile=...]
580
581 JSON:
582
583 qemu-system-x86_64 'json:{"driver":"qcow2",
584 "file":{"driver":"gluster",
585 "volume":"testvol","path":"a.img","debug":9,"logfile":"...",
586 "server":[{"type":"tcp","host":"...","port":"..."},
587 {"type":"unix","socket":"..."}]}}'
588
589 gluster is the protocol.
590
591 TYPE specifies the transport type used to connect to gluster management
592 daemon (glusterd). Valid transport types are tcp and unix. In the URI
593 form, if a transport type isn't specified, then tcp type is assumed.
594
595 HOST specifies the server where the volume file specification for the
596 given volume resides. This can be either a hostname or an ipv4 address.
597 If transport type is unix, then HOST field should not be specified.
598 Instead socket field needs to be populated with the path to unix domain
599 socket.
600
601 PORT is the port number on which glusterd is listening. This is op‐
602 tional and if not specified, it defaults to port 24007. If the trans‐
603 port type is unix, then PORT should not be specified.
604
605 VOLUME is the name of the gluster volume which contains the disk image.
606
607 PATH is the path to the actual disk image that resides on gluster vol‐
608 ume.
609
610 debug is the logging level of the gluster protocol driver. Debug levels
611 are 0-9, with 9 being the most verbose, and 0 representing no debugging
612 output. The default level is 4. The current logging levels defined in
613 the gluster source are 0 - None, 1 - Emergency, 2 - Alert, 3 - Criti‐
614 cal, 4 - Error, 5 - Warning, 6 - Notice, 7 - Info, 8 - Debug, 9 - Trace
615
616 logfile is a commandline option to mention log file path which helps in
617 logging to the specified file and also help in persisting the gfapi
618 logs. The default is stderr.
619
620 You can create a GlusterFS disk image with the command:
621
622 qemu-img create gluster://HOST/VOLUME/PATH SIZE
623
624 Examples
625
626 qemu-system-x86_64 -drive file=gluster://1.2.3.4/testvol/a.img
627 qemu-system-x86_64 -drive file=gluster+tcp://1.2.3.4/testvol/a.img
628 qemu-system-x86_64 -drive file=gluster+tcp://1.2.3.4:24007/testvol/dir/a.img
629 qemu-system-x86_64 -drive file=gluster+tcp://[1:2:3:4:5:6:7:8]/testvol/dir/a.img
630 qemu-system-x86_64 -drive file=gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img
631 qemu-system-x86_64 -drive file=gluster+tcp://server.domain.com:24007/testvol/dir/a.img
632 qemu-system-x86_64 -drive file=gluster+unix:///testvol/dir/a.img?socket=/tmp/glusterd.socket
633 qemu-system-x86_64 -drive file=gluster+rdma://1.2.3.4:24007/testvol/a.img
634 qemu-system-x86_64 -drive file=gluster://1.2.3.4/testvol/a.img,file.debug=9,file.logfile=/var/log/qemu-gluster.log
635 qemu-system-x86_64 'json:{"driver":"qcow2",
636 "file":{"driver":"gluster",
637 "volume":"testvol","path":"a.img",
638 "debug":9,"logfile":"/var/log/qemu-gluster.log",
639 "server":[{"type":"tcp","host":"1.2.3.4","port":24007},
640 {"type":"unix","socket":"/var/run/glusterd.socket"}]}}'
641 qemu-system-x86_64 -drive driver=qcow2,file.driver=gluster,file.volume=testvol,file.path=/path/a.img,
642 file.debug=9,file.logfile=/var/log/qemu-gluster.log,
643 file.server.0.type=tcp,file.server.0.host=1.2.3.4,file.server.0.port=24007,
644 file.server.1.type=unix,file.server.1.socket=/var/run/glusterd.socket
645
646 Secure Shell (ssh) disk images
647 You can access disk images located on a remote ssh server by using the
648 ssh protocol:
649
650 qemu-system-x86_64 -drive file=ssh://[USER@]SERVER[:PORT]/PATH[?host_key_check=HOST_KEY_CHECK]
651
652 Alternative syntax using properties:
653
654 qemu-system-x86_64 -drive file.driver=ssh[,file.user=USER],file.host=SERVER[,file.port=PORT],file.path=PATH[,file.host_key_check=HOST_KEY_CHECK]
655
656 ssh is the protocol.
657
658 USER is the remote user. If not specified, then the local username is
659 tried.
660
661 SERVER specifies the remote ssh server. Any ssh server can be used,
662 but it must implement the sftp-server protocol. Most Unix/Linux sys‐
663 tems should work without requiring any extra configuration.
664
665 PORT is the port number on which sshd is listening. By default the
666 standard ssh port (22) is used.
667
668 PATH is the path to the disk image.
669
670 The optional HOST_KEY_CHECK parameter controls how the remote host's
671 key is checked. The default is yes which means to use the local
672 .ssh/known_hosts file. Setting this to no turns off known-hosts check‐
673 ing. Or you can check that the host key matches a specific finger‐
674 print. The fingerprint can be provided in md5, sha1, or sha256 format,
675 however, it is strongly recommended to only use sha256, since the other
676 options are considered insecure by modern standards. The fingerprint
677 value must be given as a hex encoded string:
678
679 host_key_check=sha256:04ce2ae89ff4295a6b9c4111640bdcb3297858ee55cb434d9dd88796e93aa795
680
681 The key string may optionally contain ":" separators between each pair
682 of hex digits.
683
684 The $HOME/.ssh/known_hosts file contains the base64 encoded host keys.
685 These can be converted into the format needed for QEMU using a command
686 such as:
687
688 $ for key in `grep 10.33.8.112 known_hosts | awk '{print $3}'`
689 do
690 echo $key | base64 -d | sha256sum
691 done
692 6c3aa525beda9dc83eadfbd7e5ba7d976ecb59575d1633c87cd06ed2ed6e366f -
693 12214fd9ea5b408086f98ecccd9958609bd9ac7c0ea316734006bc7818b45dc8 -
694 d36420137bcbd101209ef70c3b15dc07362fbe0fa53c5b135eba6e6afa82f0ce -
695
696 Note that there can be multiple keys present per host, each with dif‐
697 ferent key ciphers. Care is needed to pick the key fingerprint that
698 matches the cipher QEMU will negotiate with the remote server.
699
700 Currently authentication must be done using ssh-agent. Other authenti‐
701 cation methods may be supported in future.
702
703 Note: Many ssh servers do not support an fsync-style operation. The
704 ssh driver cannot guarantee that disk flush requests are obeyed, and
705 this causes a risk of disk corruption if the remote server or network
706 goes down during writes. The driver will print a warning when fsync is
707 not supported:
708
709 warning: ssh server ssh.example.com:22 does not support fsync
710
711 With sufficiently new versions of libssh and OpenSSH, fsync is sup‐
712 ported.
713
714 NVMe disk images
715 NVM Express (NVMe) storage controllers can be accessed directly by a
716 userspace driver in QEMU. This bypasses the host kernel file system
717 and block layers while retaining QEMU block layer functionalities, such
718 as block jobs, I/O throttling, image formats, etc. Disk I/O perfor‐
719 mance is typically higher than with -drive file=/dev/sda using either
720 thread pool or linux-aio.
721
722 The controller will be exclusively used by the QEMU process once
723 started. To be able to share storage between multiple VMs and other ap‐
724 plications on the host, please use the file based protocols.
725
726 Before starting QEMU, bind the host NVMe controller to the host
727 vfio-pci driver. For example:
728
729 # modprobe vfio-pci
730 # lspci -n -s 0000:06:0d.0
731 06:0d.0 0401: 1102:0002 (rev 08)
732 # echo 0000:06:0d.0 > /sys/bus/pci/devices/0000:06:0d.0/driver/unbind
733 # echo 1102 0002 > /sys/bus/pci/drivers/vfio-pci/new_id
734
735 # qemu-system-x86_64 -drive file=nvme://HOST:BUS:SLOT.FUNC/NAMESPACE
736
737 Alternative syntax using properties:
738
739 qemu-system-x86_64 -drive file.driver=nvme,file.device=HOST:BUS:SLOT.FUNC,file.namespace=NAMESPACE
740
741 HOST:BUS:SLOT.FUNC is the NVMe controller's PCI device address on the
742 host.
743
744 NAMESPACE is the NVMe namespace number, starting from 1.
745
746 Disk image file locking
747 By default, QEMU tries to protect image files from unexpected concur‐
748 rent access, as long as it's supported by the block protocol driver and
749 host operating system. If multiple QEMU processes (including QEMU emu‐
750 lators and utilities) try to open the same image with conflicting ac‐
751 cessing modes, all but the first one will get an error.
752
753 This feature is currently supported by the file protocol on Linux with
754 the Open File Descriptor (OFD) locking API, and can be configured to
755 fall back to POSIX locking if the POSIX host doesn't support Linux OFD
756 locking.
757
758 To explicitly enable image locking, specify "locking=on" in the file
759 protocol driver options. If OFD locking is not possible, a warning will
760 be printed and the POSIX locking API will be used. In this case there
761 is a risk that the lock will get silently lost when doing hot plugging
762 and block jobs, due to the shortcomings of the POSIX locking API.
763
764 QEMU transparently handles lock handover during shared storage migra‐
765 tion. For shared virtual disk images between multiple VMs, the
766 "share-rw" device option should be used.
767
768 By default, the guest has exclusive write access to its disk image. If
769 the guest can safely share the disk image with other writers the -de‐
770 vice ...,share-rw=on parameter can be used. This is only safe if the
771 guest is running software, such as a cluster file system, that coordi‐
772 nates disk accesses to avoid corruption.
773
774 Note that share-rw=on only declares the guest's ability to share the
775 disk. Some QEMU features, such as image file formats, require exclu‐
776 sive write access to the disk image and this is unaffected by the
777 share-rw=on option.
778
779 Alternatively, locking can be fully disabled by "locking=off" block de‐
780 vice option. In the command line, the option is usually in the form of
781 "file.locking=off" as the protocol driver is normally placed as a
782 "file" child under a format driver. For example:
783
784 -blockdev driver=qcow2,file.filename=/path/to/image,file.locking=off,file.driver=file
785
786 To check if image locking is active, check the output of the "lslocks"
787 command on host and see if there are locks held by the QEMU process on
788 the image file. More than one byte could be locked by the QEMU in‐
789 stance, each byte of which reflects a particular permission that is ac‐
790 quired or protected by the running block driver.
791
792 Filter drivers
793 QEMU supports several filter drivers, which don't store any data, but
794 perform some additional tasks, hooking io requests.
795
796 preallocate
797 The preallocate filter driver is intended to be inserted between
798 format and protocol nodes and preallocates some additional space
799 (expanding the protocol file) when writing past the file’s end.
800 This can be useful for file-systems with slow allocation.
801
802 Supported options:
803
804 prealloc-align
805 On preallocation, align the file length to this value (in
806 bytes), default 1M.
807
808 prealloc-size
809 How much to preallocate (in bytes), default 128M.
810
812 The HTML documentation of QEMU for more precise information and Linux
813 user mode emulator invocation.
814
816 Fabrice Bellard and the QEMU Project developers
817
819 2023, The QEMU Project Developers
820
821
822
823
8248.1.3 Nov 28, 2023 QEMU-BLOCK-DRIVERS(7)