xref: /openbmc/openbmc/poky/documentation/dev-manual/disk-space.rst (revision 5082cc7fedfff6c28a1406c79606b09012b134bc)
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
26517393d9SAndrew GeisslerPurging Duplicate Shared State Cache Files
27517393d9SAndrew Geissler==========================================
28517393d9SAndrew Geissler
29517393d9SAndrew GeisslerAfter multiple build iterations, the Shared State (sstate) cache can contain
30*5082cc7fSAndrew Geisslerduplicate cache files for a given package, consuming a substantial amount of
31*5082cc7fSAndrew Geisslerdisk space. However, only the most recent cache files are likeky to be reusable.
32*5082cc7fSAndrew Geissler
33*5082cc7fSAndrew GeisslerThe following command is a quick way to purge all the cache files which
34*5082cc7fSAndrew Geisslerhaven't been used for a least a specified number of days::
35*5082cc7fSAndrew Geissler
36*5082cc7fSAndrew Geissler   find build/sstate-cache -type f -mtime +$DAYS -delete
37*5082cc7fSAndrew Geissler
38*5082cc7fSAndrew GeisslerThe above command relies on the fact that BitBake touches the sstate cache
39*5082cc7fSAndrew Geisslerfiles as it accesses them, when it has write access to the cache.
40*5082cc7fSAndrew Geissler
41*5082cc7fSAndrew GeisslerYou could use ``-atime`` instead of ``-mtime`` if the partition isn't mounted
42*5082cc7fSAndrew Geisslerwith the ``noatime`` option for a read only cache.
43*5082cc7fSAndrew Geissler
44*5082cc7fSAndrew GeisslerFor more advanced needs, OpenEmbedded-Core also offers a more elaborate
45*5082cc7fSAndrew Geisslercommand. It has the ability to purge all but the newest cache files on each
46*5082cc7fSAndrew Geisslerarchitecture, and also to remove files that it considers unreachable by
47*5082cc7fSAndrew Geisslerexploring a set of build configurations. However, this command
48*5082cc7fSAndrew Geisslerrequires a full build environment to be available and doesn't work well
49*5082cc7fSAndrew Geisslercovering multiple releases. It won't work either on limited environments
50*5082cc7fSAndrew Geisslersuch as BSD based NAS::
51517393d9SAndrew Geissler
52517393d9SAndrew Geissler   sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache
53517393d9SAndrew Geissler
54517393d9SAndrew GeisslerThis command will ask you to confirm the deletions it identifies.
55*5082cc7fSAndrew GeisslerRun ``sstate-cache-management.sh`` for more details about this script.
56517393d9SAndrew Geissler
57517393d9SAndrew Geissler.. note::
58517393d9SAndrew Geissler
59*5082cc7fSAndrew Geissler   As this command is much more cautious and selective, removing only cache files,
60*5082cc7fSAndrew Geissler   it will execute much slower than the simple ``find`` command described above.
61*5082cc7fSAndrew Geissler   Therefore, it may not be your best option to trim huge cache directories.
62