{"record":{"id":"ba3c267e95b48297","repo":"lima-vm/lima","slug":"failed-to-create-symlink-from-q-to-q-w","errorCode":null,"errorMessage":"failed to create symlink from %#q to %#q: %w","messagePattern":"failed to create symlink from %#q to %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go","lineNumber":182,"sourceCode":"\t}\n\tlnSrc := filepath.Join(\"/Volumes/My Shared Files\", pseudoTag)\n\n\t// FIXME: verify that the filesystem of lnSrc is indeed read-only when user-data contains the \"ro\" option.\n\t// unix.Statfs() could be used, but unix.Statfs_t.Flags & unix.MNT_RDONLY seems always 0 for virtiofs.\n\t// `mount -v` does not show \"ro\" flag either.\n\n\tlnExisting, err := os.Readlink(dir)\n\tif err == nil {\n\t\tif lnExisting == lnSrc {\n\t\t\treturn nil // already symlinked\n\t\t}\n\t\treturn fmt.Errorf(\"unexpected symlink target for virtiofs mount source %#q: expected %#q, got %#q\", lnSrc, lnSrc, lnExisting)\n\t}\n\tif !errors.Is(err, os.ErrNotExist) {\n\t\tlogrus.WithError(err).Warnf(\"Failed to read existing symlink for virtiofs mount source %#q\", lnSrc)\n\t}\n\tif err := os.Symlink(lnSrc, dir); err != nil {\n\t\treturn fmt.Errorf(\"failed to create symlink from %#q to %#q: %w\", lnSrc, dir, err)\n\t}\n\treturn nil\n}\n\nfunc setTimezone(ctx context.Context, timezone string) error {\n\tcmd := exec.CommandContext(ctx, \"systemsetup\", \"-settimezone\", timezone)\n\tlogrus.Infof(\"Executing command: %v\", cmd.Args)\n\tif output, err := cmd.CombinedOutput(); err != nil {\n\t\treturn fmt.Errorf(\"failed to execute command %v: %w (output=%#q)\", cmd.Args, err, output)\n\t}\n\treturn nil\n}\n\nfunc generatePassword() (string, error) {\n\tconst pwLen = 16\n\t// Avoid special characters to minimize potential keyboard layout issue in GUI\n\tpw, err := password.Generate(pwLen, pwLen/4, 0, false, false)\n\tif err != nil {","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/guestagent/fakecloudinit/fakecloudinit_darwin.go#L164-L200","documentation":"Raised by mountVirtiofs when os.Symlink fails while creating the destination symlink pointing to /Volumes/My Shared Files/<pseudoTag>. The OS-level reason (permission denied, path exists as a real file/directory, etc.) is wrapped in the message together with both link endpoints.","triggerScenarios":"os.Symlink(lnSrc, dir) returns an error: `dir` already exists as a regular file or directory (EEXIST - note Readlink only detected ENOENT before), the parent of dir does not exist, or the agent lacks permission to write in the destination directory.","commonSituations":"A previous provisioning run left a real directory at the mount destination, the parent mount point was never created, or a read-only destination filesystem.","solutions":["Check the wrapped OS error in the message (EEXIST vs ENOENT vs EACCES).","If dir exists as a real file/directory, remove or rename it in the guest so the symlink can be created.","Create the parent directory of dir before the mounts step (e.g. via write_files or boot scripts).","Verify /Volumes/My Shared Files/<pseudoTag> exists; if not, the share is not configured in the Lima YAML.","Ensure the guestagent runs with sufficient privileges to write at the destination path."],"exampleFix":"// inside guest VM\n// before\n$ ls -ld /mnt/share  # real directory\n$ sudo rmdir /mnt/share\n// after (next boot creates the symlink)\n$ ls -l /mnt/share  # -> /Volumes/My Shared Files/share","handlingStrategy":"try-catch","validationCode":"func ensureSymlinkable(dir string) error {\n  if fi, err := os.Lstat(dir); err == nil {\n    if fi.Mode()&os.ModeSymlink == 0 { return fmt.Errorf(\"%s exists and is not a symlink\", dir) }\n    return nil // symlink: readlink check happens separately\n  } else if !errors.Is(err, os.ErrNotExist) {\n    return err\n  }\n  return os.MkdirAll(filepath.Dir(dir), 0o755) // parent must exist\n}","typeGuard":"func canCreateSymlink(dir string) bool {\n  fi, err := os.Lstat(dir)\n  return os.IsNotExist(err) || (err == nil && fi.Mode()&os.ModeSymlink != 0)\n}","tryCatchPattern":"if err := os.Symlink(lnSrc, dir); err != nil {\n  if errors.Is(err, os.ErrExist) {\n    // destination occupied by a real file/dir: log and skip or clean up first\n  }\n  return fmt.Errorf(\"failed to create symlink from %#q to %#q: %w\", lnSrc, dir, err)\n}","preventionTips":["Ensure the destination parent directory exists before the mounts step.","Remove any real files/directories occupying the mount destination.","Run the guestagent with write permission on the destination directory.","Verify the source /Volumes/My Shared Files/<tag> exists before linking."],"tags":["macos","cloud-init","symlink","virtiofs","filesystem"],"backgroundTag":"symlink-creation-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}