2
0

qemu-block-drivers.rst.inc 32 KB

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