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
- Fix permissions on the instance directory under LIMA_HOME (chown/chmod back to the invoking user)
- Re-run the protect command after resolving the filesystem issue
- 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
- Run limactl as the same user that owns the instance directory
- Keep LIMA_HOME on a local writable filesystem, not NFS/ro mounts
- Avoid sudo for limactl commands to prevent ownership mismatches
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
- instance %#q directory %#q exists but its %#q could not be r
- failed to create temp file: %w
- failed to write temp plist: %w
- instance %q not found
- failed to register instance %#q to start at login: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/e51f9e536649f9eb.
Report an issue: GitHub.