4.2. Running QEMU

To use QEMU, you need to have QEMU installed and initialized as well as have the proper artifacts (i.e. image files and root filesystems) available. Follow these general steps to run QEMU:

  1. Install QEMU: QEMU is made available with the Yocto Project a number of ways. One method is to install a Software Development Kit (SDK). See "The QEMU Emulator" section in the Yocto Project Application Development and the Extensible Software Development Kit (eSDK) manual for information on how to install QEMU.

  2. Setting Up the Environment: How you set up the QEMU environment depends on how you installed QEMU:

    • If you cloned the poky repository or you downloaded and unpacked a Yocto Project release tarball, you can source the build environment script (i.e. oe-init-build-env):

           $ cd ~/poky
           $ source oe-init-build-env
                                  

    • If you installed a cross-toolchain, you can run the script that initializes the toolchain. For example, the following commands run the initialization script from the default poky_sdk directory:

           . ~/poky_sdk/environment-setup-core2-64-poky-linux
                                  

  3. Ensure the Artifacts are in Place: You need to be sure you have a pre-built kernel that will boot in QEMU. You also need the target root filesystem for your target machine’s architecture:

    • If you have previously built an image for QEMU (e.g. qemux86, qemuarm, and so forth), then the artifacts are in place in your Build Directory.

    • If you have not built an image, you can go to the machines/qemu area and download a pre-built image that matches your architecture and can be run on QEMU.

    See the "Extracting the Root Filesystem" section in the Yocto Project Application Development and the Extensible Software Development Kit (eSDK) manual for information on how to extract a root filesystem.

  4. Run QEMU: The basic runqemu command syntax is as follows:

         $ runqemu [option ]  [...]
                        

    Based on what you provide on the command line, runqemu does a good job of figuring out what you are trying to do. For example, by default, QEMU looks for the most recently built image according to the timestamp when it needs to look for an image. Minimally, through the use of options, you must provide either a machine name, a virtual machine image (*wic.vmdk), or a kernel image (*.bin).

    Here are some additional examples to help illustrate further QEMU:

    • This example starts QEMU with MACHINE set to "qemux86". Assuming a standard Build Directory, runqemu automatically finds the bzImage-qemux86.bin image file and the core-image-minimal-qemux86-20140707074611.rootfs.ext3 (assuming the current build created a core-image-minimal image).

      Note

      When more than one image with the same name exists, QEMU finds and uses the most recently built image according to the timestamp.

           $ runqemu qemux86
                                  

    • This example produces the exact same results as the previous example. This command, however, specifically provides the image and root filesystem type.

           $ runqemu qemux86 core-image-minimal ext3
                                  

    • This example specifies to boot an initial RAM disk image and to enable audio in QEMU. For this case, runqemu set the internal variable FSTYPE to "cpio.gz". Also, for audio to be enabled, an appropriate driver must be installed (see the previous description for the audio option for more information).

           $ runqemu qemux86 ramfs audio
                                  

    • This example does not provide enough information for QEMU to launch. While the command does provide a root filesystem type, it must also minimally provide a MACHINE, KERNEL, or VM option.

           $ runqemu ext3
                                  

    • This example specifies to boot a virtual machine image (.wic.vmdk file). From the .wic.vmdk, runqemu determines the QEMU architecture (MACHINE) to be "qemux86" and the root filesystem type to be "vmdk".

           $ runqemu /home/scott-lenovo/vm/core-image-minimal-qemux86.wic.vmdk