lima-vm/lima · error

failed to resize ASIF image %#q

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.

Solutions

  1. Check the included diskutil output for the precise rejection reason
  2. Only grow (or shrink to a size >= current data) and ensure host has free space
  3. Verify macOS supports `diskutil image resize` and the size format
  4. 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

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


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/754d4c0f66200332. Report an issue: GitHub.

Appendix: 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)