[meta-oe] image.bbclass: fix rootfs size computation

Submitted by Sumit Garg on July 23, 2020, 12:26 p.m. | Patch ID: 174650

Details

Message ID 1595507202-20625-1-git-send-email-sumit.garg@linaro.org
State New
Headers show

Commit Message

Sumit Garg July 23, 2020, 12:26 p.m.
Currently we rely on disk usage to compute rootfs size that may vary
depending on build machine filesystem type.

Consider following case:

Build machine 1: ext4 filesystem:

$ du -ks tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/
403024	tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/

Build machine 2: zfs filesystem:

$ du -ks tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/
240353	tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/

So, this leads to build failures during ext4 image creation on build
machine 2 as allocated ext4 image size is less than what is actually
required.

In order to fix this we need to rely on "--apparent-size" option
provided by "du" utility that provides the actual size. See below usage
text:

$ du --help
<snip>
Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with NUL, not newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
<snip>

With option "--apparent-size":

Build machine 1: ext4 filesystem:

$ du -ks --apparent-size tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/
379576	tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/

Build machine 2: zfs filesystem:

$ du -ks --apparent-size tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/
377455	tmp-rpb-glibc/work/qemuarm64-linaro-linux/rpb-console-image/1.0-r0/rootfs/

Although there is still little difference in actual reported size but
that can very well be covered by IMAGE_OVERHEAD_FACTOR.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 meta/classes/image.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 3b5600e..bf0685f 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -516,7 +516,7 @@  def get_rootfs_size(d):
     initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES') or ''
     initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE')
 
-    output = subprocess.check_output(['du', '-ks',
+    output = subprocess.check_output(['du', '-ks', '--apparent-size',
                                       d.getVar('IMAGE_ROOTFS')])
     size_kb = int(output.split()[0])