Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size
@ 2025-04-07 16:02 Fabio Berton
  2025-04-23  8:25 ` Fabio Berton
  2025-04-30  9:32 ` Fabio Berton
  0 siblings, 2 replies; 4+ messages in thread
From: Fabio Berton @ 2025-04-07 16:02 UTC (permalink / raw)
  To: openembedded-core

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size
  2025-04-07 16:02 [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size Fabio Berton
@ 2025-04-23  8:25 ` Fabio Berton
  2025-04-30  9:32 ` Fabio Berton
  1 sibling, 0 replies; 4+ messages in thread
From: Fabio Berton @ 2025-04-23  8:25 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 47 bytes --]

Hi,
Any thoughts on this?

Regards,
Fabio

[-- Attachment #2: Type: text/html, Size: 61 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size
  2025-04-07 16:02 [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size Fabio Berton
  2025-04-23  8:25 ` Fabio Berton
@ 2025-04-30  9:32 ` Fabio Berton
  1 sibling, 0 replies; 4+ messages in thread
From: Fabio Berton @ 2025-04-30  9:32 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 13 bytes --]

Gentle ping

[-- Attachment #2: Type: text/html, Size: 20 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size
@ 2025-06-02 21:30 Fabio Berton
  0 siblings, 0 replies; 4+ messages in thread
From: Fabio Berton @ 2025-06-02 21:30 UTC (permalink / raw)
  To: openembedded-core

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 24a19fce1a..2df0a5c30d 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',
@@ -594,9 +594,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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-02 21:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 16:02 [PATCH] classes-recipe/image: Add variable to create rootfs with a exact size Fabio Berton
2025-04-23  8:25 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox