lima-vm/lima · error
failed to rename ASIF image from %#q to %#q: %w
Error message
failed to rename ASIF image from %#q to %#q: %w
What it means
After creating an ASIF image, NewASIF handles a diskutil quirk: some versions create the file with a `.asif` suffix appended. This error occurs when `os.Rename(path+".asif", path)` fails while fixing up that quirk. It wraps the OS-level rename failure.
Source
Thrown at pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go:30
"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
}
attachArgs := []string{"image", "attach", "--noMount", path}
out, err := exec.CommandContext(context.Background(), "diskutil", attachArgs...).Output()
if err != nil {
return "", nil, fmt.Errorf("failed to attach ASIF image %#q: %w", path, err)
}View on GitHub (pinned to dd909d0973)
Solutions
- Delete the pre-existing conflicting file at `path` and retry
- Check write permissions on the directory containing the image
- Ensure no other process is concurrently creating the same image
- If rename keeps failing, manually rename `path.asif` to `path` before retrying the operation
Example fix
// before
_ = os.Remove(diskPath) // stale file blocks rename
err := asifutil.NewASIF(diskPath, size)
// after
if err := os.Remove(diskPath); err != nil && !os.IsNotExist(err) { return err }
if err := asifutil.NewASIF(diskPath, size); err != nil { return err } Defensive patterns
Strategy: try-catch
Validate before calling
// preflight: ensure target path is free before creating the image
if _, err := os.Stat(path); err == nil { return fmt.Errorf("image path %q already exists", path) } Try / catch
if err := asifutil.NewASIF(path, size); err != nil {
if strings.Contains(err.Error(), "failed to rename") {
os.Remove(path); os.Remove(path + ".asif") // clear stale files, then retry once
}
return err
} Prevention
- Remove stale image files from previous failed runs
- Avoid concurrent operations on the same image path
- Create images in directories with write permission
When it happens
Trigger: NewASIF ran successfully but the produced file is at `path+".asif"`, and the rename back to `path` fails — typically the target exists and cannot be replaced, or a permissions/volume issue prevents the move.
Common situations: A stale file already exists at the target path from a previous failed run; the directory is read-only; cross-volume rename restrictions; concurrent Lima operations racing on the same path.
Related errors
- failed to create ASIF image %#q: %w
- vmOpts.vz.diskImageFormat=%#q requires macOS 26 or higher to
- field `vmOpts.vz.diskImageFormat` must be %#q or %#q, got %#
- unsupported disk format for macOS guest: %s
- failed to find data slice in attached disk
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/40c1a2769eddf2f3.
Report an issue: GitHub.