lima-vm/lima · error
cannot determine size of %#q
Error message
cannot determine size of %#q
What it means
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.
Source
Thrown at pkg/store/disk.go:85
}
return disk, nil
}
// inspectDisk attempts to inspect the disk size and format with qcow2reader.
func inspectDisk(fName string) (size int64, format string, _ error) {
f, err := os.Open(fName)
if err != nil {
return -1, "", err
}
defer f.Close()
img, err := qcow2reader.Open(f)
if err != nil {
return -1, "", err
}
sz := img.Size()
if sz < 0 {
return -1, "", fmt.Errorf("cannot determine size of %#q", fName)
}
return sz, string(img.Type()), nil
}
func (d *Disk) Lock(instanceDir string) error {
inUseBy := filepath.Join(d.Dir, filenames.InUseBy)
return os.Symlink(instanceDir, inUseBy)
}
func (d *Disk) Unlock() error {
inUseBy := filepath.Join(d.Dir, filenames.InUseBy)
return os.Remove(inUseBy)
}
func (d *Disk) LockForInstance(instanceDir string) error {
if d.Instance != "" {
if d.InstanceDir != instanceDir {View on GitHub (pinned to dd909d0973)
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.
Example fix
// before limactl disk inspect mydisk # cannot determine size // after qemu-img check ~/.lima/disks/mydisk/data qemu-img convert -O qcow2 ~/.lima/disks/mydisk/data mydisk-fixed.qcow2 # replace the corrupt data file, then retry
Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("qemu-img", "info", dataFile).CombinedOutput()
if err != nil { return fmt.Errorf("disk image invalid: %s", out) } Try / catch
sz, format, err := store.InspectDisk(diskDir)
if err != nil {
// treat as corrupt disk: suggest qemu-img check or recreate
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- disk format %#q not supported, use `qcow2` or `raw` instead
- disk %#q already exists (%#q)
- failed to remove a directory %#q: %w
- failed to create %s disk in %#q: %w
- cannot delete disk %#q in use by instance %#q
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/b1f5e018a8bf2849.
Report an issue: GitHub.