lima-vm/lima · error
failed to resize ASIF image %#q: %w: %s
Error message
failed to resize ASIF image %#q: %w: %s
What it means
ResizeASIF grows/shrinks an ASIF image via `diskutil image resize --size <n> <path>`. This error wraps a non-zero exit and includes diskutil's combined output. The resize request was rejected or failed.
Source
Thrown at pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go:70
_ = DetachASIF(devicePath)
return "", nil, fmt.Errorf("failed to open ASIF device %#q: %w", devicePath, err)
}
return devicePath, f, err
}
// DetachASIF detaches the ASIF image device at the specified path.
func DetachASIF(devicePath string) error {
if output, err := exec.CommandContext(context.Background(), "hdiutil", "detach", devicePath).CombinedOutput(); err != nil {
return fmt.Errorf("failed to detach ASIF image %#q: %w: %s", devicePath, err, output)
}
return nil
}
// ResizeASIF resizes the ASIF image at the specified path to the given size.
func ResizeASIF(path string, size int64) error {
resizeArgs := []string{"image", "resize", "--size", fmt.Sprintf("%d", size), path}
if output, err := exec.CommandContext(context.Background(), "diskutil", resizeArgs...).CombinedOutput(); err != nil {
return fmt.Errorf("failed to resize ASIF image %#q: %w: %s", path, err, output)
}
return nil
}
type AttachedDisk struct {
Disk string // whole disk device, e.g. "disk4" (GUID_partition_scheme)
Container string // APFS container partition, e.g. "disk4s2" (Apple_APFS)
Data string // data volume device, e.g. "disk7s5"
}
// parseDiskutilImageAttachOutput parses the output of `diskutil image attach -plist -nomount <disk>`
// and returns the attached disk information.
func parseDiskutilImageAttachOutput(xmlStr string) (*AttachedDisk, error) {
var p plist.Plist
if err := xml.Unmarshal([]byte(xmlStr), &p); err != nil {
return nil, fmt.Errorf("failed to unmarshal xml: %w", err)
}
View on GitHub (pinned to dd909d0973)
Solutions
- Check the included diskutil output for the precise rejection reason
- Only grow (or shrink to a size >= current data) and ensure host has free space
- Verify macOS supports `diskutil image resize` and the size format
- Recreate the image at the desired size if resize is unsupported
Example fix
// before
asifutil.ResizeASIF(path, smallerSize) // may fail: below current data
// after
if newSize < currentSize {
log.Printf("refusing shrink below current size %d", currentSize)
return errors.New("cannot shrink ASIF below current data size")
}
return asifutil.ResizeASIF(path, newSize) Defensive patterns
Strategy: validation
Validate before calling
// preflight: never shrink below current size
func canResize(cur, want int64) bool { return want >= cur } Try / catch
if err := asifutil.ResizeASIF(path, size); err != nil {
log.Printf("resize rejected; diskutil said: %v", err) // wrapped output contains diskutil's reason
return err
} Prevention
- Only grow images, or shrink to sizes >= current data size
- Ensure free host disk space when growing
- Verify the macOS version supports `diskutil image resize`
When it happens
Trigger: Calling ResizeASIF (from convertASIFToASIF) when diskutil fails: shrinking below current data size, requesting a size smaller/larger than allowed, image not a valid ASIF, or disk space exhaustion when growing.
Common situations: Attempted shrink smaller than existing filesystem/data; target size not accepted by diskutil syntax expectations; growing an image on a nearly full host volume; older macOS without image resize support.
Related errors
- failed to create ASIF image %#q: %w
- failed to attach ASIF image %#q: %w
- failed to find data slice in attached disk
- failed to rename ASIF image from %#q to %#q: %w
- failed to open ASIF device %#q: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/754d4c0f66200332.
Report an issue: GitHub.