Home > Articles

  • Print
  • + Share This
This chapter is from the book

7.2 Building Images from Scratch

Section 7.1 detailed the Yocto Project core images and how to extend them through setting IMAGE_INSTALL, CORE_IMAGE_EXTRA_INSTALL, IMAGE_FEATURES, and EXTRA_IMAGE_FEATURES in conf/local.conf and in recipes extending predefined image recipes. Eventually, you may want to create your custom Linux distribution image from scratch without relying on one of the reference images.

A custom image recipe must inherit either the image or the core-image class. The latter is essentially an extension of the former and defines additional image features, as described earlier in Section 7.1.5. Which one to choose for custom image recipes depends on your requirements. However, inheriting core-image generally is sound advice, since the image features are made available but only installed if explicitly requested.

Listing 7-4 shows the simplest image recipe that creates a bootable console image.

Listing 7-4 Basic Image Recipe

SUMMARY = "Custom image recipe that does not get any simpler"


inherit core-image

The recipe creates an image with the core packages to boot and hardware support for the target device because the core-image class adds the two package groups packagegroup-core-boot and packagegroup-base-extended to IMAGE_INSTALL by default. Also added to IMAGE_INSTALL by the class is the variable CORE_IMAGE_EXTRA_INSTALL, which allows for simple image modification through conf/local.conf, as described earlier.

The basic image with package-group-core-boot and package-base-extended provides a good starting point that easily can be extended by adding to IMAGE_INSTALL and IMAGE_FEATURES, as shown in Listing 7-5.

Listing 7-5 Adding to the Basic Image

SUMMARY = "Custom image recipe adding packages and features"
               further customization. "


# We are using the append operator (+=) below to preserve the default
# values set by the core-image class we are inheriting.
IMAGE_INSTALL += "mtd-utils"
IMAGE_FEATURES += "splash"

inherit core-image

Within image recipes, you append directly to IMAGE_INSTALL and IMAGE_FEATURES using the += operator. Do not use EXTRA_IMAGE_FEATURES or CORE_IMAGE_EXTRA_INSTALL in your image recipe. These variables are reserved for use in conf/local.conf where they are directly assigned and overwrite any values assigned by the image recipe.

An image recipe that does not rely on the default values for IMAGE_INSTALL and IMAGE_FEATURES is equally simple, as Listing 7-6 shows.

Listing 7-6 Core Image from Scratch

SUMMARY = "Custom image recipe from scratch"
               for direct control over image contents."


# We are using the assignment operator (=) below to purposely overwrite
# the default from the core-image class.
IMAGE_INSTALL = "packagegroup-core-boot packagegroup-base-extended \
                 ${CORE_IMAGE_EXTRA_INSTALL} mtd-utils"

inherit core-image

At first glance, the image recipes of Listings 7-5 and 7-6 look rather similar. In fact, the two recipes produce exactly the same image. The differences are subtle but significant. Listing 7-5 uses the append operator += for IMAGE_INSTALL and IMAGE_FEATURES to take advantage of the default values provided by the core-image class. Listing 7-6 uses the assignment operator = to purposely overwrite the default values.

Overwriting the default values gives you the most control over the content of your image, but you also have to take care of the basics yourself. For any image, you would most likely always want to include packagegroup-core-boot to get a bootable image. Whether you want the hardware support that packagegroup-base-extended provides depends on your requirements. Also at your disposal is CORE_IMAGE_EXTRA_INSTALL: if you do not explicitly add it to IMAGE_FEATURES, you will not be able to use this variable in conf/local.conf for local customization of your target image, but it may make sense to do so for a controlled build environment for production.

The same holds true for IMAGE_FEATURES and EXTRA_IMAGE_FEATURES. If you use the assignment operator with IMAGE_FEATURES and purposely do not add EXTRA_IMAGE_FEATURES, it is not included, which means that the debug-tweaks image feature is not applied, and you need to provide passwords for shell and SSH logins. Again, this makes sense for production build environments where you do not want local configuration settings to override the settings of your production images.

  • + Share This
  • 🔖 Save To Your Account