lima-vm/lima · error
in use by instance %#q
Error message
in use by instance %#q
What it means
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.
Source
Thrown at pkg/store/disk.go:104
}
return sz, string(img.Type()), nil
}
func (d *Disk) Lock(instanceDir string) error {
inUseBy := filepath.Join(d.Dir, filenames.InUseBy)
return os.Symlink(instanceDir, inUseBy)
}
func (d *Disk) Unlock() error {
inUseBy := filepath.Join(d.Dir, filenames.InUseBy)
return os.Remove(inUseBy)
}
func (d *Disk) LockForInstance(instanceDir string) error {
if d.Instance != "" {
if d.InstanceDir != instanceDir {
return fmt.Errorf("in use by instance %#q", d.Instance)
}
if err := d.Unlock(); err != nil {
return fmt.Errorf("failed to unlock for reuse in the same instance: %w", err)
}
}
return d.Lock(instanceDir)
}
View on GitHub (pinned to dd909d0973)
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.
Example fix
// before limactl start inst-b # disk 'data' in use by inst-a // after limactl stop inst-a limactl start inst-b
Defensive patterns
Strategy: retry
Validate before calling
d, err := store.InspectDisk(diskDir)
if err == nil && d.Instance != "" && d.InstanceDir != myInstDir {
return fmt.Errorf("disk busy with %s; stop it first", d.Instance)
} Try / catch
err := disk.LockForInstance(instanceDir)
if err != nil {
if strings.Contains(err.Error(), "in use by instance") {
// limactl stop <owner> or clear stale in-use-by, then retry
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- failed to attach disk %#q: %w
- failed to unlock for reuse in the same instance: %w
- disk format %#q not supported, use `qcow2` or `raw` instead
- disk %#q already exists (%#q)
- failed to remove a directory %#q: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/11ba7fad9a4caaeb.
Report an issue: GitHub.