lima-vm/lima · error

cannot delete disk %#q in use by instance %#q

Error message

cannot delete disk %#q in use by instance %#q

What it means

`limactl disk delete` refuses to delete a disk that is currently attached to an instance. Either disk.Instance names a direct owner, or (without --force) the disk appears in some instance's additionalDisks. Lima protects against breaking a running/parked instance that references the disk.

Source

Thrown at cmd/limactl/disk.go:268

		if err != nil {
			continue
		}
		instances = append(instances, inst)
	}

	for _, diskName := range args {
		disk, err := store.InspectDisk(diskName, nil)
		if err != nil {
			if errors.Is(err, fs.ErrNotExist) {
				logrus.Warnf("Ignoring non-existent disk %#q", diskName)
				continue
			}
			return err
		}

		if !force {
			if disk.Instance != "" {
				return fmt.Errorf("cannot delete disk %#q in use by instance %#q", disk.Name, disk.Instance)
			}
			var refInstances []string
			for _, inst := range instances {
				for _, d := range inst.AdditionalDisks {
					if d.Name == diskName {
						refInstances = append(refInstances, inst.Name)
					}
				}
			}
			if len(refInstances) > 0 {
				logrus.Warnf("Skipping deleting disk %#q, disk is referenced by one or more non-running instances: %#q",
					diskName, refInstances)
				logrus.Warnf("To delete anyway, run %#q", forceDeleteCommand(diskName))
				continue
			}
		}

		if err := deleteDisk(disk); err != nil {

View on GitHub (pinned to dd909d0973)

Solutions

  1. Remove the disk from every instance's additionalDisks (edit ~/.lima/instances/<inst>/lima.yaml or recreate config), then delete again
  2. If the owning instance is no longer needed, `limactl delete` that instance first
  3. Use `limactl disk delete <name> --force` if you are certain nothing will use the disk anymore
  4. Run `limactl list` / inspect instance configs to find which instance references the disk

Example fix

// before
$ limactl disk delete data
// cannot delete disk "data" in use by instance "myvm"
// after
$ limactl disk delete data --force
// or edit ~/.lima/instances/myvm/lima.yaml to drop "data" from additionalDisks, then:
$ limactl disk delete data
Defensive patterns

Strategy: validation

Validate before calling

const disk = await inspectDisk(name)
if (disk.instance) throw new Error(`detach disk from ${disk.instance} first`)

Type guard

function isDiskInUse(disk: {instance?: string, refInstances?: string[]}): boolean {
  return Boolean(disk.instance || disk.refInstances?.length)
}

Try / catch

try {
  await deleteDisk(name)
} catch (err) {
  if (/in use by instance/.test(err.message)) {
    console.error('Remove the disk from the instance additionalDisks, or use --force')
  } else throw err
}

Prevention

When it happens

Trigger: `limactl disk delete <name>` where the disk is referenced by an instance (disk.Instance non-empty, or listed in inst.AdditionalDisks) and --force was not passed.

Common situations: Forgetting to detach/remove the disk from the instance config (lima.yaml additionalDisks) before deleting; deleting a disk still used by a stopped-but-existing instance.

Related errors


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