lima-vm/lima · error
failed to run %v: %w (output=%s)
Error message
failed to run %v: %w (output=%s)
What it means
Lima's VZ driver stops the VM by SSHing into the guest and running `sudo /sbin/shutdown -h now`. If the ssh command exits non-zero, the driver wraps the exit error plus the combined stdout/stderr output in this error. It means the guest-side shutdown command did not run successfully.
Source
Thrown at pkg/driver/vz/vz_driver_darwin.go:497
func (l *LimaVzDriver) RunGUI(_ context.Context) error {
if l.canRunGUI() {
title := fmt.Sprintf("Lima: %s", l.Instance.Name)
return l.machine.StartGraphicApplication(1920, 1200, vz.WithWindowTitle(title))
}
return fmt.Errorf("RunGUI is not supported for the given driver '%s' and display '%s'", "vz", *l.Instance.Config.Video.Display)
}
func (l *LimaVzDriver) requestStopViaSSH(ctx context.Context) error {
sshExe, err := sshutil.NewSSHExe()
if err != nil {
return err
}
cmd := exec.CommandContext(ctx, sshExe.Exe,
append(sshExe.Args, "-F", l.Instance.SSHConfigFile, l.Instance.Hostname, "--",
"sudo", "/sbin/shutdown", "-h", "now")...)
logrus.Infof("Running shutdown command in the VM: %v", cmd.Args)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to run %v: %w (output=%s)", cmd.Args, err, string(out))
}
return nil
}
func (l *LimaVzDriver) Stop(ctx context.Context) error {
logrus.Info("Shutting down VZ")
canStop := l.machine.CanRequestStop()
if canStop {
_, err := l.machine.RequestStop()
if err != nil {
return err
}
if *l.Instance.Config.OS == limatype.DARWIN {
// macOS VM does not respond to l.machine.RequestStop(),
// so we need to run `shutdown -h now` in the VM via SSH for graceful shutdown.
if err := l.requestStopViaSSH(ctx); err != nil {View on GitHub (pinned to dd909d0973)
Solutions
- Re-run `limactl stop <instance>`; transient races during shutdown often succeed on retry
- Check ssh connectivity manually: `limactl shell <instance> -- true` or `ssh -F ~/.lima/<instance>/ssh.config lima-<instance>` to see the underlying failure
- Inspect the captured output in the error message (output=...) for the guest-side reason (e.g. sudo: no tty, command not found)
- If the guest is stuck, use `limactl stop --force <instance>` to kill the VM without the graceful ssh shutdown
- Regenerate the instance ssh config (`limactl factory-reset`) if keys/config under ${LIMA_HOME} were modified
Example fix
// before (debugging raw failure)
err := driver.Stop(ctx) // opaque
// after (get details)
if err := driver.Stop(ctx); err != nil {
log.Printf("stop failed: %v; try: limactl shell <inst> -- sudo /sbin/shutdown -h now", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// before stopping, verify guest is reachable
out, err := exec.Command("limactl", "shell", inst, "--", "true").CombinedOutput()
if err != nil {
// ssh already broken: use force stop instead of graceful
exec.Command("limactl", "stop", "--force", inst).Run()
} Type guard
// Go: unwrap and inspect
var ee *exec.ExitError
if errors.As(err, &ee) { /* ssh exit code in ee.ExitCode() */ } Try / catch
if err := driver.Stop(ctx); err != nil {
if strings.Contains(err.Error(), "failed to run") {
_ = driver.Stop(ctx) // retry once, then force
}
} Prevention
- Don't edit ssh.config or keys under ${LIMA_HOME} manually
- Check `limactl list` state before stopping
- Prefer `limactl stop` over killing VM processes
- Keep guest systemd healthy so shutdown doesn't race sshd
When it happens
Trigger: requestStopViaSSH is called (from Stop) and the `ssh ... -- sudo /sbin/shutdown -h now` command returns a non-zero exit code, e.g. ssh cannot authenticate, the guest is already half-down, or shutdown is not present/allowed via sudo.
Common situations: Guest agent/sshd already died during shutdown race; SSH key or host key mismatch; guest booted without sudo rights for the lima user; a slow/busy guest where init rejected the shutdown request; wiping or replacing files under ~/.lima that hold the SSH config.
Related errors
- vz timeout while waiting for stop status
- vz: CanRequestStop is not supported
- failed to get macOS product version: %w
- failed to create a new rosetta directory share caching optio
- vz driver state stopped
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/62b8028e2c25a2a9.
Report an issue: GitHub.