lima-vm/lima · error

failed to start the instance %#q via systemctl: %w

Error message

failed to start the instance %#q via systemctl: %w

What it means

systemd.RequestStart runs `systemctl --user start lima-<instance>.service` to start an auto-started instance; this error wraps a non-zero systemctl exit. The instance was NOT started; the wrapped error contains systemctl's own message (e.g. 'Unit not found' or 'Job failed').

Source

Thrown at pkg/autostart/systemd/systemd.go:62

	return systemctl(ctx, "--user", action, UnitNameFrom(instName))
}

func systemctl(ctx context.Context, args ...string) error {
	cmd := exec.CommandContext(ctx, "systemctl", args...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	logrus.Debugf("running command: %v", cmd.Args)
	return cmd.Run()
}

// AutoStartedUnitName returns the systemd service name if the instance is started by systemd.
func AutoStartedUnitName() string {
	return CurrentUnitName()
}

func RequestStart(ctx context.Context, inst *limatype.Instance) error {
	if err := systemctl(ctx, "--user", "start", UnitNameFrom(inst.Name)); err != nil {
		return fmt.Errorf("failed to start the instance %#q via systemctl: %w", inst.Name, err)
	}
	return nil
}

func RequestStop(ctx context.Context, inst *limatype.Instance) (bool, error) {
	if inst.AutoStartedIdentifier == UnitNameFrom(inst.Name) {
		logrus.Infof("Stopping the instance %#q started by systemd", inst.Name)
		if err := systemctl(ctx, "--user", "stop", inst.AutoStartedIdentifier); err != nil {
			return false, fmt.Errorf("failed to stop the instance %#q via systemctl: %w", inst.Name, err)
		}
		return true, nil
	}
	return false, nil
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Run `systemctl --user status lima-<instance>.service` and `journalctl --user -u lima-<instance>.service` to see the root cause
  2. Re-register the autostart entry with `limactl autostart <instance>` so the unit file matches the current unit name
  3. Ensure a user systemd session exists (log in locally; for SSH set XDG_RUNTIME_DIR=/run/user/$(id -u))
  4. Check disk/memory: a failed VM start inside the unit shows as a failed systemctl job

Example fix

# diagnose and re-register
systemctl --user status lima-default.service
limactl autostart default
systemctl --user start lima-default.service
Defensive patterns

Strategy: retry

Validate before calling

unit := "lima-" + inst.Name + ".service"
out, err := exec.Command("systemctl", "--user", "cat", unit).Output()
if err != nil {
    // unit missing/invalid: re-run `limactl autostart <instance>` first
}

Try / catch

if err := autostart.RequestStart(ctx, inst); err != nil {
    _ = exec.Command("systemctl", "--user", "daemon-reload").Run()
    time.Sleep(2 * time.Second)
    if err2 := autostart.RequestStart(ctx, inst); err2 != nil {
        return fmt.Errorf("systemctl start failed twice: %w (check journalctl --user -u lima-%s)", err2, inst.Name)
    }
}

Prevention

When it happens

Trigger: RequestStart called (autostart flow, e.g. `limactl autostart start` or guestagent-driven start) when the user unit lima-<name>.service does not exist, is masked, or its start job fails.

Common situations: Autostart entry removed or unit renamed while identifier is stale; systemctl --user unavailable (no user session, LIMA_HOME under a different user, SSH without XDG_RUNTIME_DIR); the VM fails to boot so the start job times out.

Related errors


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