Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Fabio Berton <fbberton@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size
Date: Mon,  7 Apr 2025 17:02:06 +0100	[thread overview]
Message-ID: <20250407160206.2449867-1-fbberton@gmail.com> (raw)

From: Fabio Berton <fabio.berton@criticaltechworks.com>

Add the IMAGE_ROOTFS_EXACT_SIZE variable to allow the creation of a root
filesystem with an exact size as specified by the user. This bypasses
the default size calculation done by the get_rootfs_size function.

This feature is useful for creating a small ext4 filesystem with a block
size of 1k. The get_rootfs_size function uses a block size of 4k to
determine the size of IMAGE_ROOTFS, which may be larger than the value
set in IMAGE_ROOTFS_SIZE. If an ext4 rootfs with a block size of 1K is
nearly full, the .ext4 file generated by Yocto will be larger than
expected due to the way get_rootfs_size calculates the size.

By using IMAGE_ROOTFS_EXACT_SIZE, users can specify the exact size
required. Users should ensure that the size is set correctly according
to the filesystem requirements. It is not easy to predict the block size
that is used by a filesystem because it can be set by a parameter or it
can be added automatically by the tool that creates the file system.

Signed-off-by: Fabio Berton <fabio.berton@criticaltechworks.com>
---
 meta/classes-recipe/image.bbclass | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass
index 378d3bd0d4..419bb6cc14 100644
--- a/meta/classes-recipe/image.bbclass
+++ b/meta/classes-recipe/image.bbclass
@@ -132,7 +132,7 @@ python () {
 
 def rootfs_variables(d):
     from oe.rootfs import variable_depends
-    variables = ['IMAGE_DEVICE_TABLE','IMAGE_DEVICE_TABLES','BUILD_IMAGES_FROM_FEEDS','IMAGE_TYPES_MASKED','IMAGE_ROOTFS_ALIGNMENT','IMAGE_OVERHEAD_FACTOR','IMAGE_ROOTFS_SIZE','IMAGE_ROOTFS_EXTRA_SPACE',
+    variables = ['IMAGE_DEVICE_TABLE','IMAGE_DEVICE_TABLES','BUILD_IMAGES_FROM_FEEDS','IMAGE_TYPES_MASKED','IMAGE_ROOTFS_ALIGNMENT','IMAGE_OVERHEAD_FACTOR','IMAGE_ROOTFS_SIZE', 'IMAGE_ROOTFS_EXACT_SIZE', 'IMAGE_ROOTFS_EXTRA_SPACE',
                  'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS', 'IMAGE_LINGUAS_COMPLEMENTARY', 'IMAGE_LOCALES_ARCHIVE',
                  'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS',
                  'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS',
@@ -596,9 +596,14 @@ def get_rootfs_size(d):
     return base_size
 
 python set_image_size () {
-        rootfs_size = get_rootfs_size(d)
-        d.setVar('ROOTFS_SIZE', str(rootfs_size))
-        d.setVarFlag('ROOTFS_SIZE', 'export', '1')
+    rootfs_size = d.getVar('IMAGE_ROOTFS_EXACT_SIZE')
+    # If IMAGE_ROOTFS_EXACT_SIZE variable is not set, use the result of
+    # get_rootfs_size as ROOTFS_SIZE.
+    if not rootfs_size:
+        rootfs_size = str(get_rootfs_size(d))
+
+    d.setVar('ROOTFS_SIZE', rootfs_size)
+    d.setVarFlag('ROOTFS_SIZE', 'export', '1')
 }
 
 #
-- 
2.49.0



             reply	other threads:[~2025-04-07 16:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07 16:02 Fabio Berton [this message]
2025-04-23  8:25 ` [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size Fabio Berton
2025-04-30  9:32 ` Fabio Berton
  -- strict thread matches above, loose matches on Subject: below --
2025-06-02 21:30 Fabio Berton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250407160206.2449867-1-fbberton@gmail.com \
    --to=fbberton@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox