A blog for various doodles, tips, and tricks of embedded Linux development.

29 Dec 2013

Using OE/Yocto to create VMs

By default most OE builds will create a filesystem image, a kernel, and (perhaps) a bundle of kernel modules. This set of outputs makes it easy if you're looking to flash your build into real hardware or run it in emulation via qemu (i.e. runqemu). But what if you're looking to run your image in a virtual machine?

To run an image in a virtual machine you'll need a virtual disk image which contains a partition map and a bootloader. Fortunately OE provides support for generating one such type of virtual disk image: the vmdk.

Configure OE to Generate a VMDK

In order to get OE to generate a vmdk artifact simply edit your conf/local.conf to add vmdk to IMAGE_FSTYPES. Unfortunately, due to the way in which variables are handled in bitbake, it isn't possible to use the _append operator, only the +=operator can be used:

IMAGE_FSTYPES += vmdk

Now when you perform a successful OE build, a vmdk will appear in your deploy/images folder.

Running a VMDK in a Virtual Machine

In order to run a vmdk in a virtual machine such as VirtualBox simply run through VirtualBox's "add a new machine" wizard. When it asks you about the disk, tell it you already have a disk, and select the vmdk generated by your OE build.

Unfortunately by default the VirtualBox wizard will add your disk under the SATA controller:

You'll need to switch it to be connected to the IDE controller:

Notes:

currently OE is only able to generate vmdk's for x86 machines since the current procedure requires syslinux (which only runs on x86 machines)

it is also possible to use runqemu to run a vmdk

my MACHINE setting for this example is "qemux86", and I'm building distroless