lima-vm/lima · error
failed to delete instance %#q: %w
Error message
failed to delete instance %#q: %w
What it means
`limactl delete` failed while removing the instance via instance.Delete (which stops the VM if needed, unmounts, and removes the instance directory). The per-instance store error is wrapped with the instance name. Any sub-step — stopping the hostagent/guestagent, removing mounts, deleting the directory — can be the root cause surfaced in %w.
Source
Thrown at cmd/limactl/delete.go:55
ctx := cmd.Context()
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
var errs []error
for _, instName := range args {
inst, err := store.Inspect(ctx, instName)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
if err := warnAboutMissingInstance(instName); err != nil {
errs = append(errs, err)
}
continue
}
return err
}
if err := instance.Delete(ctx, inst, force); err != nil {
return fmt.Errorf("failed to delete instance %#q: %w", instName, err)
}
if registered, err := autostart.IsRegistered(ctx, inst); err != nil && !errors.Is(err, autostart.ErrNotSupported) {
logrus.WithError(err).Warnf("Failed to check if the autostart entry for instance %#q is registered", instName)
} else if registered {
if err := autostart.UnregisterFromStartAtLogin(ctx, inst); err != nil {
logrus.WithError(err).Warnf("Failed to unregister the autostart entry for instance %#q", instName)
} else {
logrus.Infof("The autostart entry for instance %#q has been unregistered", instName)
}
}
logrus.Infof("Deleted %#q (%#q)", instName, inst.Dir)
}
if err := reconcile.Reconcile(ctx, ""); err != nil {
errs = append(errs, err)
}
return errors.Join(errs...)
}
View on GitHub (pinned to dd909d0973)
Solutions
- Stop the instance first: `limactl stop <inst>`, then delete again
- Use `limactl delete --force <inst>` to skip graceful stop
- Check for lingering lima processes (hostagent/qemu/vz) holding files in the instance dir and kill them
- Fix permissions on ~/.lima/instances/<inst> (chown back to the current user)
- If only the directory remains and lima.yaml is unreadable, remove the directory manually per the missing-instance guidance
Example fix
// before $ limactl delete myvm // failed to delete instance "myvm": instance is running // after $ limactl stop myvm && limactl delete myvm // or $ limactl delete --force myvm
Defensive patterns
Strategy: validation
Validate before calling
const inst = await inspectInstance(name)
if (inst.status === 'Running' && !force) {
await stopInstance(name)
} Type guard
function isRunning(inst: {status?: string}): boolean {
return inst?.status === 'Running'
} Try / catch
try {
await deleteInstance(name)
} catch (err) {
if (/running|in use/i.test(err.message)) {
await deleteInstance(name, { force: true })
} else throw err
} Prevention
- Always `limactl stop` before delete in automation
- Check no other limactl processes hold the instance
- Avoid running limactl as root on instances created as a normal user
- Use --force only when the instance is known disposable
When it happens
Trigger: `limactl delete <inst>` where instance.Delete errors: VM still running and force not passed, files inside the instance dir held open/locked, permission problems on ${LIMA_HOME}/instances/<name>, or partially corrupted instance state.
Common situations: Deleting a running instance without --force; another limactl process concurrently using the instance; NFS/network home directories with stale locks; root-created instances later managed by an unprivileged user.
Related errors
- instance %#q not found
- instance %#q directory %#q exists but its %#q could not be r
- instance %q not found
- failed to unregister instance %#q from start at login: %w
- disk %#q already exists (%#q)
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/edb2be6525409b47.
Report an issue: GitHub.