2
0

qemu-block-drivers.texi 30 KB

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