2
0

qemu-block-drivers.texi 32 KB

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