Launch Yocto Linux in a virtual machine

Original author: Francesco B.
  • Transfer
During the development process, for example, for Intel Edison or Galileo, it may happen that the device needed for experiments was not at hand. A similar thing happens when there is hardware, but the OS installed on it does not support all the features necessary for the project. What to do?


One solution to this problem is to run the target operating system on a virtual machine. On it you can compile, deploy and test programs. Today we’ll talk about how to create Yocto Linux images suitable for running in virtual environments, for example, in a simple QEMU software emulator. In addition, such images can be used on systems with hypervisors, say, Microsoft Hyper-V on Windows.

Prerequisites


In order to successfully master this guide, you will need the following:

  • Debian / Ubuntu OS (tested on Debian 8.2. Amd64).
  • Internet connection.
  • At least 100 GB of free hard disk space.

Computer preparation


As the root user (or using "sudo"), run the following command on the computer:

# apt-get install wget git-core unzip make gcc g++ build-essential subversion sed autoconf automake texi2html texinfo coreutils diffstat python-pysqlite2 docbook-utils libsdl1.2-dev libxml-parser-perl libgl1-mesa-dev libglu1-mesa-dev xsltproc desktop-file-utils chrpath groff libtool xterm gawk fop

Note No. 1 . The success of this command depends on the version of Ubuntu / Debian you are using. However, you may well, in order to resolve package dependencies, use “aptitude” and force the installation of suitable versions of the necessary packages (for example, with the command: “aptitude install libsdl1.2-dev”).

Note No. 2 . For other Linux distributions, such as RedHat, CentOS, Fedora, SuSe, Gentoo, and so on, we would advise you to search for suitable versions of the above packages using the appropriate package manager (for example, zypper or yum).

Step one. Setting the working directory


These commands must be executed as a regular user; root privileges are not needed.

# cd
# mkdir yocto-2.0
# cd yocto-2.0
# wget http://downloads.yoctoproject.org/releases/yocto/yocto-2.0/poky-jethro-14.0.0.tar.bz2
# tar xvjf poky-jethro-14.0.0.tar.bz2
# cd poky-jethro-14.0.0/

Note No. 3 . Here you can select a different Yocto release branch. In this guide, we use Yocto Poky 2.0.14.0.0 (Jethro).

Note No. 4 . If you want to download the latest release of the Yocto source code, you can refer to the master branch. In this case, you need to change a couple of commands from the above listing to the following:

# git clone git://git.yoctoproject.org/poky.git
# cd poky

Note No. 5 . You can select the desired branch using its code name. For example, like this:

# git clone -b jethro git://git.yoctoproject.org/poky.git

Step Two Setting environment variables


This setup is very simple, it is done using a script from the developers of Yocto.

# . ./oe-init-build-env

After you run the script and it runs successfully, the build folder will become the new workspace. For example, the path to this folder might look like this:

/home//yocto-2.0/poky-jethro-14.0.0/build/.

Step Three Configure BitBake


After executing the script from the previous step, a file was created conf/local.conf.

This configuration file is needed to configure BitBake, the Yocto build system (this is the central component of the Yocto Project).

Edit the BitBake configuration file in any text editor you use. We edited it in the editor nano. This is a simple console text editor for Unix environments. It starts like this:

# cd conf/
# nano local.conf

Uncomment the following lines in the configuration file:

DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
TMPDIR ?= "${TOPDIR}/tmp"
SDKMACHINE ?= "i686"

We advise you to collect images, including all available additional features. Although the resulting image files are rather large (about 8 GB each), they include everything that is possible and, as a result, are suitable for any development task.

EXTRA_IMAGE_FEATURES = "dbg-pkgs dev-pkgs ptest-pkgs tools-sdk tools-debug eclipse-debug tools-profile tools-testapps debug-tweaks"

Save the changes to the file local.conf. In our case, this is done using the keyboard shortcut Ctrl + X. Now run the following commands:

# cd ..
# hob

In response to them, Hob (the graphical interface for BitBake, based on GTK-2) should start. He will begin to verify that the build system is configured correctly.


Checking the build system settings

After checking, select qemux86 from the drop-down menu as the target system.


Choosing the Target System

Wait for the Hob to complete the analysis of the BitBake recipes and generate the dependency tree. Then select the recipe for the target image from the corresponding drop-down list. In this case, the full image is selected without a GUI: core-image-full-cmdline.


Selecting a recipe for assembling the image

After that, click on the “Advanced configuration” button.


Switching to advanced settings

On the “Image types” tab, in the “Distro” menu, select “poky” if you want to build the latest stable release. Then, in the "Image types" list, select the desired image format. Usually it makes sense to select ".iso", ".vdi" and ".vmdk" here. Images in such formats are most convenient for practical use.


Choosing an image format

On the “Output” tab, specify the settings that suit your needs. We recommend adding at least 4 GB of free space to enable the SDK for the i686 architecture (if you are experimenting with the Edison board). In addition, it was found that it is very useful to set “deb” as the format of the root file system. As a result, we came to the following settings.


Image setup

Now you can save your settings by clicking on the “Save” button, and, in the main window, click on the “Build Image” button to start the image assembly process.


Starting the build

Hob will start the instance bitbake core-image-full-cmdlinewith the given settings.


Assembly

Note No. 6 . The build process can take a very long time. But, depending on the capabilities of your computer, you can change the number of threads used during assembly by setting the “BitBake parallel threads” and “Make parallel threads” parameters in the Hob settings window.


Setting the number of threads used in the assembly

Note No. 7 . And finally, when using Hob, you have the opportunity to choose which packages you want to include in the image that you plan to build. In order to do this, before starting the assembly of images, click on the “Edit image recipe” button.


Going to the configuration of packages included in the image

In the window that appears, select the packages you want to add to the image.


Package Selection

When the image build process is complete, you can try them right away! To do this, click on the “Run image” button. Hob will launch QEMU with the qemux86 image just built.


The image is assembled and ready to run.

At the very beginning of the launch, the system will ask you to set the superuser password.


Password Entry

Another UNIX command prompt window will open. In it, you can watch the download indicator on the background of the Yocto Project logo.


Downloading

After downloading, you can log in to the root account of the newly created Yocto image. Remember that by adding a debug parameter (debug-tweak) to the EXTRA_IMAGE_FEATURES variable in the conf / local.conf file, you can log in as a root user without a password. Otherwise, you will need to set a password for the root user in the BitBake recipe before assembling the image.


Login

Now you are ready to start experimenting with the QEMU virtual machine running Yocto Linux.

Note 8 . After assembling the Yocto image using the method described above, 89.8 GB will be occupied on the disk.


Size of data generated during image assembly

Summary


The Yocto Linux images generated during the build can be found at "~ / yocto-2.0 / poky-jethro-14.0.0 / build / tmp / deploy / images / qemux86 / *". Here, depending on the settings, there may be files in various formats. For example, .iso, .vmdk, .vdi files.

Now you can run the resulting images using the emulator or hypervisor that you usually use. Among them are Microsoft Hyper-V, VMware Fusion, VirtualBox and others. Have a good experiment!

Also popular now: