{"record":{"id":"15cd81980a2b066f","repo":"lima-vm/lima","slug":"cannot-delete-disk-q-in-use-by-instance-q","errorCode":null,"errorMessage":"cannot delete disk %#q in use by instance %#q","messagePattern":"cannot delete disk %#q in use by instance %#q","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/disk.go","lineNumber":268,"sourceCode":"\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tinstances = append(instances, inst)\n\t}\n\n\tfor _, diskName := range args {\n\t\tdisk, err := store.InspectDisk(diskName, nil)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, fs.ErrNotExist) {\n\t\t\t\tlogrus.Warnf(\"Ignoring non-existent disk %#q\", diskName)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn err\n\t\t}\n\n\t\tif !force {\n\t\t\tif disk.Instance != \"\" {\n\t\t\t\treturn fmt.Errorf(\"cannot delete disk %#q in use by instance %#q\", disk.Name, disk.Instance)\n\t\t\t}\n\t\t\tvar refInstances []string\n\t\t\tfor _, inst := range instances {\n\t\t\t\tfor _, d := range inst.AdditionalDisks {\n\t\t\t\t\tif d.Name == diskName {\n\t\t\t\t\t\trefInstances = append(refInstances, inst.Name)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif len(refInstances) > 0 {\n\t\t\t\tlogrus.Warnf(\"Skipping deleting disk %#q, disk is referenced by one or more non-running instances: %#q\",\n\t\t\t\t\tdiskName, refInstances)\n\t\t\t\tlogrus.Warnf(\"To delete anyway, run %#q\", forceDeleteCommand(diskName))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tif err := deleteDisk(disk); err != nil {","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/disk.go#L250-L286","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Remove the disk from every instance's additionalDisks (edit ~/.lima/instances/<inst>/lima.yaml or recreate config), then delete again","If the owning instance is no longer needed, `limactl delete` that instance first","Use `limactl disk delete <name> --force` if you are certain nothing will use the disk anymore","Run `limactl list` / inspect instance configs to find which instance references the disk"],"exampleFix":"// before\n$ limactl disk delete data\n// cannot delete disk \"data\" in use by instance \"myvm\"\n// after\n$ limactl disk delete data --force\n// or edit ~/.lima/instances/myvm/lima.yaml to drop \"data\" from additionalDisks, then:\n$ limactl disk delete data","handlingStrategy":"validation","validationCode":"const disk = await inspectDisk(name)\nif (disk.instance) throw new Error(`detach disk from ${disk.instance} first`)","typeGuard":"function isDiskInUse(disk: {instance?: string, refInstances?: string[]}): boolean {\n  return Boolean(disk.instance || disk.refInstances?.length)\n}","tryCatchPattern":"try {\n  await deleteDisk(name)\n} catch (err) {\n  if (/in use by instance/.test(err.message)) {\n    console.error('Remove the disk from the instance additionalDisks, or use --force')\n  } else throw err\n}","preventionTips":["Remove disks from lima.yaml additionalDisks before deleting them","Use `limactl disk list` to check the INSTANCE column first","Reserve --force for disks you are certain are abandoned"],"tags":["disk","in-use","delete"],"backgroundTag":"disk-in-use","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}