Skip to content

Conversation

@hiroTamada
Copy link
Contributor

@hiroTamada hiroTamada commented Jan 9, 2026

Summary

  • Increases ext4 filesystem overhead from 20% to 50% when converting OCI images to disk format
  • Fixes mkfs.ext4: Could not allocate block in ext2 filesystem error for images with many small files

Problem

When building and running images with many small files (like Alpine + tzdata), the image conversion to ext4 was failing:

Creating filesystem with 2702 4k blocks and 2704 inodes
Could not allocate block in ext2 filesystem while writing file "GMT-2"

The 20% overhead was insufficient for ext4 metadata (superblock, group descriptors, inode tables, directory entries), especially for small filesystems with many files.

Solution

Increased the overhead from 20% (sizeBytes / 5) to 50% (sizeBytes / 2).

Metric Before (20%) After (50%)
Example: 8.80 MB rootfs 10.56 MB disk 13.20 MB disk
Result ❌ mkfs.ext4 failed ✅ Success

Test plan

  • Built Alpine + tzdata image via hypeman build
  • Successfully pulled and converted image to ext4
  • Successfully ran instance with the image

Note

Adjusts ext4 image sizing to avoid mkfs failures on rootfs with many small files.

  • In convertToExt4, increase overhead from sizeBytes/5 to sizeBytes/2 (retain 10MB minimum) when computing diskSizeBytes
  • Add clarifying comments about ext4 metadata overhead and small-files failure cases

Written by Cursor Bugbot for commit 5493085. This will update automatically on new commits. Configure here.

The 20% overhead was insufficient for small filesystems with many files
(like images with timezone data). ext4 requires significant space for
superblock, group descriptors, inode tables, and directory entries.

This caused mkfs.ext4 to fail with "Could not allocate block in ext2
filesystem" when converting images to disk format.

Tested with Alpine + tzdata image which previously failed.
Copy link

@tembo tembo bot left a comment

Choose a reason for hiding this comment

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

Makes sense to bump overhead here given mkfs.ext4 failures on small roots with lots of files. One thought: if this ever needs tuning again, having a named constant (or config knob) for the overhead ratio would make it easier to adjust without re-auditing the comment/math everywhere.

// Add 50% overhead for filesystem metadata, minimum 10MB
// ext4 needs significant overhead for superblock, group descriptors, inode tables, etc.
// 20% was insufficient for small filesystems with many files (like tzdata)
diskSizeBytes := sizeBytes + (sizeBytes / 2)
Copy link

Choose a reason for hiding this comment

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

Nit: to keep the comment and math from drifting, consider pulling the ratio into a named constant.

Suggested change
diskSizeBytes := sizeBytes + (sizeBytes / 2)
const ext4MetadataOverheadPercent int64 = 50
diskSizeBytes := sizeBytes + (sizeBytes*ext4MetadataOverheadPercent)/100

@hiroTamada hiroTamada requested a review from rgarcia January 9, 2026 23:12
Copy link
Contributor

@rgarcia rgarcia left a comment

Choose a reason for hiding this comment

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

lgtm - makes sense for small filesystems with many files

@hiroTamada hiroTamada merged commit 157365b into main Jan 12, 2026
4 checks passed
@hiroTamada hiroTamada deleted the fix/ext4-overhead branch January 12, 2026 03:08
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