Click here to Skip to main content
15,946,316 members
Articles / Internet of Things
Article

How to run Yocto Linux OS in a virtual machine

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
18 Feb 2016CPOL5 min read 30.5K   7  
In this article I'll show how to create a runnable image of Yocto and how to test it inside QEMU, a basic software emulator; and following how to run it inside an Hypervisor, like Microsoft Hyper-V on Windows.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

Sometime we need a complete development environment to compile, deploy and test our solutions, and sometimes we can't play directly on the hardware, or, simply, the provided SDK is not enough for our development plans. This could be, for example, the case of Intel Edison or Galileo: how can I compile entire frameworks, runtimes and their dependencies on Yocto Linux OS?

In this article I'll show how to create a runnable image of Yocto and how to test it inside QEMU, a basic software emulator; and following how to run it inside an Hypervisor, like Microsoft Hyper-V on Windows.

Prerequisites to Work with this Tutorial

  • Debian/Ubuntu (tested on Debian 8.2 amd64)
  • Internet Connection
  • At least 100 GB free space on the disk

Preliminary Preparation of Your Building Machine

As root (or via "sudo") run the following command

C++
# 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 1: the success of the previous command depends on the version of the Ubuntu/Debian you are using. Eventually, to resolve dependencies of packages you can run "aptitude" and force the installation of the right version of packages you need (for example, "aptitude install libsdl1.2-dev").

Note 2: for other Linux-distribution, like RadHat, CentOS, Fedora, SuSe, Gentoo, etc… I suggest to check the respective versions of the previous package using the correct package-manager (for example, zypper, yum, ...).

First Step: Set Up Working Folder

As normal user withous privileges (no root)

C++
# 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 3: you can choose other development branch of Yocto releases following this link https://www.yoctoproject.org/downloads. In this tutorial will use the current latest release "Jocto Poky 2.0.14.0.0 codename Jethro".

Note 4: if you want to fetch the lastest bleeding edge release of Yocto sources you can grab the master development branch, you need to substitute the wget operation with the following:

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

Note 5: You can in addition also select a specific development branch using its codenname. For example:

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

Second Step: Set the Environment Variables for Your System Shell

There is a very easy-to-use script provided by Yocto developers.

C++
# . ./oe-init-build-env

After you run the script, if it worked, your location will be changed to a build subdirectory that will be your new workspace. Something like /home/<your user>/yocto-2.0/poky-jethro-14.0.0/build/.

Third Step: Set Up Bitbake

Executing the previous script a conf/local.conf file was created.

The configuration file needs to set up bitbake, the build engine of Yocto (core component of the Yocto Project).

Edit the bitbake configuration file with your preferred text editor. In this tutorial we'll use nano, a simple command-line-interface text editor for Unix-like environments, as follows:

C++
# cd conf/
# nano local.conf

Uncomment the following rows

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

I suggest to build all the available extra features to the image. The resulting images will be heavy (around 8GB each), but absolutely complete and absolutely versatile for every need of development.

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

Now, save the changes made to the file local.conf with CTRL+X keyboard combination.

Then:

C++
# cd ..
# hob

Now an instance of Hob (the GTK2-based graphical user interface for BitBake) should start, checking for the correctness of build system.

Image 1

Now select qemux86 as machine in the dropdown menu.

Image 2

Wait until Hob will finish parsing BitBake recipes and generating dependency tree. Then, select your preferred target image to build from the "select an image recipe" from the menu above. In this sample we'll select the full core image without the GUI: core-image-full-cmdline.

Image 3

Now click on "Advanced Configuration".

Image 4

In "Image types" panel leave poky in the "Distro" menu if you want to build the latest stable release. Then in "Image types" field select the format you need: usually, I select ".iso", ".vdi" and ".vmdk", they are the most useful and comfortable formats.

Image 5

In "Output" panel please select the best options that fit your needs. I suggest to add at least 4GB of free storage to your image, to populate the SDK for i686 architecture (if you are playing with Edison development board). In addition, I find very usefull to set "deb" as packaging format for the root filesystem. So, as follows:

Image 6

Ok, save. Now, you are ready to build your image! Click on "Build image" button!

Image 7

Hob will launch for you an instance of bitbake core-image-full-cmdline with your favorite settings.

Image 8

Note 7: this process will take a very long time to build the final images. But depending on your host machine capabilities you can change the number of processor cores used in build operation acting on "BitBake parallel threads" and "Make parallel threads". To can modify these variables from Hob settings window:

Image 9

Note 8: finally, with Hob you have the opportunity to decide what packages you want to include inside the image you are going to build. To do that before start building the image, you can select "Edit image recipe".

Image 10

And, then, choose packages to include through the following window:

Image 11

Now, when the building process will end, you’ll be able to directly try out your new generated images! Clicking on "Run image" Hob will launch for you an instance of QEMU to run the newly created qemux86 image.

Image 12

But, before, system will ask you to provide super-user privileges password:

Image 13

Another UNIX command line console window will open to show the loading state and the splashscreen of Yocto Project OS.

Image 14

You are now ready to log into the root account of your newly created Yocto image. Remember: inserting debug-tweaks parameter in EXTRA_IMAGE_FEATURES variable onto the conf/local.conf you’ll be able to login as root leaving the password field empty. Otherwise, you’ll need to set up root password in the recipe before building the image.

Image 15

You are now ready to star playing with the Yocto QEMU virtual machine.

Note 9: after built the Yocto image as presented in this tutorial, 89.8GBs of free space were occupied on the drive.

Image 16

You will can find the generated images in the .iso, .vmdk, .vdi and the other formats you choose inside the directory ~/yocto-2.0/poky-jethro-14.0.0/build/tmp/deploy/images/qemux86/*. Now, you are free to load the images inside your preferred hypervisor or emulator (Microsoft* Hyper-V, vmWare Fusion, Virtualbox, etc…).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
This is a Organisation

42 members

Comments and Discussions

 
-- There are no messages in this forum --