lima-vm/lima · error

failed to convert %#q to %#q: %w

Error message

failed to convert %#q to %#q: %w

What it means

EnsureDisk wraps a failure from diskUtil.Convert, which shells out to an image tool (qemu-img style via proxyimgutil) to convert the downloaded image to the requested disk format and size. Lima throws this when the conversion tool fails or is unavailable. The wrapped error contains the tool's own message.

Source

Thrown at pkg/driverutil/disk.go:114

			return fmt.Errorf("failed to create disk %#q: %w", diskPath, err)
		}
	} else {
		format, err := nativeimgutil.DetectFormat(imagePath)
		if err != nil {
			return err
		}

		// Resize handled by prepareDisk() after CreateDisk()
		if format == string(diskImageFormat) {
			if err = os.Rename(imagePath, diskPath); err != nil {
				return fmt.Errorf("failed to rename %#q to %#q: %w", imagePath, diskPath, err)
			}
			if err := os.Chmod(diskPath, 0o644); err != nil {
				return fmt.Errorf("failed to chmod %#q: %w", diskPath, err)
			}
		} else {
			if err := diskUtil.Convert(ctx, diskImageFormat, imagePath, diskPath, &diskSizeInBytes, false); err != nil {
				return fmt.Errorf("failed to convert %#q to %#q: %w", imagePath, diskPath, err)
			}
			os.Remove(imagePath)
		}
	}
	return nil
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Read the wrapped error for the underlying tool message; install qemu-utils (or the platform equivalent) if it is a missing-binary error
  2. Re-download the image; verify it with nativeimgutil.DetectFormat or qemu-img info to rule out corruption
  3. Check free disk space in instDir and use a valid diskSize value
  4. Set the instance's vmType/image format so requested diskImageFormat matches the downloaded image format, avoiding conversion entirely

Example fix

// before: conversion fails with exec: "qemu-img": executable file not found
// after: install the tool
//   Debian/Ubuntu: apt-get install qemu-utils
//   macOS: brew install qemu
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := exec.LookPath("qemu-img"); err != nil {
    return fmt.Errorf("qemu-img required for image conversion: %w", err)
}

Try / catch

if err := driverutil.EnsureDisk(ctx, instDir, diskSize, format); err != nil {
    if strings.Contains(err.Error(), "failed to convert") {
        // check free space, tool availability, then retry once after re-download
    }
    return err
}

Prevention

When it happens

Trigger: EnsureDisk detects the image format differs from the requested diskImageFormat and calls Convert; conversion fails because qemu-img (or equivalent) is not installed, the source image is corrupt, the target size is invalid, or disk is full.

Common situations: Minimal host without qemu-utils installed; downloaded image truncated/corrupt (interrupted download); disk size string parsed to 0 or too large for free space; incompatible source format the proxy tool cannot handle.

Related errors


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