{"record":{"id":"11ba7fad9a4caaeb","repo":"lima-vm/lima","slug":"in-use-by-instance-q","errorCode":null,"errorMessage":"in use by instance %#q","messagePattern":"in use by instance %#q","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/disk.go","lineNumber":104,"sourceCode":"\t}\n\n\treturn sz, string(img.Type()), nil\n}\n\nfunc (d *Disk) Lock(instanceDir string) error {\n\tinUseBy := filepath.Join(d.Dir, filenames.InUseBy)\n\treturn os.Symlink(instanceDir, inUseBy)\n}\n\nfunc (d *Disk) Unlock() error {\n\tinUseBy := filepath.Join(d.Dir, filenames.InUseBy)\n\treturn os.Remove(inUseBy)\n}\n\nfunc (d *Disk) LockForInstance(instanceDir string) error {\n\tif d.Instance != \"\" {\n\t\tif d.InstanceDir != instanceDir {\n\t\t\treturn fmt.Errorf(\"in use by instance %#q\", d.Instance)\n\t\t}\n\t\tif err := d.Unlock(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to unlock for reuse in the same instance: %w\", err)\n\t\t}\n\t}\n\treturn d.Lock(instanceDir)\n}\n","sourceCodeStart":86,"sourceCodeEnd":112,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/store/disk.go#L86-L112","documentation":"Disk.LockForInstance enforces that a disk is attached to at most one instance at a time, tracked via the 'in-use-by' lock metadata. If the disk's recorded instance differs from the requested instanceDir, the attach is rejected naming the owning instance.","triggerScenarios":"Starting or attaching instance B to a disk whose metadata says it is in use by instance A (d.Instance set and d.InstanceDir != instanceDir).","commonSituations":"Two lima.yaml files referencing the same limactl disk; a crashed instance left the lock metadata stale (disk still marked in-use); running the same instance from two different directories or copies of the instance dir.","solutions":["Stop the instance currently using the disk (limactl stop <instance>) so it releases the lock.","If the owning instance is gone/crashed and the lock is stale, delete the in-use-by marker file in the disk directory (limactl disk unlock if available, or remove ~/.lima/disks/<disk>/in-use-by).","Change your instance config to reference a different disk not already in use."],"exampleFix":"// before\nlimactl start inst-b   # disk 'data' in use by inst-a\n// after\nlimactl stop inst-a\nlimactl start inst-b","handlingStrategy":"retry","validationCode":"d, err := store.InspectDisk(diskDir)\nif err == nil && d.Instance != \"\" && d.InstanceDir != myInstDir {\n    return fmt.Errorf(\"disk busy with %s; stop it first\", d.Instance)\n}","typeGuard":null,"tryCatchPattern":"err := disk.LockForInstance(instanceDir)\nif err != nil {\n    if strings.Contains(err.Error(), \"in use by instance\") {\n        // limactl stop <owner> or clear stale in-use-by, then retry\n    }\n    return err\n}","preventionTips":["Stop the owning instance before attaching the disk elsewhere","After crashes, clear stale in-use-by markers","Never share one disk between concurrently running instances"],"tags":["disk","locking","resource-conflict"],"backgroundTag":"disk-already-in-use","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}