lima-vm/lima · error

failed to create disk %#q: %w

Error message

failed to create disk %#q: %w

What it means

EnsureDisk creates the instance's data disk by converting the base image to a qcow2 of the requested size. When diskUtil.Convert fails, the partially created disk is removed, the ISO/image is restored, and this wrapped error is returned. It surfaces the underlying conversion-tool failure (usually qemu-img).

Source

Thrown at pkg/driverutil/disk.go:96

	if isISO {
		isoPath := filepath.Join(instDir, filenames.ISO)
		if err := os.Rename(imagePath, isoPath); err != nil {
			return err
		}
		f, err := os.Create(diskPath)
		if err != nil {
			_ = os.Rename(isoPath, imagePath)
			return err
		}
		if err := f.Close(); err != nil {
			os.Remove(diskPath)
			_ = os.Rename(isoPath, imagePath)
			return err
		}
		if err := diskUtil.Convert(ctx, diskImageFormat, diskPath, diskPath, &diskSizeInBytes, false); err != nil {
			os.Remove(diskPath)
			_ = os.Rename(isoPath, imagePath)
			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)

View on GitHub (pinned to dd909d0973)

Solutions

  1. Read the wrapped cause; install/repair qemu-img (`qemu-img --version`) and ensure it is on PATH
  2. Verify the base image integrity (checksum) and re-download if corrupt
  3. Increase the instance's disk size or free space on the host volume
  4. Retry instance creation after cleaning the partial files in the instance dir

Example fix

# before
$ limactl create inst   # failed to create disk "/home/u/.lima/inst/disk": exit status 1
# after
$ which qemu-img || sudo apt install qemu-utils
$ limactl delete -f inst && limactl create inst
Defensive patterns

Strategy: try-catch

Validate before calling

func diskCreationPrecheck(imagePath string, diskSize int64) error {
	if _, err := exec.LookPath("qemu-img"); err != nil {
		return fmt.Errorf("qemu-img not installed: %w", err)
	}
	fi, err := os.Stat(imagePath)
	if err != nil { return err }
	if diskSize < fi.Size() { return fmt.Errorf("disk size %d smaller than image %d", diskSize, fi.Size()) }
	return nil
}

Type guard

func qemuImgAvailable() bool {
	_, err := exec.LookPath("qemu-img")
	return err == nil
}

Try / catch

if err := driverutil.EnsureDisk(ctx, ...); err != nil {
	if strings.Contains(err.Error(), "failed to create disk") {
		// inspect wrapped cause: reinstall qemu-utils, verify image,
		// free space, then retry
	}
	return err
}

Prevention

When it happens

Trigger: EnsureDisk (called by CreateDisk) has an ISO base image, converts iso->disk via diskUtil.Convert with the requested disk size, and Convert returns an error (bad ISO, unsupported format, qemu-img missing, insufficient space, invalid size).

Common situations: qemu-img not installed or not on PATH; corrupted base image download; disk size smaller than the image; out-of-disk-space on the host; permission issues in the instance dir.

Related errors


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