lima-vm/lima · error

failed to remove %s: %w

Error message

failed to remove %s: %w

What it means

daemonUninstall removes the LaunchDaemon plist with `sudo rm -f <dest>` after booting out and disabling the service; this error wraps that rm failure. Since rm -f rarely fails on a missing file, this usually means sudo was denied or the file is protected.

Source

Thrown at cmd/limactl/autostart_darwin.go:154

		return fmt.Errorf("failed to enable LaunchDaemon: %w", err)
	}
	if err := runSudo(ctx, "launchctl", "bootstrap", "system", destPath); err != nil {
		return fmt.Errorf("failed to bootstrap LaunchDaemon: %w", err)
	}

	logrus.Infof("LaunchDaemon installed for instance %q (runs as %q at boot)", instName, userName)
	logrus.Infof("Plist: %s", destPath)
	return nil
}

func daemonUninstall(ctx context.Context, instName string) error {
	svcTarget := "system/" + launchd.DaemonServiceNameFrom(instName)
	destPath := launchd.GetDaemonPlistPath(instName)

	_ = runSudo(ctx, "launchctl", "bootout", svcTarget)
	_ = runSudo(ctx, "launchctl", "disable", svcTarget)
	if err := runSudo(ctx, "rm", "-f", destPath); err != nil {
		return fmt.Errorf("failed to remove %s: %w", destPath, err)
	}
	logrus.Infof("LaunchDaemon uninstalled for instance %q", instName)
	return nil
}

// runSudo executes a command under sudo, inheriting the terminal so password prompts work.
func runSudo(ctx context.Context, args ...string) error {
	cmd := exec.CommandContext(ctx, "sudo", args...) //nolint:gosec // args are constructed internally, not from user input
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Stdin = os.Stdin
	logrus.Infof("running: sudo %v", args)
	return cmd.Run()
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Rerun interactively and enter the sudo password
  2. Verify sudo rights: `sudo -v`
  3. Remove manually if policy allows: `sudo rm -f /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist`
  4. Check MDM/security-agent restrictions on /Library/LaunchDaemons

Example fix

// before: limactl autostart --uninstall myinstance  (sudo: no tty)
// after:  sudo -v && limactl autostart --uninstall myinstance
Defensive patterns

Strategy: try-catch

Validate before calling

sudo -v 2>/dev/null || { echo "sudo unavailable"; exit 1; }
ls -l /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist 2>/dev/null

Try / catch

if err := daemonUninstall(ctx, inst.Name); err != nil {
	if strings.Contains(err.Error(), "failed to remove") {
		logrus.Warn("Plist removal failed; remove manually: sudo rm -f /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist")
		return
	}
	panic(err)
}

Prevention

When it happens

Trigger: `limactl autostart --uninstall <instance>` (autostartDisableAction) on macOS when a boot-mode daemon exists at /Library/LaunchDaemons/io.lima-vm.daemon.<instance>.plist and `sudo rm -f` exits nonzero: canceled password prompt, non-admin user, or MDM/SIP protection on the path.

Common situations: Running disable from a script without a TTY so sudo cannot prompt for a password; managed Macs where LaunchDaemons writes are policy-blocked; stale plist owned by root with restrictive permissions and sudo refused.

Related errors


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