{"record":{"id":"fa2ec649cdc16ece","repo":"lima-vm/lima","slug":"cannot-use-sync-when-the-instance-has-host-mou","errorCode":null,"errorMessage":"cannot use `--sync` when the instance has host mounts configured, start the instance with `--mount-none` to disable mounts","messagePattern":"cannot use `--sync` when the instance has host mounts configured, start the instance with `--mount-none` to disable mounts","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/shell.go","lineNumber":214,"sourceCode":"\t\t\t// fresh master can be established.\n\t\t\tremoved, rmErr := sshutil.RemoveStaleControlMaster(ctx, inst.Dir)\n\t\t\tif rmErr != nil {\n\t\t\t\treturn rmErr\n\t\t\t}\n\t\t\tif !removed {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tlogrus.WithError(err).Warnf(\"Removed stale ssh control socket for the instance %#q after the master had already exited\", instName)\n\t\t}\n\t}\n\n\tsyncDirVal, err := flags.GetString(\"sync\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get sync flag: %w\", err)\n\t}\n\tsyncHostWorkdir := syncDirVal != \"\"\n\tif syncHostWorkdir && len(inst.Config.Mounts) > 0 {\n\t\treturn errors.New(\"cannot use `--sync` when the instance has host mounts configured, start the instance with `--mount-none` to disable mounts\")\n\t}\n\t// A wsl2 guest already reaches the host directory through the /mnt automount,\n\t// so `--sync` cannot isolate it from host files the way it does elsewhere.\n\tif syncHostWorkdir && inst.VMType == limatype.WSL2 {\n\t\treturn errors.New(\"cannot use `--sync` with a wsl2 instance, the host directory is already visible in the guest\")\n\t}\n\n\t// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.\n\t//\n\t// changeDirCmd := \"cd workDir || exit 1\"                  if workDir != \"\"\n\t//              := \"cd hostCurrentDir || cd hostHomeDir\"   if workDir == \"\"\n\tvar changeDirCmd string\n\t// hostCurrentDirNative is the path as the host sees it. hostCurrentDir is the\n\t// form the guest and the copy tool receive, which on Windows differs.\n\tvar hostCurrentDir, hostCurrentDirNative string\n\tif syncDirVal != \"\" {\n\t\thostCurrentDirNative, err = filepath.Abs(syncDirVal)\n\t} else {","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/shell.go#L196-L232","documentation":"`limactl shell --sync` copies the host working directory into the guest with rsync instead of relying on a shared filesystem mount. Lima rejects the flag when the instance still has host mounts configured in its lima.yaml, because the two mechanisms would expose the same host files through two different paths and defeat the isolation `--sync` is meant to provide. The check happens up front in shellAction before any SSH or rsync work starts.","triggerScenarios":"Running `limactl shell <instance> --sync <dir>` (or with --sync pointing at the current directory) against an instance whose config has a non-empty `mounts:` list, i.e. the instance was started without `--mount-none`.","commonSituations":"A developer wants to stop sharing host files into the guest but forgets that the instance was created with default mounts (the default template mounts the home directory); they add `--sync` to the shell command while the instance still runs with mounts enabled.","solutions":["Recreate or restart the instance with mounts disabled: `limactl stop <instance>` then `limactl start --mount-none <instance>` (or remove the `mounts:` entries from the lima.yaml before starting).","If you actually want the host files visible, drop the `--sync` flag and rely on the existing mounts instead.","Verify with `limactl list <instance>` / the instance's lima.yaml that `mounts` is empty before retrying."],"exampleFix":"# before\nlimactl shell default --sync .\n# after\nlimactl stop default\nlimactl start --mount-none default\nlimactl shell default --sync .","handlingStrategy":"validation","validationCode":"if [ -n \"$LIMA_MOUNTS\" ]; then echo 'start instance with --mount-none before using --sync'; fi\n# or check config: yq '.mounts | length == 0' ~/.lima/<instance>/lima.yaml","typeGuard":"null","tryCatchPattern":"if ! limactl shell \"$inst\" --sync . 2>err.txt; then grep -q 'mount-none' err.txt && echo 'recreate instance with: limactl start --mount-none' || cat err.txt; fi","preventionTips":["Start instances intended for --sync usage with `limactl start --mount-none`.","Check `mounts` in ~/.lima/<instance>/lima.yaml is empty before scripting --sync commands.","Keep one instance profile dedicated to synced-shell workflows without mounts."],"tags":["cli","limactl","mounts","sync"],"backgroundTag":"incompatible-flag-with-instance-config","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}