blob: 903028f5cf58f01f2834a1a71bafe9d2502bf787 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!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>
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500200 <listitem><para id='kvm-cond'><filename>kvm</filename>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500201 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
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500207qemux86" or "qemux86-64".
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500208 </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>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 The build host <filename>/dev/kvm</filename>
216 directory has to be both writable and readable.
217 </para></listitem>
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500218 </itemizedlist>
219 </para></listitem>
220 <listitem><para><filename>kvm-vhost</filename>:
221 Enables KVM with VHOST support when running "qemux86" or "qemux86-64"
222 QEMU architectures.
223 For KVM with VHOST to work, the following conditions must
224 be met:
225 <itemizedlist>
226 <listitem><para>
227 <link linkend='kvm-cond'>kvm</link> option
228 conditions must be met.
229 </para></listitem>
230 <listitem><para>
231 Your build host has to have virtio net device, which
232 are <filename>/dev/vhost-net</filename>.
233 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 <listitem><para>
235 The build host <filename>/dev/vhost-net</filename>
236 directory has to be either readable or writable
237 and “slirp-enabled”.
238 </para></listitem>
239 </itemizedlist>
240 </para></listitem>
241 <listitem><para><filename>publicvnc</filename>:
242 Enables a VNC server open to all hosts.
243 </para></listitem>
244 </itemizedlist>
245 </para>
246
247 <para>
248 For further understanding regarding option use with
249 <filename>runqemu</filename>, consider some examples.
250 </para>
251
252 <para>
253 This example starts QEMU with
254 <replaceable>MACHINE</replaceable> set to "qemux86".
255 Assuming a standard
256 <link linkend='build-directory'>Build Directory</link>,
257 <filename>runqemu</filename> automatically finds the
258 <filename>bzImage-qemux86.bin</filename> image file and
259 the
260 <filename>core-image-minimal-qemux86-20140707074611.rootfs.ext3</filename>
261 (assuming the current build created a
262 <filename>core-image-minimal</filename> image).
263 <note>
264 When more than one image with the same name exists, QEMU finds
265 and uses the most recently built image according to the
266 timestamp.
267 </note>
268 <literallayout class='monospaced'>
269 $ runqemu qemux86
270 </literallayout>
271 This example produces the exact same results as the
272 previous example.
273 This command, however, specifically provides the image
274 and root filesystem type.
275 <literallayout class='monospaced'>
276 $ runqemu qemux86 core-image-minimal ext3
277 </literallayout>
278 This example specifies to boot an initial RAM disk image
279 and to enable audio in QEMU.
280 For this case, <filename>runqemu</filename> set the
281 internal variable <filename>FSTYPE</filename> to
282 "cpio.gz".
283 Also, for audio to be enabled, an appropriate driver must
284 be installed (see the previous description for the
285 <filename>audio</filename> option for more information).
286 <literallayout class='monospaced'>
287 $ runqemu qemux86 ramfs audio
288 </literallayout>
289 This example does not provide enough information for
290 QEMU to launch.
291 While the command does provide a root filesystem type, it
292 must also minimally provide a
293 <replaceable>MACHINE</replaceable>,
294 <replaceable>KERNEL</replaceable>, or
295 <replaceable>VM</replaceable> option.
296 <literallayout class='monospaced'>
297 $ runqemu ext3
298 </literallayout>
299 This example specifies to boot a virtual machine image
300 (<filename>.vmdk</filename> file).
301 From the <filename>.vmdk</filename>,
302 <filename>runqemu</filename> determines the QEMU
303 architecture (<replaceable>MACHINE</replaceable>) to be
304 "qemux86" and the root filesystem type to be "vmdk".
305 <literallayout class='monospaced'>
306 $ runqemu /home/scott-lenovo/vm/core-image-minimal-qemux86.vmdk
307 </literallayout>
308 </para>
309 </section>
310</section>
311
312<section id='qemu-running-under-a-network-file-system-nfs-server'>
313 <title>Running Under a Network File System (NFS) Server</title>
314
315 <para>
316 One method for running QEMU is to run it on an NFS server.
317 This is useful when you need to access the same file system from both
318 the build and the emulated system at the same time.
319 It is also worth noting that the system does not need root privileges
320 to run.
321 It uses a user space NFS server to avoid that.
322 This section describes how to set up for running QEMU using an NFS
323 server and then how you can start and stop the server.
324 </para>
325
326 <section id='qemu-setting-up-to-use-nfs'>
327 <title>Setting Up to Use NFS</title>
328
329 <para>
330 Once you are able to run QEMU in your environment, you can use the
331 <filename>runqemu-extract-sdk</filename> script, which is located
332 in the <filename>scripts</filename> directory along with
333 <filename>runqemu</filename> script.
334 The <filename>runqemu-extract-sdk</filename> takes a root
335 file system tarball and extracts it into a location that you
336 specify.
337 Then, when you run <filename>runqemu</filename>, you can specify
338 the location that has the file system to pass it to QEMU.
339 Here is an example that takes a file system and extracts it to
340 a directory named <filename>test-nfs</filename>:
341 <literallayout class='monospaced'>
342 runqemu-extract-sdk ./tmp/deploy/images/qemux86/core-image-sato-qemux86.tar.bz2 test-nfs
343 </literallayout>
344 Once you have extracted the file system, you can run
345 <filename>runqemu</filename> normally with the additional
346 location of the file system.
347 You can then also make changes to the files within
348 <filename>./test-nfs</filename> and see those changes appear in the
349 image in real time.
350 Here is an example using the <filename>qemux86</filename> image:
351 <literallayout class='monospaced'>
352 runqemu qemux86 ./test-nfs
353 </literallayout>
354 </para>
355 </section>
356
357 <section id='qemu-starting-and-stopping-nfs'>
358 <title>Starting and Stopping NFS</title>
359
360 <para>
361 You can manually start and stop the NFS share using these
362 commands:
363 <itemizedlist>
364 <listitem><para><emphasis><filename>start</filename>:</emphasis>
365 Starts the NFS share:
366 <literallayout class='monospaced'>
367 runqemu-export-rootfs start <replaceable>file-system-location</replaceable>
368 </literallayout>
369 </para></listitem>
370 <listitem><para><emphasis><filename>stop</filename>:</emphasis>
371 Stops the NFS share:
372 <literallayout class='monospaced'>
373 runqemu-export-rootfs stop <replaceable>file-system-location</replaceable>
374 </literallayout>
375 </para></listitem>
376 <listitem><para><emphasis><filename>restart</filename>:</emphasis>
377 Restarts the NFS share:
378 <literallayout class='monospaced'>
379 runqemu-export-rootfs restart <replaceable>file-system-location</replaceable>
380 </literallayout>
381 </para></listitem>
382 </itemizedlist>
383 </para>
384 </section>
385</section>
386
387<section id='qemu-tips-and-tricks'>
388 <title>Tips and Tricks</title>
389
390 <para>
391 The following list describes things you can do to make running QEMU
392 in the context of the Yocto Project a better experience:
393 <itemizedlist>
394 <listitem><para><emphasis>Switching Between Consoles:</emphasis>
395 When booting or running QEMU, you can switch between
396 supported consoles by using
397 Ctrl+Alt+<replaceable>number</replaceable>.
398 For example, Ctrl+Alt+3 switches you to the serial console as
399 long as that console is enabled.
400 Being able to switch consoles is helpful, for example, if the
401 main QEMU console breaks for some reason.
402 <note>
403 Usually, "2" gets you to the main console and "3" gets you
404 to the serial console.
405 </note>
406 </para></listitem>
407 <listitem><para><emphasis>Removing the Splash Screen:</emphasis>
408 You can remove the splash screen when QEMU is booting by
409 using Alt+left.
410 Removing the splash screen allows you to see what is happening
411 in the background.
412 </para></listitem>
413 <listitem><para><emphasis>Disabling the Cursor Grab:</emphasis>
414 The default QEMU integration captures the cursor within the
415 main window.
416 It does this since standard mouse devices only provide relative
417 input and not absolute coordinates.
418 You then have to break out of the grab using the "Ctrl+Alt" key
419 combination.
420 However, the Yocto Project's integration of QEMU enables the
421 wacom USB touch pad driver by default to allow input of absolute
422 coordinates.
423 This default means that the mouse can enter and leave the
424 main window without the grab taking effect leading to a better
425 user experience.
426 </para></listitem>
427 </itemizedlist>
428 </para>
429</section>
430
431</chapter>
432<!--
433vim: expandtab tw=80 ts=4
434-->