blob: 85e73158720f120f469e4e20210096c450f2e87c [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010 This chapter provides procedures that show you how to use the
11 Quick EMUlator (QEMU), which is an Open Source project the Yocto
12 Project uses as part of its development "tool set".
13 For reference information on the Yocto Project implementation of QEMU,
14 see the
15 "<ulink url='&YOCTO_DOCS_REF_URL;#ref-quick-emulator-qemu'>Quick EMUlator (QEMU)</ulink>"
16 section in the Yocto Project Reference Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017 </para>
18
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019 <section id='qemu-running-qemu'>
20 <title>Running QEMU</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021
22 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023 To use QEMU, you need to have QEMU installed and initialized as
24 well as have the proper artifacts (i.e. image files and root
25 filesystems) available.
26 Follow these general steps to run QEMU:
27 <orderedlist>
28 <listitem><para>
29 <emphasis>Install QEMU:</emphasis>
30 See
31 "<ulink url='&YOCTO_DOCS_SDK_URL;#the-qemu-emulator'>The QEMU Emulator</ulink>"
32 section in the Yocto Project Application Development and
33 the Extensible Software Development Kit (eSDK) manual
34 for information on how to install QEMU.
35 </para></listitem>
36 <listitem><para>
37 <emphasis>Setting Up the Environment:</emphasis>
38 How you set up the QEMU environment depends on how you
39 installed QEMU:
40 <itemizedlist>
41 <listitem><para>
42 If you cloned the <filename>poky</filename>
43 repository or you downloaded and unpacked a
44 Yocto Project release tarball, you can source
45 the build environment script (i.e.
46 <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>):
47 <literallayout class='monospaced'>
48 $ cd ~/poky
49 $ source oe-init-build-env
50 </literallayout>
51 </para></listitem>
52 <listitem><para>
53 If you installed a cross-toolchain, you can
54 run the script that initializes the toolchain.
55 For example, the following commands run the
56 initialization script from the default
57 <filename>poky_sdk</filename> directory:
58 <literallayout class='monospaced'>
59 . ~/poky_sdk/environment-setup-core2-64-poky-linux
60 </literallayout>
61 </para></listitem>
62 </itemizedlist>
63 </para></listitem>
64 <listitem><para>
65 <emphasis>Ensure the Artifacts are in Place:</emphasis>
66 You need to be sure you have a pre-built kernel that
67 will boot in QEMU.
68 You also need the target root filesystem for your target
69 machine’s architecture:
70 <itemizedlist>
71 <listitem><para>
72 If you have previously built an image for QEMU
73 (e.g. <filename>qemux86</filename>,
74 <filename>qemuarm</filename>, and so forth),
75 then the artifacts are in place in your
76 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
77 </para></listitem>
78 <listitem><para>
79 If you have not built an image, you can go to the
80 <ulink url='&YOCTO_MACHINES_DL_URL;'>machines/qemu</ulink>
81 area and download a pre-built image that matches
82 your architecture and can be run on QEMU.
83 </para></listitem>
84 </itemizedlist></para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085
Brad Bishopd7bf8c12018-02-25 22:55:05 -050086 <para>See the
87 "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-extracting-the-root-filesystem'>Extracting the Root Filesystem</ulink>"
88 section in the Yocto Project Application Development and
89 the Extensible Software Development Kit (eSDK) manual
90 for information on how to extract a root filesystem.
91 </para></listitem>
92 <listitem><para>
93 <emphasis>Run QEMU:</emphasis>
94 The basic <filename>runqemu</filename> command syntax is as
95 follows:
96 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 $ runqemu [<replaceable>option</replaceable> ] [...]
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098 </literallayout>
99 Based on what you provide on the command line,
100 <filename>runqemu</filename> does a good job of figuring
101 out what you are trying to do.
102 For example, by default, QEMU looks for the most recently
103 built image according to the timestamp when it needs to
104 look for an image.
105 Minimally, through the use of options, you must provide
106 either a machine name, a virtual machine image
107 (<filename>*wic.vmdk</filename>), or a kernel image
108 (<filename>*.bin</filename>).</para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 <para>Here are some additional examples to help illustrate
111 further QEMU:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 <itemizedlist>
113 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500114 This example starts QEMU with
115 <replaceable>MACHINE</replaceable> set to "qemux86".
116 Assuming a standard
117 <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>,
118 <filename>runqemu</filename> automatically finds the
119 <filename>bzImage-qemux86.bin</filename> image file and
120 the
121 <filename>core-image-minimal-qemux86-20140707074611.rootfs.ext3</filename>
122 (assuming the current build created a
123 <filename>core-image-minimal</filename> image).
124 <note>
125 When more than one image with the same name exists, QEMU finds
126 and uses the most recently built image according to the
127 timestamp.
128 </note>
129 <literallayout class='monospaced'>
130 $ runqemu qemux86
131 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132 </para></listitem>
133 <listitem><para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500134 This example produces the exact same results as the
135 previous example.
136 This command, however, specifically provides the image
137 and root filesystem type.
138 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 $ runqemu qemux86 core-image-minimal ext3
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140 </literallayout>
141 </para></listitem>
142 <listitem><para>
143 This example specifies to boot an initial RAM disk image
144 and to enable audio in QEMU.
145 For this case, <filename>runqemu</filename> set the
146 internal variable <filename>FSTYPE</filename> to
147 "cpio.gz".
148 Also, for audio to be enabled, an appropriate driver must
149 be installed (see the previous description for the
150 <filename>audio</filename> option for more information).
151 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 $ runqemu qemux86 ramfs audio
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500153 </literallayout>
154 </para></listitem>
155 <listitem><para>
156 This example does not provide enough information for
157 QEMU to launch.
158 While the command does provide a root filesystem type, it
159 must also minimally provide a
160 <replaceable>MACHINE</replaceable>,
161 <replaceable>KERNEL</replaceable>, or
162 <replaceable>VM</replaceable> option.
163 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 $ runqemu ext3
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500165 </literallayout>
166 </para></listitem>
167 <listitem><para>
168 This example specifies to boot a virtual machine
169 image (<filename>.wic.vmdk</filename> file).
170 From the <filename>.wic.vmdk</filename>,
171 <filename>runqemu</filename> determines the QEMU
172 architecture (<replaceable>MACHINE</replaceable>) to be
173 "qemux86" and the root filesystem type to be "vmdk".
174 <literallayout class='monospaced'>
175 $ runqemu /home/scott-lenovo/vm/core-image-minimal-qemux86.wic.vmdk
176 </literallayout>
177 </para></listitem>
178 </itemizedlist>
179 </para></listitem>
180 </orderedlist>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181 </para>
182 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500184 <section id='switching-between-consoles'>
185 <title>Switching Between Consoles</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
187 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500188 When booting or running QEMU, you can switch between
189 supported consoles by using
190 Ctrl+Alt+<replaceable>number</replaceable>.
191 For example, Ctrl+Alt+3 switches you to the serial console
192 as long as that console is enabled.
193 Being able to switch consoles is helpful, for example, if
194 the main QEMU console breaks for some reason.
195 <note>
196 Usually, "2" gets you to the main console and "3"
197 gets you to the serial console.
198 </note>
199 </para>
200 </section>
201
202 <section id='removing-the-splash-screen'>
203 <title>Removing the Splash Screen</title>
204
205 <para>
206 You can remove the splash screen when QEMU is booting by
207 using Alt+left.
208 Removing the splash screen allows you to see what is
209 happening in the background.
210 </para>
211 </section>
212
213 <section id='disabling-the-cursor-grab'>
214 <title>Disabling the Cursor Grab</title>
215
216 <para>
217 The default QEMU integration captures the cursor within the
218 main window.
219 It does this since standard mouse devices only provide
220 relative input and not absolute coordinates.
221 You then have to break out of the grab using the "Ctrl+Alt"
222 key combination.
223 However, the Yocto Project's integration of QEMU enables
224 the wacom USB touch pad driver by default to allow input
225 of absolute coordinates.
226 This default means that the mouse can enter and leave the
227 main window without the grab taking effect leading to a
228 better user experience.
229 </para>
230 </section>
231
232 <section id='qemu-running-under-a-network-file-system-nfs-server'>
233 <title>Running Under a Network File System (NFS) Server</title>
234
235 <para>
236 One method for running QEMU is to run it on an NFS server.
237 This is useful when you need to access the same file system
238 from both the build and the emulated system at the same time.
239 It is also worth noting that the system does not need root
240 privileges to run.
241 It uses a user space NFS server to avoid that.
242 Follow these steps to set up for running QEMU using an NFS
243 server.
244 <orderedlist>
245 <listitem><para>
246 <emphasis>Extract a Root Filesystem:</emphasis>
247 Once you are able to run QEMU in your environment, you can
248 use the <filename>runqemu-extract-sdk</filename> script,
249 which is located in the <filename>scripts</filename>
250 directory along with the <filename>runqemu</filename>
251 script.</para>
252
253 <para>The <filename>runqemu-extract-sdk</filename> takes a
254 root filesystem tarball and extracts it into a location
255 that you specify.
256 Here is an example that takes a file system and
257 extracts it to a directory named
258 <filename>test-nfs</filename>:
259 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260 runqemu-extract-sdk ./tmp/deploy/images/qemux86/core-image-sato-qemux86.tar.bz2 test-nfs
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500261 </literallayout>
262 </para></listitem>
263 <listitem><para>
264 <emphasis>Start QEMU:</emphasis>
265 Once you have extracted the file system, you can run
266 <filename>runqemu</filename> normally with the additional
267 location of the file system.
268 You can then also make changes to the files within
269 <filename>./test-nfs</filename> and see those changes
270 appear in the image in real time.
271 Here is an example using the <filename>qemux86</filename>
272 image:
273 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500274 runqemu qemux86 ./test-nfs
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500275 </literallayout>
276 </para></listitem>
277 </orderedlist>
278 <note>
279 <para>
280 Should you need to start, stop, or restart the NFS share,
281 you can use the following commands:
282 <itemizedlist>
283 <listitem><para>
284 The following command starts the NFS share:
285 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286 runqemu-export-rootfs start <replaceable>file-system-location</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500287 </literallayout>
288 </para></listitem>
289 <listitem><para>
290 The following command stops the NFS share:
291 <literallayout class='monospaced'>
292 runqemu-export-rootfs stop <replaceable>file-system-location</replaceable>
293 </literallayout>
294 </para></listitem>
295 <listitem><para>
296 The following command restarts the NFS share:
297 <literallayout class='monospaced'>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 runqemu-export-rootfs restart <replaceable>file-system-location</replaceable>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500299 </literallayout>
300 </para></listitem>
301 </itemizedlist>
302 </para>
303 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304 </para>
305 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306</chapter>
307<!--
308vim: expandtab tw=80 ts=4
309-->