dev-manual-qemu.xml 20 KB

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