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