dev-manual-qemu.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
  3. [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
  4. <chapter id='dev-manual-qemu'>
  5. <title>Using the Quick EMUlator (QEMU)</title>
  6. <para>
  7. Quick EMUlator (QEMU) is an Open Source project the Yocto Project uses
  8. as part of its development "tool set".
  9. As such, the information in this chapter is limited to the
  10. Yocto Project integration of QEMU and not QEMU in general.
  11. For official information and documentation on QEMU, see the
  12. following references:
  13. <itemizedlist>
  14. <listitem><para><emphasis><ulink url='http://wiki.qemu.org/Main_Page'>QEMU Website</ulink>:</emphasis>
  15. The official website for the QEMU Open Source project.
  16. </para></listitem>
  17. <listitem><para><emphasis><ulink url='http://wiki.qemu.org/Manual'>Documentation</ulink>:</emphasis>
  18. The QEMU user manual.
  19. </para></listitem>
  20. </itemizedlist>
  21. </para>
  22. <para>
  23. This chapter provides an overview of the Yocto Project's integration of
  24. QEMU, a description of how you use QEMU and its various options, running
  25. under a Network File System (NFS) server, and a few tips and tricks you
  26. might find helpful when using QEMU.
  27. </para>
  28. <section id='qemu-overview'>
  29. <title>Overview</title>
  30. <para>
  31. Within the context of the Yocto Project, QEMU is an
  32. emulator and virtualization machine that allows you to run a complete
  33. image you have built using the Yocto Project as just another task
  34. on your build system.
  35. QEMU is useful for running and testing images and applications on
  36. supported Yocto Project architectures without having actual hardware.
  37. Among other things, the Yocto Project uses QEMU to run automated
  38. Quality Assurance (QA) tests on final images shipped with each
  39. release.
  40. </para>
  41. <para>
  42. QEMU is made available with the Yocto Project a number of ways.
  43. One method is to install a Software Development Kit (SDK).
  44. For more information on how to make sure you have
  45. QEMU available, see the
  46. <ulink url='&YOCTO_DOCS_SDK_URL;#sdk-intro'>Yocto Project Software Development Kit (SDK) Developer's Guide</ulink>.
  47. </para>
  48. </section>
  49. <section id='qemu-running-qemu'>
  50. <title>Running QEMU</title>
  51. <para>
  52. Running QEMU involves having your build environment set up, having the
  53. right artifacts available, and understanding how to use the many
  54. options that are available to you when you start QEMU using the
  55. <filename>runqemu</filename> command.
  56. </para>
  57. <section id='qemu-setting-up-the-environment'>
  58. <title>Setting Up the Environment</title>
  59. <para>
  60. You run QEMU in the same environment from which you run BitBake.
  61. This means you need to source a build environment script (i.e.
  62. <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
  63. or
  64. <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>).
  65. </para>
  66. </section>
  67. <section id='qemu-using-the-runqemu-command'>
  68. <title>Using the <filename>runqemu</filename> Command</title>
  69. <para>
  70. The basic <filename>runqemu</filename> command syntax is as
  71. follows:
  72. <literallayout class='monospaced'>
  73. $ runqemu [<replaceable>option</replaceable> ] [...]
  74. </literallayout>
  75. Based on what you provide on the command line,
  76. <filename>runqemu</filename> does a good job of figuring out what
  77. you are trying to do.
  78. For example, by default, QEMU looks for the most recently built
  79. image according to the timestamp when it needs to look for an
  80. image.
  81. Minimally, through the use of options, you must provide either
  82. a machine name, a virtual machine image
  83. (<filename>*.vmdk</filename>), or a kernel image
  84. (<filename>*.bin</filename>).
  85. </para>
  86. <para>
  87. Following is a description of <filename>runqemu</filename>
  88. options you can provide on the command line:
  89. <note><title>Tip</title>
  90. If you do provide some "illegal" option combination or perhaps
  91. you do not provide enough in the way of options,
  92. <filename>runqemu</filename> provides appropriate error
  93. messaging to help you correct the problem.
  94. </note>
  95. <itemizedlist>
  96. <listitem><para><replaceable>QEMUARCH</replaceable>:
  97. The QEMU machine architecture, which must be "qemux86",
  98. "qemux86_64", "qemuarm", "qemumips", "qemumipsel",
  99. “qemumips64", "qemush4", "qemuppc", "qemumicroblaze",
  100. or "qemuzynq".
  101. </para></listitem>
  102. <listitem><para><filename><replaceable>VM</replaceable></filename>:
  103. The virtual machine image, which must be a
  104. <filename>.vmdk</filename> file.
  105. Use this option when you want to boot a
  106. <filename>.vmdk</filename> image.
  107. The image filename you provide must contain one of the
  108. following strings: "qemux86-64", "qemux86", "qemuarm",
  109. "qemumips64", "qemumips", "qemuppc", or "qemush4".
  110. </para></listitem>
  111. <listitem><para><replaceable>ROOTFS</replaceable>:
  112. A root filesystem that has one of the following
  113. filetype extensions: "ext2", "ext3", "ext4", "jffs2",
  114. "nfs", or "btrfs".
  115. If the filename you provide for this option uses “nfs”, it
  116. must provide an explicit root filesystem path.
  117. </para></listitem>
  118. <listitem><para><replaceable>KERNEL</replaceable>:
  119. A kernel image, which is a <filename>.bin</filename> file.
  120. When you provide a <filename>.bin</filename> file,
  121. <filename>runqemu</filename> detects it and assumes the
  122. file is a kernel image.
  123. </para></listitem>
  124. <listitem><para><replaceable>MACHINE</replaceable>:
  125. The architecture of the QEMU machine, which must be one
  126. of the following: "qemux86",
  127. "qemux86-64", "qemuarm", "qemumips", "qemumipsel",
  128. “qemumips64", "qemush4", "qemuppc", "qemumicroblaze",
  129. or "qemuzynq".
  130. The <replaceable>MACHINE</replaceable> and
  131. <replaceable>QEMUARCH</replaceable> options are basically
  132. identical.
  133. If you do not provide a <replaceable>MACHINE</replaceable>
  134. option, <filename>runqemu</filename> tries to determine
  135. it based on other options.
  136. </para></listitem>
  137. <listitem><para><filename>ramfs</filename>:
  138. Indicates you are booting an initial RAM disk (initramfs)
  139. image, which means the <filename>FSTYPE</filename> is
  140. <filename>cpio.gz</filename>.
  141. </para></listitem>
  142. <listitem><para><filename>iso</filename>:
  143. Indicates you are booting an ISO image, which means the
  144. <filename>FSTYPE</filename> is
  145. <filename>.iso</filename>.
  146. </para></listitem>
  147. <listitem><para><filename>nographic</filename>:
  148. Disables the video console, which sets the console to
  149. "ttys0".
  150. </para></listitem>
  151. <listitem><para><filename>serial</filename>:
  152. Enables a serial console on
  153. <filename>/dev/ttyS0</filename>.
  154. </para></listitem>
  155. <listitem><para><filename>biosdir</filename>:
  156. Establishes a custom directory for BIOS, VGA BIOS and
  157. keymaps.
  158. </para></listitem>
  159. <listitem><para><filename>biosfilename</filename>:
  160. Establishes a custom BIOS name.
  161. </para></listitem>
  162. <listitem><para><filename>qemuparams=\"<replaceable>xyz</replaceable>\"</filename>:
  163. Specifies custom QEMU parameters.
  164. Use this option to pass options other than the simple
  165. "kvm" and "serial" options.
  166. </para></listitem>
  167. <listitem><para><filename>bootparams=\"<replaceable>xyz</replaceable>\"</filename>:
  168. Specifies custom boot parameters for the kernel.
  169. </para></listitem>
  170. <listitem><para><filename>audio</filename>:
  171. Enables audio in QEMU.
  172. The <replaceable>MACHINE</replaceable> option must be
  173. either "qemux86" or "qemux86-64" in order for audio to be
  174. enabled.
  175. Additionally, the <filename>snd_intel8x0</filename>
  176. or <filename>snd_ens1370</filename> driver must be
  177. installed in linux guest.
  178. </para></listitem>
  179. <listitem><para><filename>slirp</filename>:
  180. Enables "slirp" networking, which is a different way
  181. of networking that does not need root access
  182. but also is not as easy to use or comprehensive
  183. as the default.
  184. </para></listitem>
  185. <listitem><para id='kvm-cond'><filename>kvm</filename>:
  186. Enables KVM when running "qemux86" or "qemux86-64"
  187. QEMU architectures.
  188. For KVM to work, all the following conditions must be met:
  189. <itemizedlist>
  190. <listitem><para>
  191. Your <replaceable>MACHINE</replaceable> must be either
  192. qemux86" or "qemux86-64".
  193. </para></listitem>
  194. <listitem><para>
  195. Your build host has to have the KVM modules
  196. installed, which are
  197. <filename>/dev/kvm</filename>.
  198. </para></listitem>
  199. <listitem><para>
  200. The build host <filename>/dev/kvm</filename>
  201. directory has to be both writable and readable.
  202. </para></listitem>
  203. </itemizedlist>
  204. </para></listitem>
  205. <listitem><para><filename>kvm-vhost</filename>:
  206. Enables KVM with VHOST support when running "qemux86" or "qemux86-64"
  207. QEMU architectures.
  208. For KVM with VHOST to work, the following conditions must
  209. be met:
  210. <itemizedlist>
  211. <listitem><para>
  212. <link linkend='kvm-cond'>kvm</link> option
  213. conditions must be met.
  214. </para></listitem>
  215. <listitem><para>
  216. Your build host has to have virtio net device, which
  217. are <filename>/dev/vhost-net</filename>.
  218. </para></listitem>
  219. <listitem><para>
  220. The build host <filename>/dev/vhost-net</filename>
  221. directory has to be either readable or writable
  222. and “slirp-enabled”.
  223. </para></listitem>
  224. </itemizedlist>
  225. </para></listitem>
  226. <listitem><para><filename>publicvnc</filename>:
  227. Enables a VNC server open to all hosts.
  228. </para></listitem>
  229. </itemizedlist>
  230. </para>
  231. <para>
  232. For further understanding regarding option use with
  233. <filename>runqemu</filename>, consider some examples.
  234. </para>
  235. <para>
  236. This example starts QEMU with
  237. <replaceable>MACHINE</replaceable> set to "qemux86".
  238. Assuming a standard
  239. <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
  240. <filename>runqemu</filename> automatically finds the
  241. <filename>bzImage-qemux86.bin</filename> image file and
  242. the
  243. <filename>core-image-minimal-qemux86-20140707074611.rootfs.ext3</filename>
  244. (assuming the current build created a
  245. <filename>core-image-minimal</filename> image).
  246. <note>
  247. When more than one image with the same name exists, QEMU finds
  248. and uses the most recently built image according to the
  249. timestamp.
  250. </note>
  251. <literallayout class='monospaced'>
  252. $ runqemu qemux86
  253. </literallayout>
  254. This example produces the exact same results as the
  255. previous example.
  256. This command, however, specifically provides the image
  257. and root filesystem type.
  258. <literallayout class='monospaced'>
  259. $ runqemu qemux86 core-image-minimal ext3
  260. </literallayout>
  261. This example specifies to boot an initial RAM disk image
  262. and to enable audio in QEMU.
  263. For this case, <filename>runqemu</filename> set the
  264. internal variable <filename>FSTYPE</filename> to
  265. "cpio.gz".
  266. Also, for audio to be enabled, an appropriate driver must
  267. be installed (see the previous description for the
  268. <filename>audio</filename> option for more information).
  269. <literallayout class='monospaced'>
  270. $ runqemu qemux86 ramfs audio
  271. </literallayout>
  272. This example does not provide enough information for
  273. QEMU to launch.
  274. While the command does provide a root filesystem type, it
  275. must also minimally provide a
  276. <replaceable>MACHINE</replaceable>,
  277. <replaceable>KERNEL</replaceable>, or
  278. <replaceable>VM</replaceable> option.
  279. <literallayout class='monospaced'>
  280. $ runqemu ext3
  281. </literallayout>
  282. This example specifies to boot a virtual machine image
  283. (<filename>.vmdk</filename> file).
  284. From the <filename>.vmdk</filename>,
  285. <filename>runqemu</filename> determines the QEMU
  286. architecture (<replaceable>MACHINE</replaceable>) to be
  287. "qemux86" and the root filesystem type to be "vmdk".
  288. <literallayout class='monospaced'>
  289. $ runqemu /home/scott-lenovo/vm/core-image-minimal-qemux86.vmdk
  290. </literallayout>
  291. </para>
  292. </section>
  293. </section>
  294. <section id='qemu-running-under-a-network-file-system-nfs-server'>
  295. <title>Running Under a Network File System (NFS) Server</title>
  296. <para>
  297. One method for running QEMU is to run it on an NFS server.
  298. This is useful when you need to access the same file system from both
  299. the build and the emulated system at the same time.
  300. It is also worth noting that the system does not need root privileges
  301. to run.
  302. It uses a user space NFS server to avoid that.
  303. This section describes how to set up for running QEMU using an NFS
  304. server and then how you can start and stop the server.
  305. </para>
  306. <section id='qemu-setting-up-to-use-nfs'>
  307. <title>Setting Up to Use NFS</title>
  308. <para>
  309. Once you are able to run QEMU in your environment, you can use the
  310. <filename>runqemu-extract-sdk</filename> script, which is located
  311. in the <filename>scripts</filename> directory along with
  312. <filename>runqemu</filename> script.
  313. The <filename>runqemu-extract-sdk</filename> takes a root
  314. file system tarball and extracts it into a location that you
  315. specify.
  316. Then, when you run <filename>runqemu</filename>, you can specify
  317. the location that has the file system to pass it to QEMU.
  318. Here is an example that takes a file system and extracts it to
  319. a directory named <filename>test-nfs</filename>:
  320. <literallayout class='monospaced'>
  321. runqemu-extract-sdk ./tmp/deploy/images/qemux86/core-image-sato-qemux86.tar.bz2 test-nfs
  322. </literallayout>
  323. Once you have extracted the file system, you can run
  324. <filename>runqemu</filename> normally with the additional
  325. location of the file system.
  326. You can then also make changes to the files within
  327. <filename>./test-nfs</filename> and see those changes appear in the
  328. image in real time.
  329. Here is an example using the <filename>qemux86</filename> image:
  330. <literallayout class='monospaced'>
  331. runqemu qemux86 ./test-nfs
  332. </literallayout>
  333. </para>
  334. </section>
  335. <section id='qemu-starting-and-stopping-nfs'>
  336. <title>Starting and Stopping NFS</title>
  337. <para>
  338. You can manually start and stop the NFS share using these
  339. commands:
  340. <itemizedlist>
  341. <listitem><para><emphasis><filename>start</filename>:</emphasis>
  342. Starts the NFS share:
  343. <literallayout class='monospaced'>
  344. runqemu-export-rootfs start <replaceable>file-system-location</replaceable>
  345. </literallayout>
  346. </para></listitem>
  347. <listitem><para><emphasis><filename>stop</filename>:</emphasis>
  348. Stops the NFS share:
  349. <literallayout class='monospaced'>
  350. runqemu-export-rootfs stop <replaceable>file-system-location</replaceable>
  351. </literallayout>
  352. </para></listitem>
  353. <listitem><para><emphasis><filename>restart</filename>:</emphasis>
  354. Restarts the NFS share:
  355. <literallayout class='monospaced'>
  356. runqemu-export-rootfs restart <replaceable>file-system-location</replaceable>
  357. </literallayout>
  358. </para></listitem>
  359. </itemizedlist>
  360. </para>
  361. </section>
  362. </section>
  363. <section id='qemu-tips-and-tricks'>
  364. <title>Tips and Tricks</title>
  365. <para>
  366. The following list describes things you can do to make running QEMU
  367. in the context of the Yocto Project a better experience:
  368. <itemizedlist>
  369. <listitem><para><emphasis>Switching Between Consoles:</emphasis>
  370. When booting or running QEMU, you can switch between
  371. supported consoles by using
  372. Ctrl+Alt+<replaceable>number</replaceable>.
  373. For example, Ctrl+Alt+3 switches you to the serial console as
  374. long as that console is enabled.
  375. Being able to switch consoles is helpful, for example, if the
  376. main QEMU console breaks for some reason.
  377. <note>
  378. Usually, "2" gets you to the main console and "3" gets you
  379. to the serial console.
  380. </note>
  381. </para></listitem>
  382. <listitem><para><emphasis>Removing the Splash Screen:</emphasis>
  383. You can remove the splash screen when QEMU is booting by
  384. using Alt+left.
  385. Removing the splash screen allows you to see what is happening
  386. in the background.
  387. </para></listitem>
  388. <listitem><para><emphasis>Disabling the Cursor Grab:</emphasis>
  389. The default QEMU integration captures the cursor within the
  390. main window.
  391. It does this since standard mouse devices only provide relative
  392. input and not absolute coordinates.
  393. You then have to break out of the grab using the "Ctrl+Alt" key
  394. combination.
  395. However, the Yocto Project's integration of QEMU enables the
  396. wacom USB touch pad driver by default to allow input of absolute
  397. coordinates.
  398. This default means that the mouse can enter and leave the
  399. main window without the grab taking effect leading to a better
  400. user experience.
  401. </para></listitem>
  402. </itemizedlist>
  403. </para>
  404. </section>
  405. </chapter>
  406. <!--
  407. vim: expandtab tw=80 ts=4
  408. -->