{"record":{"id":"754d4c0f66200332","repo":"lima-vm/lima","slug":"failed-to-resize-asif-image-q-w-s","errorCode":null,"errorMessage":"failed to resize ASIF image %#q: %w: %s","messagePattern":"failed to resize ASIF image %#q: %w: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go","lineNumber":70,"sourceCode":"\t\t_ = DetachASIF(devicePath)\n\t\treturn \"\", nil, fmt.Errorf(\"failed to open ASIF device %#q: %w\", devicePath, err)\n\t}\n\treturn devicePath, f, err\n}\n\n// DetachASIF detaches the ASIF image device at the specified path.\nfunc DetachASIF(devicePath string) error {\n\tif output, err := exec.CommandContext(context.Background(), \"hdiutil\", \"detach\", devicePath).CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"failed to detach ASIF image %#q: %w: %s\", devicePath, err, output)\n\t}\n\treturn nil\n}\n\n// ResizeASIF resizes the ASIF image at the specified path to the given size.\nfunc ResizeASIF(path string, size int64) error {\n\tresizeArgs := []string{\"image\", \"resize\", \"--size\", fmt.Sprintf(\"%d\", size), path}\n\tif output, err := exec.CommandContext(context.Background(), \"diskutil\", resizeArgs...).CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"failed to resize ASIF image %#q: %w: %s\", path, err, output)\n\t}\n\treturn nil\n}\n\ntype AttachedDisk struct {\n\tDisk      string // whole disk device, e.g. \"disk4\" (GUID_partition_scheme)\n\tContainer string // APFS container partition, e.g. \"disk4s2\" (Apple_APFS)\n\tData      string // data volume device, e.g. \"disk7s5\"\n}\n\n// parseDiskutilImageAttachOutput parses the output of `diskutil image attach -plist -nomount <disk>`\n// and returns the attached disk information.\nfunc parseDiskutilImageAttachOutput(xmlStr string) (*AttachedDisk, error) {\n\tvar p plist.Plist\n\tif err := xml.Unmarshal([]byte(xmlStr), &p); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal xml: %w\", err)\n\t}\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/imgutil/nativeimgutil/asifutil/asif_darwin.go#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nasifutil.ResizeASIF(path, smallerSize) // may fail: below current data\n// after\nif newSize < currentSize {\n    log.Printf(\"refusing shrink below current size %d\", currentSize)\n    return errors.New(\"cannot shrink ASIF below current data size\")\n}\nreturn asifutil.ResizeASIF(path, newSize)","handlingStrategy":"validation","validationCode":"// preflight: never shrink below current size\nfunc canResize(cur, want int64) bool { return want >= cur }","typeGuard":null,"tryCatchPattern":"if err := asifutil.ResizeASIF(path, size); err != nil {\n    log.Printf(\"resize rejected; diskutil said: %v\", err) // wrapped output contains diskutil's reason\n    return err\n}","preventionTips":["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`"],"tags":["macos","diskutil","resize","asif"],"backgroundTag":"disk-image-resize-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}