xref: /openbmc/openbmc/poky/documentation/dev-manual/disk-space.rst (revision 2f814a6d8285b35e9fb74e3ce9ce1c44b7e4f763)
1517393d9SAndrew Geissler.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
2517393d9SAndrew Geissler
3517393d9SAndrew GeisslerConserving Disk Space
4517393d9SAndrew Geissler*********************
5517393d9SAndrew Geissler
6517393d9SAndrew GeisslerConserving Disk Space During Builds
7517393d9SAndrew Geissler===================================
8517393d9SAndrew Geissler
9517393d9SAndrew GeisslerTo help conserve disk space during builds, you can add the following
10517393d9SAndrew Geisslerstatement to your project's ``local.conf`` configuration file found in
11517393d9SAndrew Geisslerthe :term:`Build Directory`::
12517393d9SAndrew Geissler
13517393d9SAndrew Geissler   INHERIT += "rm_work"
14517393d9SAndrew Geissler
15517393d9SAndrew GeisslerAdding this statement deletes the work directory used for
16517393d9SAndrew Geisslerbuilding a recipe once the recipe is built. For more information on
17517393d9SAndrew Geissler"rm_work", see the :ref:`ref-classes-rm-work` class in the
18517393d9SAndrew GeisslerYocto Project Reference Manual.
19517393d9SAndrew Geissler
208e7b46e2SPatrick WilliamsWhen you inherit this class and build a ``core-image-sato`` image for a
218e7b46e2SPatrick Williams``qemux86-64`` machine from an Ubuntu 22.04 x86-64 system, you end up with a
228e7b46e2SPatrick Williamsfinal disk usage of 22 Gbytes instead of &MIN_DISK_SPACE; Gbytes. However,
238e7b46e2SPatrick Williams&MIN_DISK_SPACE_RM_WORK; Gbytes of initial free disk space are still needed to
248e7b46e2SPatrick Williamscreate temporary files before they can be deleted.
258e7b46e2SPatrick Williams
26220dafdbSAndrew GeisslerPurging Obsolete Shared State Cache Files
27220dafdbSAndrew Geissler=========================================
28517393d9SAndrew Geissler
29517393d9SAndrew GeisslerAfter multiple build iterations, the Shared State (sstate) cache can contain
30220dafdbSAndrew Geisslermultiple cache files for a given package, consuming a substantial amount of
31220dafdbSAndrew Geisslerdisk space. However, only the most recent ones are likely to be reused.
325082cc7fSAndrew Geissler
335082cc7fSAndrew GeisslerThe following command is a quick way to purge all the cache files which
345082cc7fSAndrew Geisslerhaven't been used for a least a specified number of days::
355082cc7fSAndrew Geissler
365082cc7fSAndrew Geissler   find build/sstate-cache -type f -mtime +$DAYS -delete
375082cc7fSAndrew Geissler
385082cc7fSAndrew GeisslerThe above command relies on the fact that BitBake touches the sstate cache
395082cc7fSAndrew Geisslerfiles as it accesses them, when it has write access to the cache.
405082cc7fSAndrew Geissler
415082cc7fSAndrew GeisslerYou could use ``-atime`` instead of ``-mtime`` if the partition isn't mounted
425082cc7fSAndrew Geisslerwith the ``noatime`` option for a read only cache.
435082cc7fSAndrew Geissler
445082cc7fSAndrew GeisslerFor more advanced needs, OpenEmbedded-Core also offers a more elaborate
455082cc7fSAndrew Geisslercommand. It has the ability to purge all but the newest cache files on each
465082cc7fSAndrew Geisslerarchitecture, and also to remove files that it considers unreachable by
475082cc7fSAndrew Geisslerexploring a set of build configurations. However, this command
485082cc7fSAndrew Geisslerrequires a full build environment to be available and doesn't work well
495082cc7fSAndrew Geisslercovering multiple releases. It won't work either on limited environments
505082cc7fSAndrew Geisslersuch as BSD based NAS::
51517393d9SAndrew Geissler
52*2f814a6dSPatrick Williams   sstate-cache-management.py --remove-duplicated --cache-dir=sstate-cache
53517393d9SAndrew Geissler
54517393d9SAndrew GeisslerThis command will ask you to confirm the deletions it identifies.
555082cc7fSAndrew GeisslerRun ``sstate-cache-management.sh`` for more details about this script.
56517393d9SAndrew Geissler
57517393d9SAndrew Geissler.. note::
58517393d9SAndrew Geissler
595082cc7fSAndrew Geissler   As this command is much more cautious and selective, removing only cache files,
605082cc7fSAndrew Geissler   it will execute much slower than the simple ``find`` command described above.
615082cc7fSAndrew Geissler   Therefore, it may not be your best option to trim huge cache directories.
62