diff options
Diffstat (limited to 'documentation/dev-manual/qemu.rst')
-rw-r--r-- | documentation/dev-manual/qemu.rst | 118 |
1 files changed, 63 insertions, 55 deletions
diff --git a/documentation/dev-manual/qemu.rst b/documentation/dev-manual/qemu.rst index 766691b97b..19f3e40d63 100644 --- a/documentation/dev-manual/qemu.rst +++ b/documentation/dev-manual/qemu.rst | |||
@@ -44,31 +44,29 @@ To use QEMU, you need to have QEMU installed and initialized as well as | |||
44 | have the proper artifacts (i.e. image files and root filesystems) | 44 | have the proper artifacts (i.e. image files and root filesystems) |
45 | available. Follow these general steps to run QEMU: | 45 | available. Follow these general steps to run QEMU: |
46 | 46 | ||
47 | 1. *Install QEMU:* QEMU is made available with the Yocto Project a | 47 | #. *Install QEMU:* QEMU is made available with the Yocto Project a |
48 | number of ways. One method is to install a Software Development Kit | 48 | number of ways. One method is to install a Software Development Kit |
49 | (SDK). See ":ref:`sdk-manual/intro:the qemu emulator`" section in the | 49 | (SDK). See ":ref:`sdk-manual/intro:the qemu emulator`" section in the |
50 | Yocto Project Application Development and the Extensible Software | 50 | Yocto Project Application Development and the Extensible Software |
51 | Development Kit (eSDK) manual for information on how to install QEMU. | 51 | Development Kit (eSDK) manual for information on how to install QEMU. |
52 | 52 | ||
53 | 2. *Setting Up the Environment:* How you set up the QEMU environment | 53 | #. *Setting Up the Environment:* How you set up the QEMU environment |
54 | depends on how you installed QEMU: | 54 | depends on how you installed QEMU: |
55 | 55 | ||
56 | - If you cloned the ``poky`` repository or you downloaded and | 56 | - If you cloned the ``poky`` repository or you downloaded and |
57 | unpacked a Yocto Project release tarball, you can source the build | 57 | unpacked a Yocto Project release tarball, you can source the build |
58 | environment script (i.e. :ref:`structure-core-script`): | 58 | environment script (i.e. :ref:`structure-core-script`):: |
59 | :: | ||
60 | 59 | ||
61 | $ cd ~/poky | 60 | $ cd poky |
62 | $ source oe-init-build-env | 61 | $ source oe-init-build-env |
63 | 62 | ||
64 | - If you installed a cross-toolchain, you can run the script that | 63 | - If you installed a cross-toolchain, you can run the script that |
65 | initializes the toolchain. For example, the following commands run | 64 | initializes the toolchain. For example, the following commands run |
66 | the initialization script from the default ``poky_sdk`` directory: | 65 | the initialization script from the default ``poky_sdk`` directory:: |
67 | :: | ||
68 | 66 | ||
69 | . ~/poky_sdk/environment-setup-core2-64-poky-linux | 67 | . poky_sdk/environment-setup-core2-64-poky-linux |
70 | 68 | ||
71 | 3. *Ensure the Artifacts are in Place:* You need to be sure you have a | 69 | #. *Ensure the Artifacts are in Place:* You need to be sure you have a |
72 | pre-built kernel that will boot in QEMU. You also need the target | 70 | pre-built kernel that will boot in QEMU. You also need the target |
73 | root filesystem for your target machine's architecture: | 71 | root filesystem for your target machine's architecture: |
74 | 72 | ||
@@ -86,8 +84,7 @@ available. Follow these general steps to run QEMU: | |||
86 | Extensible Software Development Kit (eSDK) manual for information on | 84 | Extensible Software Development Kit (eSDK) manual for information on |
87 | how to extract a root filesystem. | 85 | how to extract a root filesystem. |
88 | 86 | ||
89 | 4. *Run QEMU:* The basic ``runqemu`` command syntax is as follows: | 87 | #. *Run QEMU:* The basic ``runqemu`` command syntax is as follows:: |
90 | :: | ||
91 | 88 | ||
92 | $ runqemu [option ] [...] | 89 | $ runqemu [option ] [...] |
93 | 90 | ||
@@ -102,12 +99,13 @@ available. Follow these general steps to run QEMU: | |||
102 | Here are some additional examples to help illustrate further QEMU: | 99 | Here are some additional examples to help illustrate further QEMU: |
103 | 100 | ||
104 | - This example starts QEMU with MACHINE set to "qemux86-64". | 101 | - This example starts QEMU with MACHINE set to "qemux86-64". |
105 | Assuming a standard | 102 | Assuming a standard :term:`Build Directory`, ``runqemu`` |
106 | :term:`Build Directory`, ``runqemu`` | ||
107 | automatically finds the ``bzImage-qemux86-64.bin`` image file and | 103 | automatically finds the ``bzImage-qemux86-64.bin`` image file and |
108 | the ``core-image-minimal-qemux86-64-20200218002850.rootfs.ext4`` | 104 | the ``core-image-minimal-qemux86-64-20200218002850.rootfs.ext4`` |
109 | (assuming the current build created a ``core-image-minimal`` | 105 | (assuming the current build created a ``core-image-minimal`` |
110 | image). | 106 | image):: |
107 | |||
108 | $ runqemu qemux86-64 | ||
111 | 109 | ||
112 | .. note:: | 110 | .. note:: |
113 | 111 | ||
@@ -115,38 +113,31 @@ available. Follow these general steps to run QEMU: | |||
115 | and uses the most recently built image according to the | 113 | and uses the most recently built image according to the |
116 | timestamp. | 114 | timestamp. |
117 | 115 | ||
118 | :: | ||
119 | |||
120 | $ runqemu qemux86-64 | ||
121 | |||
122 | - This example produces the exact same results as the previous | 116 | - This example produces the exact same results as the previous |
123 | example. This command, however, specifically provides the image | 117 | example. This command, however, specifically provides the image |
124 | and root filesystem type. | 118 | and root filesystem type:: |
125 | :: | ||
126 | 119 | ||
127 | $ runqemu qemux86-64 core-image-minimal ext4 | 120 | $ runqemu qemux86-64 core-image-minimal ext4 |
128 | 121 | ||
129 | - This example specifies to boot an initial RAM disk image and to | 122 | - This example specifies to boot an :term:`Initramfs` image and to |
130 | enable audio in QEMU. For this case, ``runqemu`` set the internal | 123 | enable audio in QEMU. For this case, ``runqemu`` sets the internal |
131 | variable ``FSTYPE`` to "cpio.gz". Also, for audio to be enabled, | 124 | variable ``FSTYPE`` to ``cpio.gz``. Also, for audio to be enabled, |
132 | an appropriate driver must be installed (see the previous | 125 | an appropriate driver must be installed (see the ``audio`` option |
133 | description for the ``audio`` option for more information). | 126 | in :ref:`dev-manual/qemu:\`\`runqemu\`\` command-line options` |
134 | :: | 127 | for more information):: |
135 | 128 | ||
136 | $ runqemu qemux86-64 ramfs audio | 129 | $ runqemu qemux86-64 ramfs audio |
137 | 130 | ||
138 | - This example does not provide enough information for QEMU to | 131 | - This example does not provide enough information for QEMU to |
139 | launch. While the command does provide a root filesystem type, it | 132 | launch. While the command does provide a root filesystem type, it |
140 | must also minimally provide a `MACHINE`, `KERNEL`, or `VM` option. | 133 | must also minimally provide a `MACHINE`, `KERNEL`, or `VM` option:: |
141 | :: | ||
142 | 134 | ||
143 | $ runqemu ext4 | 135 | $ runqemu ext4 |
144 | 136 | ||
145 | - This example specifies to boot a virtual machine image | 137 | - This example specifies to boot a virtual machine image |
146 | (``.wic.vmdk`` file). From the ``.wic.vmdk``, ``runqemu`` | 138 | (``.wic.vmdk`` file). From the ``.wic.vmdk``, ``runqemu`` |
147 | determines the QEMU architecture (`MACHINE`) to be "qemux86-64" and | 139 | determines the QEMU architecture (`MACHINE`) to be "qemux86-64" and |
148 | the root filesystem type to be "vmdk". | 140 | the root filesystem type to be "vmdk":: |
149 | :: | ||
150 | 141 | ||
151 | $ runqemu /home/scott-lenovo/vm/core-image-minimal-qemux86-64.wic.vmdk | 142 | $ runqemu /home/scott-lenovo/vm/core-image-minimal-qemux86-64.wic.vmdk |
152 | 143 | ||
@@ -193,7 +184,7 @@ the system does not need root privileges to run. It uses a user space | |||
193 | NFS server to avoid that. Follow these steps to set up for running QEMU | 184 | NFS server to avoid that. Follow these steps to set up for running QEMU |
194 | using an NFS server. | 185 | using an NFS server. |
195 | 186 | ||
196 | 1. *Extract a Root Filesystem:* Once you are able to run QEMU in your | 187 | #. *Extract a Root Filesystem:* Once you are able to run QEMU in your |
197 | environment, you can use the ``runqemu-extract-sdk`` script, which is | 188 | environment, you can use the ``runqemu-extract-sdk`` script, which is |
198 | located in the ``scripts`` directory along with the ``runqemu`` | 189 | located in the ``scripts`` directory along with the ``runqemu`` |
199 | script. | 190 | script. |
@@ -207,7 +198,7 @@ using an NFS server. | |||
207 | 198 | ||
208 | runqemu-extract-sdk ./tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64.tar.bz2 test-nfs | 199 | runqemu-extract-sdk ./tmp/deploy/images/qemux86-64/core-image-sato-qemux86-64.tar.bz2 test-nfs |
209 | 200 | ||
210 | 2. *Start QEMU:* Once you have extracted the file system, you can run | 201 | #. *Start QEMU:* Once you have extracted the file system, you can run |
211 | ``runqemu`` normally with the additional location of the file system. | 202 | ``runqemu`` normally with the additional location of the file system. |
212 | You can then also make changes to the files within ``./test-nfs`` and | 203 | You can then also make changes to the files within ``./test-nfs`` and |
213 | see those changes appear in the image in real time. Here is an | 204 | see those changes appear in the image in real time. Here is an |
@@ -222,18 +213,15 @@ using an NFS server. | |||
222 | Should you need to start, stop, or restart the NFS share, you can use | 213 | Should you need to start, stop, or restart the NFS share, you can use |
223 | the following commands: | 214 | the following commands: |
224 | 215 | ||
225 | - The following command starts the NFS share: | 216 | - To start the NFS share:: |
226 | :: | ||
227 | 217 | ||
228 | runqemu-export-rootfs start file-system-location | 218 | runqemu-export-rootfs start file-system-location |
229 | 219 | ||
230 | - The following command stops the NFS share: | 220 | - To stop the NFS share:: |
231 | :: | ||
232 | 221 | ||
233 | runqemu-export-rootfs stop file-system-location | 222 | runqemu-export-rootfs stop file-system-location |
234 | 223 | ||
235 | - The following command restarts the NFS share: | 224 | - To restart the NFS share:: |
236 | :: | ||
237 | 225 | ||
238 | runqemu-export-rootfs restart file-system-location | 226 | runqemu-export-rootfs restart file-system-location |
239 | 227 | ||
@@ -252,11 +240,10 @@ be a problem when QEMU is running with KVM enabled. Specifically, | |||
252 | software compiled with a certain CPU feature crashes when run on a CPU | 240 | software compiled with a certain CPU feature crashes when run on a CPU |
253 | under KVM that does not support that feature. To work around this | 241 | under KVM that does not support that feature. To work around this |
254 | problem, you can override QEMU's runtime CPU setting by changing the | 242 | problem, you can override QEMU's runtime CPU setting by changing the |
255 | ``QB_CPU_KVM`` variable in ``qemuboot.conf`` in the | 243 | ``QB_CPU_KVM`` variable in ``qemuboot.conf`` in the :term:`Build Directory` |
256 | :term:`Build Directory` ``deploy/image`` | 244 | ``deploy/image`` directory. This setting specifies a ``-cpu`` option passed |
257 | directory. This setting specifies a ``-cpu`` option passed into QEMU in | 245 | into QEMU in the ``runqemu`` script. Running ``qemu -cpu help`` returns a |
258 | the ``runqemu`` script. Running ``qemu -cpu help`` returns a list of | 246 | list of available supported CPU types. |
259 | available supported CPU types. | ||
260 | 247 | ||
261 | QEMU Performance | 248 | QEMU Performance |
262 | ================ | 249 | ================ |
@@ -281,7 +268,7 @@ present, the toolchain is also automatically used. | |||
281 | 268 | ||
282 | .. note:: | 269 | .. note:: |
283 | 270 | ||
284 | Several mechanisms exist that let you connect to the system running | 271 | There are several mechanisms to connect to the system running |
285 | on the QEMU emulator: | 272 | on the QEMU emulator: |
286 | 273 | ||
287 | - QEMU provides a framebuffer interface that makes standard consoles | 274 | - QEMU provides a framebuffer interface that makes standard consoles |
@@ -292,7 +279,7 @@ present, the toolchain is also automatically used. | |||
292 | that port to run a console. The connection uses standard IP | 279 | that port to run a console. The connection uses standard IP |
293 | networking. | 280 | networking. |
294 | 281 | ||
295 | - SSH servers exist in some QEMU images. The ``core-image-sato`` | 282 | - SSH servers are available in some QEMU images. The ``core-image-sato`` |
296 | QEMU image has a Dropbear secure shell (SSH) server that runs with | 283 | QEMU image has a Dropbear secure shell (SSH) server that runs with |
297 | the root password disabled. The ``core-image-full-cmdline`` and | 284 | the root password disabled. The ``core-image-full-cmdline`` and |
298 | ``core-image-lsb`` QEMU images have OpenSSH instead of Dropbear. | 285 | ``core-image-lsb`` QEMU images have OpenSSH instead of Dropbear. |
@@ -306,15 +293,14 @@ present, the toolchain is also automatically used. | |||
306 | tarball by using the ``runqemu-extract-sdk`` command. After | 293 | tarball by using the ``runqemu-extract-sdk`` command. After |
307 | running the command, you must then point the ``runqemu`` script to | 294 | running the command, you must then point the ``runqemu`` script to |
308 | the extracted directory instead of a root filesystem image file. | 295 | the extracted directory instead of a root filesystem image file. |
309 | See the "`Running Under a Network File System (NFS) | 296 | See the |
310 | Server <#qemu-running-under-a-network-file-system-nfs-server>`__" | 297 | ":ref:`dev-manual/qemu:running under a network file system (nfs) server`" |
311 | section for more information. | 298 | section for more information. |
312 | 299 | ||
313 | QEMU Command-Line Syntax | 300 | QEMU Command-Line Syntax |
314 | ======================== | 301 | ======================== |
315 | 302 | ||
316 | The basic ``runqemu`` command syntax is as follows: | 303 | The basic ``runqemu`` command syntax is as follows:: |
317 | :: | ||
318 | 304 | ||
319 | $ runqemu [option ] [...] | 305 | $ runqemu [option ] [...] |
320 | 306 | ||
@@ -325,8 +311,7 @@ timestamp when it needs to look for an image. Minimally, through the use | |||
325 | of options, you must provide either a machine name, a virtual machine | 311 | of options, you must provide either a machine name, a virtual machine |
326 | image (``*wic.vmdk``), or a kernel image (``*.bin``). | 312 | image (``*wic.vmdk``), or a kernel image (``*.bin``). |
327 | 313 | ||
328 | Following is the command-line help output for the ``runqemu`` command: | 314 | Here is the command-line help output for the ``runqemu`` command:: |
329 | :: | ||
330 | 315 | ||
331 | $ runqemu --help | 316 | $ runqemu --help |
332 | 317 | ||
@@ -338,7 +323,7 @@ Following is the command-line help output for the ``runqemu`` command: | |||
338 | Simplified QEMU command-line options can be passed with: | 323 | Simplified QEMU command-line options can be passed with: |
339 | nographic - disable video console | 324 | nographic - disable video console |
340 | serial - enable a serial console on /dev/ttyS0 | 325 | serial - enable a serial console on /dev/ttyS0 |
341 | slirp - enable user networking, no root privileges is required | 326 | slirp - enable user networking, no root privileges required |
342 | kvm - enable KVM when running x86/x86_64 (VT-capable CPU required) | 327 | kvm - enable KVM when running x86/x86_64 (VT-capable CPU required) |
343 | kvm-vhost - enable KVM with vhost when running x86/x86_64 (VT-capable CPU required) | 328 | kvm-vhost - enable KVM with vhost when running x86/x86_64 (VT-capable CPU required) |
344 | publicvnc - enable a VNC server open to all hosts | 329 | publicvnc - enable a VNC server open to all hosts |
@@ -368,7 +353,7 @@ Following is the command-line help output for the ``runqemu`` command: | |||
368 | ``runqemu`` Command-Line Options | 353 | ``runqemu`` Command-Line Options |
369 | ================================ | 354 | ================================ |
370 | 355 | ||
371 | Following is a description of ``runqemu`` options you can provide on the | 356 | Here is a description of ``runqemu`` options you can provide on the |
372 | command line: | 357 | command line: |
373 | 358 | ||
374 | .. note:: | 359 | .. note:: |
@@ -402,7 +387,7 @@ command line: | |||
402 | options are basically identical. If you do not provide a MACHINE | 387 | options are basically identical. If you do not provide a MACHINE |
403 | option, ``runqemu`` tries to determine it based on other options. | 388 | option, ``runqemu`` tries to determine it based on other options. |
404 | 389 | ||
405 | - ``ramfs``: Indicates you are booting an initial RAM disk (initramfs) | 390 | - ``ramfs``: Indicates you are booting an :term:`Initramfs` |
406 | image, which means the ``FSTYPE`` is ``cpio.gz``. | 391 | image, which means the ``FSTYPE`` is ``cpio.gz``. |
407 | 392 | ||
408 | - ``iso``: Indicates you are booting an ISO image, which means the | 393 | - ``iso``: Indicates you are booting an ISO image, which means the |
@@ -436,6 +421,29 @@ command line: | |||
436 | networking that does not need root access but also is not as easy to | 421 | networking that does not need root access but also is not as easy to |
437 | use or comprehensive as the default. | 422 | use or comprehensive as the default. |
438 | 423 | ||
424 | Using ``slirp`` by default will forward the guest machine's | ||
425 | 22 and 23 TCP ports to host machine's 2222 and 2323 ports | ||
426 | (or the next free ports). Specific forwarding rules can be configured | ||
427 | by setting ``QB_SLIRP_OPT`` as environment variable or in ``qemuboot.conf`` | ||
428 | in the :term:`Build Directory` ``deploy/image`` directory. | ||
429 | Examples:: | ||
430 | |||
431 | QB_SLIRP_OPT="-netdev user,id=net0,hostfwd=tcp::8080-:80" | ||
432 | |||
433 | QB_SLIRP_OPT="-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22" | ||
434 | |||
435 | The first example forwards TCP port 80 from the emulated system to | ||
436 | port 8080 (or the next free port) on the host system, | ||
437 | allowing access to an http server running in QEMU from | ||
438 | ``http://<host ip>:8080/``. | ||
439 | |||
440 | The second example does the same, but also forwards TCP port 22 on the | ||
441 | guest system to 2222 (or the next free port) on the host system, | ||
442 | allowing ssh access to the emulated system using | ||
443 | ``ssh -P 2222 <user>@<host ip>``. | ||
444 | |||
445 | Keep in mind that proper configuration of firewall software is required. | ||
446 | |||
439 | - ``kvm``: Enables KVM when running "qemux86" or "qemux86-64" QEMU | 447 | - ``kvm``: Enables KVM when running "qemux86" or "qemux86-64" QEMU |
440 | architectures. For KVM to work, all the following conditions must be | 448 | architectures. For KVM to work, all the following conditions must be |
441 | met: | 449 | met: |
@@ -452,7 +460,7 @@ command line: | |||
452 | or "qemux86-64" QEMU architectures. For KVM with VHOST to work, the | 460 | or "qemux86-64" QEMU architectures. For KVM with VHOST to work, the |
453 | following conditions must be met: | 461 | following conditions must be met: |
454 | 462 | ||
455 | - `kvm <#kvm-cond>`__ option conditions must be met. | 463 | - ``kvm`` option conditions defined above must be met. |
456 | 464 | ||
457 | - Your build host has to have virtio net device, which are | 465 | - Your build host has to have virtio net device, which are |
458 | ``/dev/vhost-net``. | 466 | ``/dev/vhost-net``. |