lima-vm/lima · error

failed to remove the autostart entry for instance %#q: %w

Error message

failed to remove the autostart entry for instance %#q: %w

What it means

os.Remove of the autostart entry file failed after the disable step succeeded. The wrapper tells you which instance's entry could not be removed; the wrapped error carries the OS reason (most commonly ENOENT from a race, or EACCES/EPERM).

Source

Thrown at pkg/autostart/managers.go:110

	if t.enabler != nil {
		return t.enabler(ctx, true, inst.Name)
	}
	return nil
}

func (t *TemplateFileBasedManager) UnregisterFromStartAtLogin(ctx context.Context, inst *limatype.Instance) error {
	if registered, err := t.IsRegistered(ctx, inst); err != nil {
		return fmt.Errorf("failed to check if the autostart entry for instance %#q is registered: %w", inst.Name, err)
	} else if !registered {
		return nil
	}
	if t.enabler != nil {
		if err := t.enabler(ctx, false, inst.Name); err != nil {
			return fmt.Errorf("failed to disable the autostart entry for instance %#q: %w", inst.Name, err)
		}
	}
	if err := os.Remove(t.filePath(inst.Name)); err != nil {
		return fmt.Errorf("failed to remove the autostart entry for instance %#q: %w", inst.Name, err)
	}
	return nil
}

func (t *TemplateFileBasedManager) renderTemplate(instName, workDir string, getExecutable func() (string, error)) ([]byte, error) {
	if t.template == "" {
		return nil, errors.New("no template available")
	}
	selfExeAbs, err := getExecutable()
	if err != nil {
		return nil, err
	}
	data := map[string]string{
		"Binary":   selfExeAbs,
		"Instance": instName,
		"WorkDir":  workDir,
	}
	maps.Copy(data, t.extraTemplateVars)

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check the wrapped error: if ENOENT, the entry is already gone — treat unregister as done
  2. Fix ownership/permissions on the entry file and its directory (chown back to your user; avoid running limactl with sudo)
  3. Remove manually: delete ~/.config/systemd/user/lima-<instance>.service (Linux) or ~/Library/LaunchAgents/lima-*.plist (macOS) and reload

Example fix

// before: entry owned by root after sudo use
sudo chown -R $USER ~/.config/systemd/user
// after: retry
limactl autostart remove default
Defensive patterns

Strategy: try-catch

Validate before calling

path := entryPath(inst.Name)
if _, err := os.Stat(path); err == nil {
    if fi, err2 := os.Stat(filepath.Dir(path)); err2 != nil || !isWritable(fi) {
        // fix dir permissions before unregister
    }
}

Try / catch

if err := mgr.UnregisterFromStartAtLogin(ctx, inst); err != nil {
    var pathErr *os.PathError
    if errors.As(err, &pathErr) && errors.Is(pathErr.Err, syscall.ENOENT) {
        return nil // already removed concurrently
    }
    return err
}

Prevention

When it happens

Trigger: UnregisterFromStartAtLogin: IsRegistered returned true, disable succeeded, then os.Remove(t.filePath(inst.Name)) failed — e.g. the file was deleted concurrently, the directory is read-only, or an immutable/ACL flag blocks deletion.

Common situations: Another limactl process or the user removed the entry file between the stat and the remove; ~/.config/systemd/user or ~/Library/LaunchAgents permissions changed; entry file owned by another user after running limactl with sudo previously.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/fa5d65398067df81. Report an issue: GitHub.