lima-vm/lima · error

failed to create ASIF image %#q: %w

Error message

failed to create ASIF image %#q: %w

What it means

NewASIF creates a blank ASIF disk image by shelling out to `diskutil image create blank --format ASIF` on macOS. This error wraps a non-zero exit from diskutil during creation. It means diskutil refused or failed to create the image file at the requested path/size.

Source

Thrown at pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go:24

import (
	"bytes"
	"context"
	"encoding/xml"
	"errors"
	"fmt"
	"os"
	"os/exec"
	"strconv"
	"strings"

	"github.com/lima-vm/lima/v2/pkg/plist"
)

// NewASIF creates a new ASIF image file at the specified path with the given size.
func NewASIF(path string, size int64) error {
	createArgs := []string{"image", "create", "blank", "--fs", "none", "--format", "ASIF", "--size", strconv.FormatInt(size, 10), path}
	if err := exec.CommandContext(context.Background(), "diskutil", createArgs...).Run(); err != nil {
		return fmt.Errorf("failed to create ASIF image %#q: %w", path, err)
	}
	if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
		if _, err2 := os.Stat(path + ".asif"); !errors.Is(err2, os.ErrNotExist) {
			// diskutil may create the file with .asif suffix
			if err3 := os.Rename(path+".asif", path); err3 != nil {
				return fmt.Errorf("failed to rename ASIF image from %#q to %#q: %w", path+".asif", path, err3)
			}
		}
	}
	return nil
}

// NewAttachedASIF creates a new ASIF image file at the specified path with the given size
// and attaches it, returning the attached device path and an open file handle.
// The caller is responsible for detaching the ASIF image device when done.
func NewAttachedASIF(path string, size int64) (string, *os.File, error) {
	if err := NewASIF(path, size); err != nil {
		return "", nil, err

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check the wrapped diskutil error (stderr) for the underlying cause (space, permissions, unsupported format)
  2. Verify the macOS version supports `diskutil image create blank --format ASIF` (try the command manually)
  3. Free disk space or reduce the requested image size
  4. Choose a writable, simple path without special characters

Example fix

// diagnose manually
// before: opaque failure from NewASIF
// after
err := asifutil.NewASIF(path, size)
if err != nil {
    log.Fatalf("ASIF creation failed; run: diskutil image create blank --fs none --format ASIF --size %d %q", size, path)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: check host free space and diskutil ASIF support
if st, err := os.Stat(filepath.Dir(path)); err != nil || st.Mode().Perm()&0o200 == 0 { return errors.New("image directory not writable") }

Try / catch

if err := asifutil.NewASIF(path, size); err != nil {
    var exitErr *exec.ExitError
    if errors.As(err, &exitErr) { log.Printf("diskutil failed: %s", exitErr.Stderr) }
    return err
}

Prevention

When it happens

Trigger: Calling NewASIF(path, size) (via createDiskMacOSGuest or NewAttachedASIF) when diskutil fails: unsupported macOS version lacking ASIF support, insufficient disk space for the requested size, unwritable target path, or invalid size argument.

Common situations: Running on macOS older than the version that supports ASIF images (Tahoe/26+ era diskutil); creating huge images on a nearly full APFS volume; path in a read-only location or with characters diskutil dislikes.

Related errors


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