How it works...

Start with an appropriate image, such as core-image-minimal, analyze the dependencies as shown in the Debugging the build system recipe in Chapter 1, The Build System, and decide which of them are not needed. You could also use the file sizes listed in the image's build history, as seen in the Using build history recipe, also in Chapter 1, The Build System, to detect the biggest files in the filesystem and review them. To sort the file sizes, which appear in the fourth column of the files-in-image.txt file, in reverse order, we could execute:

$ sort -r -g  -k 4,4 files-in-image.txt -o sorted-files-in-image.txt
sorted-files-in-image.txt:
-rw-r--r-- root       root          7267688 ./boot/zImage-4.1.44+g0d698de42426                  
-rwxr-xr-x root       root          2667248 ./usr/bin/trace                     
-rwxr-xr-x root       root          2667248 ./usr/bin/perf                      
-r-xr-xr-x root       root          1627632 ./usr/lib/libperl.so.5.24.1         
-rwxr-xr-x root       root          1261024 ./usr/lib/libstdc++.so.6.0.24           
-rwxr-xr-x root       root          1222352 ./lib/libc-2.26.so                  
-rwxr-xr-x root       root           867168 ./bin/bash.bash                     
-rw-r--r-- root       root           830424 ./usr/lib/libslang.so.2.3.1         
-rwxr-xr-x root       root           797648 ./usr/lib/libbfd-2.29.0.20170912.so
-rwxr-xr-x root       root           535396 ./bin/busybox.nosuid                
-rwxr-xr-x root       root           525488 ./sbin/ldconfig                     
-rwxr-xr-x root       root           460144 ./lib/libm-2.26.so                  
-rw-r--r-- root       root           338696 ./boot/u-boot-wandboard-v2017.09+gitAUTOINC+a6a15fedd1-r0.img
-rwxr-xr-x root       root           265796 ./usr/bin/trace-cmd                 
-rwxr-xr-x root       root           263592 ./usr/lib/libpcre.so.1.2.9          
-rwxr-xr-x root       root           256356 ./usr/bin/udevadm                   
-rwxr-xr-x root       root           248212 ./sbin/udevd     

Poky has a dirsize.py script that reports component sizes for the filesystem. An extract from its output (when launched from the rootfs directory in the tmp directory) is:

$ cd /opt/yocto/fsl-community-bsp/wandboard/tmp/work/wandboard-poky-linux-gnueabi/core-image-minimal/1.0-r0/rootfs
$ /opt/yocto/fsl-community-bsp/sources/poky/scripts/tiny/dirsize.py
  12997690 .
   7943835 ./boot
       197 ./boot/extlinux
       197 ./boot/extlinux/extlinux.conf
   7267688 ./boot/zImage-4.1.44+g0d698de42426
    338696 ./boot/u-boot-wandboard-v2017.09+gitAUTOINC+a6a15fedd1-r0.img
     48128 ./boot/SPL-wandboard-v2017.09+gitAUTOINC+a6a15fedd1-r0
     43827 ./boot/imx6qp-wandboard-revd1.dtb
     42197 ./boot/imx6q-wandboard-revd1.dtb
     41167 ./boot/imx6q-wandboard.dtb
     41167 ./boot/imx6q-wandboard-revb1.dtb
     40956 ./boot/imx6dl-wandboard-revd1.dtb
     39906 ./boot/imx6dl-wandboard.dtb
     39906 ./boot/imx6dl-wandboard-revb1.dtb
   2958219 ./lib

From this, we observe that the boot folder, which contains u-boot, the kernel, the device tree, and the extlinux.conf used to boot the system, is the biggest contributor to filesystem size.

Some other places where some space on a console-only system can be saved are:

  • Use the IPK package manager, as it is the lightest, or better yet remove the package-management feature from your production root filesystem altogether
  • Use BusyBox's mdev device manager instead of udev by specifying it in your conf/local.conf file as follows:
VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" 

Note that this will only work with core images that include packagegroup-core-boot

  • If we are running the root filesystem on a block device, use ext2 instead of ext3 or ext4 without the journal
  • Configure BusyBox with only the essential applets by providing your own configuration file in a bbappend file
  • Review the glibc configuration, which can be changed via the DISTRO_FEATURES_LIBC distribution configuration variable
  • Compile your applications with -Os to optimize for size
  • If using the Poky distribution, consider switching to a lighter C library than the default glibc such as musl, a new MIT-licensed C library

To enable the musl C library, you would add the following to your image file:
TCLIBC = "musl".

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

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