imagepull/BuildExt4: omit positional fs-size; rely on file truncation

mkfs.ext4's positional fs-size is documented in 1 KiB units (not the
filesystem's 4 KiB block size), so passing sizeBytes/4096 made
filesystems 1/4 the intended size. A 4 GiB request became a 1 GiB
ext4 in a 4 GiB file, packed to 0 free blocks — VM create then failed
with 'Could not allocate block' when patchRootOverlay tried to write
guest config.

The file is truncated to the target size before mkfs runs; without
the positional arg, mkfs uses the whole device.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-18 14:58:42 -03:00
parent b2dcdf9757
commit ed4117d926
No known key found for this signature in database
GPG key ID: 33112E6833C34679

View file

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"
"strconv"
"banger/internal/system"
)
@ -53,6 +52,11 @@ func BuildExt4(ctx context.Context, runner system.CommandRunner, srcDir, outFile
return err
}
// mkfs.ext4's positional `fs-size` is documented in 1 KiB units
// (NOT the filesystem's 4 KiB block size), so dividing by 4096
// produces a filesystem 1/4 the intended size. Omit the positional
// entirely — the file was truncated to sizeBytes above, and mkfs
// with no fs-size arg uses the whole device.
out, runErr := runner.Run(ctx, "mkfs.ext4",
"-F",
"-q",
@ -60,7 +64,6 @@ func BuildExt4(ctx context.Context, runner system.CommandRunner, srcDir, outFile
"-L", "banger-rootfs",
"-E", "root_owner=0:0",
outFile,
strconv.FormatInt(sizeBytes/4096, 10), // size in 4 KiB blocks
)
if runErr != nil {
_ = os.Remove(outFile)