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