{"record":{"id":"b1f5e018a8bf2849","repo":"lima-vm/lima","slug":"cannot-determine-size-of-q","errorCode":null,"errorMessage":"cannot determine size of %#q","messagePattern":"cannot determine size of %#q","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/disk.go","lineNumber":85,"sourceCode":"\t}\n\n\treturn disk, nil\n}\n\n// inspectDisk attempts to inspect the disk size and format with qcow2reader.\nfunc inspectDisk(fName string) (size int64, format string, _ error) {\n\tf, err := os.Open(fName)\n\tif err != nil {\n\t\treturn -1, \"\", err\n\t}\n\tdefer f.Close()\n\timg, err := qcow2reader.Open(f)\n\tif err != nil {\n\t\treturn -1, \"\", err\n\t}\n\tsz := img.Size()\n\tif sz < 0 {\n\t\treturn -1, \"\", fmt.Errorf(\"cannot determine size of %#q\", fName)\n\t}\n\n\treturn sz, string(img.Type()), nil\n}\n\nfunc (d *Disk) Lock(instanceDir string) error {\n\tinUseBy := filepath.Join(d.Dir, filenames.InUseBy)\n\treturn os.Symlink(instanceDir, inUseBy)\n}\n\nfunc (d *Disk) Unlock() error {\n\tinUseBy := filepath.Join(d.Dir, filenames.InUseBy)\n\treturn os.Remove(inUseBy)\n}\n\nfunc (d *Disk) LockForInstance(instanceDir string) error {\n\tif d.Instance != \"\" {\n\t\tif d.InstanceDir != instanceDir {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/store/disk.go#L67-L103","documentation":"inspectDisk opens the disk's backing qcow2 image with qcow2reader and asks it for the virtual size; if img.Size() returns a negative value the size cannot be determined, so the function fails with the file name. This protects callers from storing/acting on an invalid size.","triggerScenarios":"Calling InspectDisk on a disk whose backing file exists and opens, but whose format/size metadata yields a negative size from qcow2reader (unsupported or corrupt image metadata).","commonSituations":"Corrupted or truncated qcow2 file (e.g. after a crash or full disk); image in a format qcow2reader cannot fully parse; manually created/edited disk images with invalid headers.","solutions":["Inspect the image with qemu-img info <file> to see whether the header is valid and the size is sane.","Delete and recreate the disk with limactl disk create if the image is corrupt and contains no needed data.","Recover the image with qemu-img check/convert to a fresh file, then retry InspectDisk."],"exampleFix":"// before\nlimactl disk inspect mydisk   # cannot determine size\n// after\nqemu-img check ~/.lima/disks/mydisk/data\nqemu-img convert -O qcow2 ~/.lima/disks/mydisk/data mydisk-fixed.qcow2\n# replace the corrupt data file, then retry","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"qemu-img\", \"info\", dataFile).CombinedOutput()\nif err != nil { return fmt.Errorf(\"disk image invalid: %s\", out) }","typeGuard":null,"tryCatchPattern":"sz, format, err := store.InspectDisk(diskDir)\nif err != nil {\n    // treat as corrupt disk: suggest qemu-img check or recreate\n    return err\n}","preventionTips":["Shut down instances cleanly to avoid truncated qcow2 files","Periodically run qemu-img check on disk data files","Keep sufficient free space to prevent interrupted writes"],"tags":["qcow2","disk","corrupt-image"],"backgroundTag":"disk-image-invalid","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}