How to do it...

An example of a small image that does not include the core image class and can be used as the base for a bottom-up root filesystem image with reduced size, recipes-core/images/image-small.bb, is shown next:

DESCRIPTION = "Minimal console-only image." 
 
IMAGE_INSTALL= "
        base-files   
        base-passwd  
        busybox   
        sysvinit   
        initscripts   
" 
 
IMAGE_LINGUAS = " " 
 
LICENSE = "MIT" 
 
inherit image 
 
IMAGE_ROOTFS_SIZE = "8192" 

This recipe produces a root filesystem of 4.8 MB. You can go even smaller if you use the
poky-tiny distribution by adding the following to your conf/local.conf file:

DISTRO = "poky-tiny" 

The poky-tiny distribution makes a series of size optimizations that may restrict the set of packages you can include in your image. These optimizations include:

  • Using the musl C library instead of glibc
  • Removing native language support
  • Streamlining distribution features
  • Using the BusyBox init system and mdev device manager
  • Only building a cpio image suitable for an initramfsimage-small
  • Emptying MACHINE_ESSENTIAL_EXTRA_RDEPENDS so no machine-specific packages are installed
  • Removing Perl and Python dependencies
  • Blacklisting a set of core images that are not buildable with the previous restrictions

The following needs to be added to conf/local.conf to be able to build image-small with poky-tiny:

IMAGE_INSTALL_remove = "sysvinit" 

Removing sysvinit is needed as poky-tiny uses the BusyBox init system and removes the sysvinit DISTRO_FEATURE by blacklisting it in DISTRO_FEATURES_BACKFILL_CONSIDERED, which prevents it from being automatically added.

The poky-tiny distribution configuration file also overrides the virtual/kernel provider to linux-yocto-tiny, which we know the Wandboard does not support, so in order to build for the Wandboard we also need to create our own poky-tiny-custom distribution, which is added in our meta-custom layer with the following conf/distro/poky-tiny-custom.conf file:

require conf/distro/poky-tiny.conf                                               
PREFERRED_PROVIDER_virtual/kernel = "linux-wandboard" 

We have already seen how to reduce the size of the Linux kernel in the Reducing the Linux kernel image size recipe.

With poky-tiny-custom, the size of the root filesystem is further reduced to around 2.5 MB.

Once the root filesystem size is optimized, the final size of the image depends on three factors:

  • rootfs-size: The actual size of the root filesystem as calculated by the du command, multiplied by an overhead factor as defined by the IMAGE_OVERHEAD_FACTOR variable (which defaults to 1.3).
  • minimum-rootfs-size: The requested minimum image size in KB specified by IMAGE_ROOTFS_SIZE. If the value is smaller than the requested minimum image, the latter is used.
  • extra-space: An extra space in KB requested with the IMAGE_ROOTFS_EXTRA_SPACE variable, which is added to the previous value. By default, there is no extra space added.

The final image size used to generate ext2/3/4 and btrfs images is calculated by adding the extra-space to either the minimum-rootfs-size or the rootfs-size, whichever is bigger, as expressed in the following expression:

size = max(rootfs-size, minimum-rootfs-size) + extra-space 

The final image size of this image-small recipe is 8 MB as specified by the IMAGE_ROOTFS_SIZE variable.

The root filesystem needs free space on the image to cater for post-installation scripts and the package management system if any, and probably also to host application data. This can be provided either by the overhead factor or by fixing the extra space to use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset