Skip to content

Fix size estimation for image size in percent - #340

Open
aeolio wants to merge 1 commit into
pengutronix:masterfrom
aeolio:percent
Open

aeolio wants to merge 1 commit into
pengutronix:masterfrom
aeolio:percent

Conversation

@aeolio

@aeolio aeolio commented Jul 25, 2026

Copy link
Copy Markdown

Commit 8d9c1a2 ("genimage: allow percentages for image sizes") introduced the option to specity image sizes as a percentage of the initial data. Size estimation for this option is based on the root path only, which makes this feature unusable for partitions populated mainly by files.

Add calculation of file size to the size estimation before applying the percentage.

Fixes: : #227 ("Image size in % does not work")

@learmj

learmj commented Jul 29, 2026

Copy link
Copy Markdown

+1 for this. The patch works great for me (packs a vfat image from /bootfs in the chroot with variable size) in the target filesystem, eg

image image.vfat {
   vfat {
      label = "BOOT"
   }
   size = 100%
   mountpoint = "/bootfs"
}

@learmj

learmj commented Sep 16, 2026

Copy link
Copy Markdown

Hi @michaelolbrich Do you think this will be accepted? One particular build configuration we have packs a vfat boot disk from a mountpoint which can vary in size, but we only ever need it to be 100%. It would be great if this patch could be integrated into genimage.

@michaelolbrich michaelolbrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simpler, and please rebase while at it.

Comment thread util.c Resolved

@michaelolbrich michaelolbrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. Some minor stuff, and please rebase instead of merging master into your branch.

Comment thread genimage.c Outdated
unsigned long long alignment = 1024ULL * 1024ULL; // align to the next MiB
unsigned long long size = image_mountpath_size(image) + image_file_size(image);
size = size * image->size / 100ULL;
image->size = ((size + alignment) / alignment) * alignment;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add an unconditional 1M alignment. That changes existing users.
4k should be save because that is probably what filesystems will do anyway. That should fix the failing test.

Anything else needs some kind of new option. I'm not sure what though. I think it would be nice to propagate the partition alignment back to the image, but that would change the size after setup is called for the image and that is not a good idea.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea behind the image alignment was to avoid warnings from partitioning tools later. Since this can be handled with the partition.align option, such a feature might not be needed ...

Comment thread image-file.c Outdated
strerror(errno));
return ret;
}
unsigned long long size = s.st_size;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable should be declared at the beginning of the function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread README.rst Outdated
mountpoint or by specifying file{} or files{} options,
'%' can be used as a suffix to indicate a percentage.
'200%' means the resulting filesystem should be about
50% filled. Due to rounding, this value will not be exact.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't reformat the existing test. That makes it hard to see what actually changed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Comment thread util.c Outdated
if (image->empty)
return 0;
return dir_size(image, AT_FDCWD, mountpath(image), 4096);
const char *mnt = mountpath(image);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, move the variable declaration to the top.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed. New version was pushed.

Commit 8d9c1a2 ("genimage: allow percentages for image sizes") introduced
the option to specity image sizes as a percentage of the initial data.
Size estimation for this option is based on the root path only, which
makes this feature unusable for partitions populated mainly by files.

Add calculation of file size to the size estimation before applying the
percentage.

Fixes: : pengutronix#227 ("Image size in % does not work")
Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants