lima-vm/lima · error

failed to protect instance %#q: %w

Error message

failed to protect instance %#q: %w

What it means

After inspection succeeds, protectAction calls inst.Protect(), which writes the protection marker into the instance directory. If that filesystem operation fails (permissions, disk, concurrent modification), the error is wrapped as "failed to protect instance" and joined into the aggregate error at the end.

Source

Thrown at cmd/limactl/protect.go:44

	}
	return protectCommand
}

func protectAction(cmd *cobra.Command, args []string) error {
	ctx := cmd.Context()
	var errs []error
	for _, instName := range args {
		inst, err := store.Inspect(ctx, instName)
		if err != nil {
			errs = append(errs, fmt.Errorf("failed to inspect instance %#q: %w", instName, err))
			continue
		}
		if inst.Protected {
			logrus.Warnf("Instance %#q is already protected. Skipping.", instName)
			continue
		}
		if err := inst.Protect(); err != nil {
			errs = append(errs, fmt.Errorf("failed to protect instance %#q: %w", instName, err))
			continue
		}
		logrus.Infof("Protected %#q", instName)
	}
	return errors.Join(errs...)
}

func protectBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
	return bashCompleteInstanceNames(cmd)
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Fix permissions on the instance directory under LIMA_HOME (chown/chmod back to the invoking user)
  2. Re-run the protect command after resolving the filesystem issue
  3. Check disk space and that LIMA_HOME is on a writable filesystem

Example fix

// before
sudo limactl protect ubuntu   # creates root-owned state / permission mismatch
// after
limactl protect ubuntu        # run as the instance-owning user
Defensive patterns

Strategy: try-catch

Validate before calling

test -w ~/.lima/instances/$inst || { echo "instance dir not writable" >&2; exit 1; }

Try / catch

if err := protectCmd.Run(); err != nil {
    if strings.Contains(err.Error(), "failed to protect instance") {
        // check permissions/ownership of the instance dir, disk space, then retry
    }
}

Prevention

When it happens

Trigger: `limactl protect <name>` where inst.Protect() fails: read-only LIMA_HOME, permission changes on ~/.lima, disk full, or the instance directory mutated between inspect and protect.

Common situations: Running limactl as a different user than the instance owner; root-owned files after sudo usage; read-only mounts/NFS home directories; antivirus or sync tools locking files.

Related errors


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