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

  1. Inspect the image with qemu-img info <file> to see whether the header is valid and the size is sane.
  2. Delete and recreate the disk with limactl disk create if the image is corrupt and contains no needed data.
  3. 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

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


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