lima-vm/lima · error

failed to create %s disk in %#q: %w

Error message

failed to create %s disk in %#q: %w

What it means

The underlying disk image creation failed. diskUtil.CreateDisk (which shells out to qemu-img via proxyimgutil) returned an error while creating the data disk inside the new disk directory; Lima wraps it with the format and directory, having already attempted (and joined, if it failed) directory cleanup.

Source

Thrown at cmd/limactl/disk.go:124

		return fmt.Errorf("disk %#q already exists (%#q)", name, diskDir)
	}

	logrus.Infof("Creating %s disk %#q with size %s", format, name, units.BytesSize(float64(diskSize)))

	if err := os.MkdirAll(diskDir, 0o700); err != nil {
		return err
	}

	// qemu may not be available, use it only if needed.
	dataDisk := filepath.Join(diskDir, filenames.DataDisk)
	diskUtil := proxyimgutil.NewDiskUtil(ctx)
	err = diskUtil.CreateDisk(ctx, dataDisk, diskSize)
	if err != nil {
		rerr := os.RemoveAll(diskDir)
		if rerr != nil {
			err = errors.Join(err, fmt.Errorf("failed to remove a directory %#q: %w", diskDir, rerr))
		}
		return fmt.Errorf("failed to create %s disk in %#q: %w", format, diskDir, err)
	}

	return nil
}

func newDiskListCommand() *cobra.Command {
	diskListCommand := &cobra.Command{
		Use: "list",
		Example: `
To list existing disks:
$ limactl disk list
`,
		Short:   "List existing Lima disks",
		Aliases: []string{"ls"},
		Args:    WrapArgsError(cobra.ArbitraryArgs),
		RunE:    diskListAction,
	}
	diskListCommand.Flags().Bool("json", false, "JSONify output")

View on GitHub (pinned to dd909d0973)

Solutions

  1. Install/verify qemu-img: qemu-img --version (part of qemu-utils)
  2. Check free space on the filesystem holding ~/.lima/disks
  3. Validate the --size value (e.g. 10GiB) and the --format (qcow2/raw)
  4. Inspect the wrapped %w error for the exact qemu-img failure and fix accordingly

Example fix

// before
$ limactl disk create data --size 10GiB
// failed to create qcow2 disk in "...": exec: "qemu-img": executable file not found
// after
$ brew install qemu   # or apt install qemu-utils
$ limactl disk create data --size 10GiB
Defensive patterns

Strategy: try-catch

Validate before calling

const { execFileSync } = require('child_process')
try { execFileSync('qemu-img', ['--version']) } catch { throw new Error('qemu-img is required for limactl disk create') }

Type guard

function isCreateDiskErr(err: unknown): boolean {
  return err instanceof Error && /failed to create .* disk/.test(err.message)
}

Try / catch

try {
  await createDisk(name, { size: '10GiB' })
} catch (err) {
  if (isCreateDiskErr(err)) {
    console.error('Check qemu-img install, free space, and size syntax:', err.cause ?? err)
  } else throw err
}

Prevention

When it happens

Trigger: `limactl disk create` when qemu-img is unavailable/misbehaving: qemu-img not installed, unsupported size syntax, full disk, or qemu-img exiting nonzero on the target filesystem.

Common situations: Missing qemu-img in PATH on the host; specifying size like 10GB vs 10GiB issues; no space left on device; read-only or incompatible filesystem for qcow2.

Related errors


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