lima-vm/lima · error
cannot safely prune while instance %#q is being used: %w
Error message
cannot safely prune while instance %#q is being used: %w
What it means
knownLocations enumerates instances to decide what prune may safely delete. If store.Inspect on a listed instance returns an error that is os.ErrNotExist, the listing is stale relative to the disk, so prune aborts with "cannot safely prune while instance <name> is being used" rather than deleting data based on inconsistent state. Other inspect errors are returned unwrapped.
Source
Thrown at cmd/limactl/prune.go:86
}
// Sweep leftover partial downloads (data.part / data.tmp.*) from the kept entries.
return downloader.RemoveStaleTempFiles(opt)
}
func knownLocations(ctx context.Context) (map[string]limatype.File, error) {
locations := make(map[string]limatype.File)
// Collect locations from instances
instances, err := store.Instances()
if err != nil {
return nil, err
}
for _, instanceName := range instances {
instance, err := store.Inspect(ctx, instanceName)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("cannot safely prune while instance %#q is being used: %w", instanceName, err)
}
return nil, err
}
if instance.Errors != nil {
logrus.Warnf("skipping instance %#q because it has errors: %v", instanceName, instance.Errors)
continue
}
maps.Copy(locations, locationsFromLimaYAML(instance.Config))
}
// Collect locations from templates
templates, err := templatestore.Templates()
if err != nil {
return nil, err
}
for _, t := range templates {
tmpl, err := limatmpl.Read(ctx, "", t.Location)
if err != nil {View on GitHub (pinned to dd909d0973)
Solutions
- Re-run `limactl prune` once no other limactl commands are executing
- Run `limactl list` to refresh/verify consistent instance state, then prune
- Remove the stale/ghost instance reference (e.g. finish the interrupted delete) and retry
Example fix
// before limactl prune & limactl delete myvm --force # racy // after limactl delete myvm --force limactl prune
Defensive patterns
Strategy: retry
Validate before calling
# ensure no other limactl operation is in flight
pgrep -f 'limactl (delete|prune)' && { echo 'lima operation in progress' >&2; exit 1; } Try / catch
if err := pruneCmd.Run(); err != nil {
if strings.Contains(err.Error(), "cannot safely prune while instance") {
time.Sleep(2 * time.Second)
// retry prune once concurrent operations have finished
}
} Prevention
- Do not run prune concurrently with instance create/delete
- Refresh state with `limactl list` after external modifications to ~/.lima
- Clean up interrupted deletes before pruning
When it happens
Trigger: An instance directory listed by store.Instances() disappeared (concurrent `limactl delete`, external rm) between listing and inspection while running `limactl prune`.
Common situations: Running prune in parallel with instance deletion; manually removing ~/.lima/instance dirs while Lima commands run; race with another limactl process in CI.
Related errors
- instance %q not found
- instance %#q not found
- failed to delete instance %#q: %w
- instance %#q directory %#q exists but its %#q could not be r
- failed to inspect instance %#q: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/a6a5b6b379b43c90.
Report an issue: GitHub.